Skip to content

Commit dca1bdb

Browse files
committed
Fix race with latest dts file
1 parent 53a9bac commit dca1bdb

File tree

4 files changed

+149
-11
lines changed

4 files changed

+149
-11
lines changed

internal/collections/syncset.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ func (s *SyncSet[T]) Range(fn func(key T) bool) {
2222
return fn(key)
2323
})
2424
}
25+
26+
func (s *SyncSet[T]) ToArray() []T {
27+
var arr []T
28+
arr = make([]T, 0, s.m.Size())
29+
s.m.Range(func(key T, value struct{}) bool {
30+
arr = append(arr, key)
31+
return true
32+
})
33+
return arr
34+
}

internal/execute/tscincremental_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ func TestIncremental(t *testing.T) {
3434
</Component>)`,
3535
}, "/home/src/workspaces/project"),
3636
},
37+
{
38+
subScenario: "serializing composite project",
39+
sys: newTestSys(FileMap{
40+
"/home/src/workspaces/project/tsconfig.json": `{
41+
"compilerOptions": {
42+
"composite": true,
43+
"strict": true,
44+
"module": "esnext",
45+
},
46+
}`,
47+
"/home/src/workspaces/project/index.tsx": `export const a = 1;`,
48+
"/home/src/workspaces/project/other.ts": `export const b = 2;`,
49+
}, "/home/src/workspaces/project"),
50+
},
3751
{
3852
subScenario: "change to modifier of class expression field with declaration emit enabled",
3953
sys: newTestSys(FileMap{

internal/incremental/emitfileshandler.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package incremental
22

33
import (
44
"context"
5+
"slices"
56

67
"github.com/microsoft/typescript-go/internal/ast"
78
"github.com/microsoft/typescript-go/internal/collections"
@@ -16,14 +17,14 @@ type emitUpdate struct {
1617
}
1718

1819
type emitFilesHandler struct {
19-
ctx context.Context
20-
program *Program
21-
isForDtsErrors bool
22-
signatures collections.SyncMap[tspath.Path, string]
23-
emitSignatures collections.SyncMap[tspath.Path, *emitSignature]
24-
latestChangedDtsFile string
25-
deletedPendingKinds collections.Set[tspath.Path]
26-
emitUpdates collections.SyncMap[tspath.Path, *emitUpdate]
20+
ctx context.Context
21+
program *Program
22+
isForDtsErrors bool
23+
signatures collections.SyncMap[tspath.Path, string]
24+
emitSignatures collections.SyncMap[tspath.Path, *emitSignature]
25+
latestChangedDtsFiles collections.SyncSet[string]
26+
deletedPendingKinds collections.Set[tspath.Path]
27+
emitUpdates collections.SyncMap[tspath.Path, *emitUpdate]
2728
}
2829

2930
// Determining what all is pending to be emitted based on previous options or previous file emit flags
@@ -206,7 +207,7 @@ func (h *emitFilesHandler) skipDtsOutputOfComposite(file *ast.SourceFile, output
206207
data.DiffersOnlyInMap = true
207208
}
208209
} else {
209-
h.latestChangedDtsFile = outputFileName
210+
h.latestChangedDtsFiles.Add(outputFileName)
210211
}
211212
h.emitSignatures.Store(file.Path(), &emitSignature{signature: newSignature})
212213
return false
@@ -227,8 +228,10 @@ func (h *emitFilesHandler) updateSnapshot() []*compiler.EmitResult {
227228
h.program.snapshot.buildInfoEmitPending = true
228229
return true
229230
})
230-
if h.latestChangedDtsFile != "" {
231-
h.program.snapshot.latestChangedDtsFile = h.latestChangedDtsFile
231+
latestChangedDtsFiles := h.latestChangedDtsFiles.ToArray()
232+
slices.Sort(latestChangedDtsFiles)
233+
if latestChangedDtsFile := core.LastOrNil(latestChangedDtsFiles); latestChangedDtsFile != "" {
234+
h.program.snapshot.latestChangedDtsFile = latestChangedDtsFile
232235
h.program.snapshot.buildInfoEmitPending = true
233236
}
234237
for file := range h.deletedPendingKinds.Keys() {
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::
5+
//// [/home/src/workspaces/project/index.tsx] *new*
6+
export const a = 1;
7+
//// [/home/src/workspaces/project/other.ts] *new*
8+
export const b = 2;
9+
//// [/home/src/workspaces/project/tsconfig.json] *new*
10+
{
11+
"compilerOptions": {
12+
"composite": true,
13+
"strict": true,
14+
"module": "esnext",
15+
},
16+
}
17+
18+
ExitStatus:: 0
19+
20+
CompilerOptions::{}
21+
Output::
22+
//// [/home/src/tslibs/TS/Lib/lib.d.ts] *Lib*
23+
/// <reference no-default-lib="true"/>
24+
interface Boolean {}
25+
interface Function {}
26+
interface CallableFunction {}
27+
interface NewableFunction {}
28+
interface IArguments {}
29+
interface Number { toExponential: any; }
30+
interface Object {}
31+
interface RegExp {}
32+
interface String { charAt: any; }
33+
interface Array<T> { length: number; [n: number]: T; }
34+
interface ReadonlyArray<T> {}
35+
interface SymbolConstructor {
36+
(desc?: string | number): symbol;
37+
for(name: string): symbol;
38+
readonly toStringTag: symbol;
39+
}
40+
declare var Symbol: SymbolConstructor;
41+
interface Symbol {
42+
readonly [Symbol.toStringTag]: string;
43+
}
44+
declare const console: { log(msg: any): void; };
45+
//// [/home/src/workspaces/project/index.d.ts] *new*
46+
export declare const a = 1;
47+
48+
//// [/home/src/workspaces/project/index.js] *new*
49+
export const a = 1;
50+
51+
//// [/home/src/workspaces/project/other.d.ts] *new*
52+
export declare const b = 2;
53+
54+
//// [/home/src/workspaces/project/other.js] *new*
55+
export const b = 2;
56+
57+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] *new*
58+
{"version":"FakeTSVersion","fileNames":["../../tslibs/TS/Lib/lib.d.ts","./index.tsx","./other.ts"],"fileInfos":[{"version":"7dee939514de4bde7a51760a39e2b3bfa068bfc4a2939e1dbad2bfdf2dc4662e","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"683314ed22112e8dea8095c8c6173afa2c61279f5fe07968ebe0e21fff16871d","signature":"f0f1286d442f3c09fa07d37db7d31755cb3761daed3c8008fbfce412770425c6","impliedNodeFormat":1},{"version":"34f0f66ce649a0df0d3d5bad537c3b867b11b2fbeb5eee37e1c75a795544a4ed","signature":"0fb7bb75ad82d403bd7ba1f151c0297ef6a9167d0039e90a9067289387a719a7","impliedNodeFormat":1}],"options":{"composite":true,"module":99,"strict":true},"latestChangedDtsFile":"./other.d.ts"}
59+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
60+
{
61+
"version": "FakeTSVersion",
62+
"fileNames": [
63+
"../../tslibs/TS/Lib/lib.d.ts",
64+
"./index.tsx",
65+
"./other.ts"
66+
],
67+
"fileInfos": [
68+
{
69+
"fileName": "../../tslibs/TS/Lib/lib.d.ts",
70+
"version": "7dee939514de4bde7a51760a39e2b3bfa068bfc4a2939e1dbad2bfdf2dc4662e",
71+
"signature": "7dee939514de4bde7a51760a39e2b3bfa068bfc4a2939e1dbad2bfdf2dc4662e",
72+
"affectsGlobalScope": true,
73+
"impliedNodeFormat": "CommonJS",
74+
"original": {
75+
"version": "7dee939514de4bde7a51760a39e2b3bfa068bfc4a2939e1dbad2bfdf2dc4662e",
76+
"affectsGlobalScope": true,
77+
"impliedNodeFormat": 1
78+
}
79+
},
80+
{
81+
"fileName": "./index.tsx",
82+
"version": "683314ed22112e8dea8095c8c6173afa2c61279f5fe07968ebe0e21fff16871d",
83+
"signature": "f0f1286d442f3c09fa07d37db7d31755cb3761daed3c8008fbfce412770425c6",
84+
"impliedNodeFormat": "CommonJS",
85+
"original": {
86+
"version": "683314ed22112e8dea8095c8c6173afa2c61279f5fe07968ebe0e21fff16871d",
87+
"signature": "f0f1286d442f3c09fa07d37db7d31755cb3761daed3c8008fbfce412770425c6",
88+
"impliedNodeFormat": 1
89+
}
90+
},
91+
{
92+
"fileName": "./other.ts",
93+
"version": "34f0f66ce649a0df0d3d5bad537c3b867b11b2fbeb5eee37e1c75a795544a4ed",
94+
"signature": "0fb7bb75ad82d403bd7ba1f151c0297ef6a9167d0039e90a9067289387a719a7",
95+
"impliedNodeFormat": "CommonJS",
96+
"original": {
97+
"version": "34f0f66ce649a0df0d3d5bad537c3b867b11b2fbeb5eee37e1c75a795544a4ed",
98+
"signature": "0fb7bb75ad82d403bd7ba1f151c0297ef6a9167d0039e90a9067289387a719a7",
99+
"impliedNodeFormat": 1
100+
}
101+
}
102+
],
103+
"options": {
104+
"composite": true,
105+
"module": 99,
106+
"strict": true
107+
},
108+
"latestChangedDtsFile": "./other.d.ts",
109+
"size": 693
110+
}
111+

0 commit comments

Comments
 (0)