Skip to content

Commit d2834c2

Browse files
committed
Tests for reference map
1 parent 08b7e8c commit d2834c2

File tree

5 files changed

+461
-20
lines changed

5 files changed

+461
-20
lines changed

internal/collections/manytomanymap.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,16 @@ func (m *ManyToManyMap[K, V]) Keys() map[K]*Set[V] {
2525

2626
func (m *ManyToManyMap[K, V]) Add(key K, valueSet *Set[V]) {
2727
existingValueSet, hasExisting := m.keyToValueSet[key]
28+
if m.keyToValueSet == nil {
29+
m.keyToValueSet = make(map[K]*Set[V])
30+
}
2831
m.keyToValueSet[key] = valueSet
2932
for value := range valueSet.Keys() {
3033
if !hasExisting || !existingValueSet.Has(value) {
3134
// Add to valueToKeySet
35+
if m.valueToKeySet == nil {
36+
m.valueToKeySet = make(map[V]*Set[K])
37+
}
3238
addToMapOfSet(m.valueToKeySet, value, key)
3339
}
3440
}
@@ -46,7 +52,7 @@ func (m *ManyToManyMap[K, V]) Add(key K, valueSet *Set[V]) {
4652
func addToMapOfSet[K comparable, V comparable](mapKSetV map[K]*Set[V], key K, value V) {
4753
set, exists := mapKSetV[key]
4854
if !exists {
49-
set := &Set[V]{}
55+
set = &Set[V]{}
5056
mapKSetV[key] = set
5157
}
5258
set.Add(value)

internal/execute/tscincremental_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,74 @@ func TestIncremental(t *testing.T) {
4242
</Component>)`,
4343
}, "/home/src/workspaces/project"),
4444
},
45+
{
46+
subScenario: "change to modifier of class expression field with declaration emit enabled",
47+
sys: newTestSys(FileMap{
48+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "module": "esnext", "declaration": true } }`,
49+
"/home/src/workspaces/project/main.ts": `
50+
import MessageablePerson from './MessageablePerson.js';
51+
function logMessage( person: MessageablePerson ) {
52+
console.log( person.message );
53+
}`,
54+
"/home/src/workspaces/project/MessageablePerson.ts": `
55+
const Messageable = () => {
56+
return class MessageableClass {
57+
public message = 'hello';
58+
}
59+
};
60+
const wrapper = () => Messageable();
61+
type MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;
62+
export default MessageablePerson;`,
63+
}, "/home/src/workspaces/project"),
64+
commandLineArgs: []string{"--incremental"},
65+
// edits: [
66+
// noChangeRun,
67+
// {
68+
// caption: "modify public to protected",
69+
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected"),
70+
// },
71+
// noChangeRun,
72+
// {
73+
// caption: "modify protected to public",
74+
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public"),
75+
// },
76+
// noChangeRun,
77+
// ],
78+
},
79+
{
80+
subScenario: "change to modifier of class expression field",
81+
sys: newTestSys(FileMap{
82+
"/home/src/workspaces/project/tsconfig.json": `{ "compilerOptions": { "module": "esnext" } }`,
83+
"/home/src/workspaces/project/main.ts": `
84+
import MessageablePerson from './MessageablePerson.js';
85+
function logMessage( person: MessageablePerson ) {
86+
console.log( person.message );
87+
}`,
88+
"/home/src/workspaces/project/MessageablePerson.ts": `
89+
const Messageable = () => {
90+
return class MessageableClass {
91+
public message = 'hello';
92+
}
93+
};
94+
const wrapper = () => Messageable();
95+
type MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;
96+
export default MessageablePerson;`,
97+
}, "/home/src/workspaces/project"),
98+
commandLineArgs: []string{"--incremental"},
99+
// edits: [
100+
// noChangeRun,
101+
// {
102+
// caption: "modify public to protected",
103+
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "public", "protected"),
104+
// },
105+
// noChangeRun,
106+
// {
107+
// caption: "modify protected to public",
108+
// edit: sys => sys.replaceFileText("/home/src/workspaces/project/MessageablePerson.ts", "protected", "public"),
109+
// },
110+
// noChangeRun,
111+
// ],
112+
},
45113
}
46114

47115
for _, test := range testCases {

internal/incremental/snapshot.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,33 +358,35 @@ func newSnapshotForProgram(program *compiler.Program, oldProgram *Program) *snap
358358
impliedNodeFormat := program.GetSourceFileMetaData(file.Path()).ImpliedNodeFormat
359359
affectsGlobalScope := fileAffectsGlobalScope(file)
360360
var signature string
361+
var newReferences *collections.Set[tspath.Path]
362+
if snapshot.referencedMap != nil {
363+
newReferences := getReferencedFiles(program, file)
364+
if newReferences != nil {
365+
snapshot.referencedMap.Add(file.Path(), newReferences)
366+
}
367+
}
361368
if canUseStateFromOldProgram {
362369
if oldFileInfo, ok := oldProgram.snapshot.fileInfos[file.Path()]; ok {
363370
signature = oldFileInfo.signature
364371
if oldFileInfo.version == version || oldFileInfo.affectsGlobalScope != affectsGlobalScope || oldFileInfo.impliedNodeFormat != impliedNodeFormat {
365372
snapshot.addFileToChangeSet(file.Path())
366-
}
367-
} else {
368-
snapshot.addFileToChangeSet(file.Path())
369-
}
370-
if snapshot.referencedMap != nil {
371-
newReferences := getReferencedFiles(program, file)
372-
if newReferences != nil {
373-
snapshot.referencedMap.Add(file.Path(), newReferences)
374-
}
375-
oldReferences, _ := oldProgram.snapshot.referencedMap.GetValues(file.Path())
376-
// Referenced files changed
377-
if !newReferences.Equals(oldReferences) {
378-
snapshot.addFileToChangeSet(file.Path())
379-
} else {
380-
for refPath := range newReferences.Keys() {
381-
if program.GetSourceFileByPath(refPath) == nil {
382-
// Referenced file was deleted in the new program
383-
snapshot.addFileToChangeSet(file.Path())
384-
break
373+
} else if snapshot.referencedMap != nil {
374+
oldReferences, _ := oldProgram.snapshot.referencedMap.GetValues(file.Path())
375+
// Referenced files changed
376+
if !newReferences.Equals(oldReferences) {
377+
snapshot.addFileToChangeSet(file.Path())
378+
} else {
379+
for refPath := range newReferences.Keys() {
380+
if program.GetSourceFileByPath(refPath) == nil {
381+
// Referenced file was deleted in the new program
382+
snapshot.addFileToChangeSet(file.Path())
383+
break
384+
}
385385
}
386386
}
387387
}
388+
} else {
389+
snapshot.addFileToChangeSet(file.Path())
388390
}
389391
if !snapshot.changedFilesSet.Has(file.Path()) {
390392
if emitDiagnostics, ok := oldProgram.snapshot.emitDiagnosticsPerFile[file.Path()]; ok {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
2+
currentDirectory::/home/src/workspaces/project
3+
useCaseSensitiveFileNames::true
4+
Input::--incremental
5+
//// [/home/src/workspaces/project/MessageablePerson.ts] new file
6+
7+
const Messageable = () => {
8+
return class MessageableClass {
9+
public message = 'hello';
10+
}
11+
};
12+
const wrapper = () => Messageable();
13+
type MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;
14+
export default MessageablePerson;
15+
//// [/home/src/workspaces/project/main.ts] new file
16+
17+
import MessageablePerson from './MessageablePerson.js';
18+
function logMessage( person: MessageablePerson ) {
19+
console.log( person.message );
20+
}
21+
//// [/home/src/workspaces/project/tsconfig.json] new file
22+
{ "compilerOptions": { "module": "esnext", "declaration": true } }
23+
24+
ExitStatus:: 0
25+
26+
CompilerOptions::{
27+
"incremental": true
28+
}
29+
Output::
30+
//// [/home/src/workspaces/project/MessageablePerson.d.ts] new file
31+
declare const wrapper: () => {
32+
new (): {
33+
message: string;
34+
};
35+
};
36+
type MessageablePerson = InstanceType<ReturnType<typeof wrapper>>;
37+
export default MessageablePerson;
38+
39+
//// [/home/src/workspaces/project/MessageablePerson.js] new file
40+
const Messageable = () => {
41+
return class MessageableClass {
42+
message = 'hello';
43+
};
44+
};
45+
const wrapper = () => Messageable();
46+
export {};
47+
48+
//// [/home/src/workspaces/project/MessageablePerson.ts] no change
49+
//// [/home/src/workspaces/project/main.d.ts] new file
50+
export {};
51+
52+
//// [/home/src/workspaces/project/main.js] new file
53+
function logMessage(person) {
54+
console.log(person.message);
55+
}
56+
export {};
57+
58+
//// [/home/src/workspaces/project/main.ts] no change
59+
//// [/home/src/workspaces/project/tsconfig.json] no change
60+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo] new file
61+
{"Version":"FakeTSVersion","fileNames":["bundled:///libs/lib.d.ts","bundled:///libs/lib.es5.d.ts","bundled:///libs/lib.dom.d.ts","bundled:///libs/lib.webworker.importscripts.d.ts","bundled:///libs/lib.scripthost.d.ts","bundled:///libs/lib.decorators.d.ts","bundled:///libs/lib.decorators.legacy.d.ts","./MessageablePerson.ts","./main.ts"],"fileInfos":["a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",{"version":"69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true,"impliedNodeFormat":1},{"version":"ff666de4fdc53b5500de60a9b8c073c9327a9e9326417ef4861b8d2473c7457a","signature":"6ec1f7bdc192ba06258caff3fa202fd577f8f354d676f548500eeb232155cbbe","impliedNodeFormat":1},{"version":"36f0b00de3c707929bf1919e32e5b6053c8730bb00aa779bcdd1925414d68b8c","signature":"8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881","impliedNodeFormat":1}],"fileIdsList":[[8]],"options":{"declaration":true,"module":99},"referencedMap":[[9,1]]}
62+
//// [/home/src/workspaces/project/tsconfig.tsbuildinfo.readable.baseline.txt] new file
63+
{
64+
"Version": "FakeTSVersion",
65+
"fileNames": [
66+
"bundled:///libs/lib.d.ts",
67+
"bundled:///libs/lib.es5.d.ts",
68+
"bundled:///libs/lib.dom.d.ts",
69+
"bundled:///libs/lib.webworker.importscripts.d.ts",
70+
"bundled:///libs/lib.scripthost.d.ts",
71+
"bundled:///libs/lib.decorators.d.ts",
72+
"bundled:///libs/lib.decorators.legacy.d.ts",
73+
"./MessageablePerson.ts",
74+
"./main.ts"
75+
],
76+
"fileInfos": [
77+
{
78+
"fileName": "bundled:///libs/lib.d.ts",
79+
"version": "a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",
80+
"signature": "a7297ff837fcdf174a9524925966429eb8e5feecc2cc55cc06574e6b092c1eaa",
81+
"impliedNodeFormat": "CommonJS"
82+
},
83+
{
84+
"fileName": "bundled:///libs/lib.es5.d.ts",
85+
"version": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
86+
"signature": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
87+
"affectsGlobalScope": true,
88+
"impliedNodeFormat": "CommonJS",
89+
"original": {
90+
"version": "69684132aeb9b5642cbcd9e22dff7818ff0ee1aa831728af0ecf97d3364d5546",
91+
"affectsGlobalScope": true,
92+
"impliedNodeFormat": 1
93+
}
94+
},
95+
{
96+
"fileName": "bundled:///libs/lib.dom.d.ts",
97+
"version": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
98+
"signature": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
99+
"affectsGlobalScope": true,
100+
"impliedNodeFormat": "CommonJS",
101+
"original": {
102+
"version": "092c2bfe125ce69dbb1223c85d68d4d2397d7d8411867b5cc03cec902c233763",
103+
"affectsGlobalScope": true,
104+
"impliedNodeFormat": 1
105+
}
106+
},
107+
{
108+
"fileName": "bundled:///libs/lib.webworker.importscripts.d.ts",
109+
"version": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
110+
"signature": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
111+
"affectsGlobalScope": true,
112+
"impliedNodeFormat": "CommonJS",
113+
"original": {
114+
"version": "80e18897e5884b6723488d4f5652167e7bb5024f946743134ecc4aa4ee731f89",
115+
"affectsGlobalScope": true,
116+
"impliedNodeFormat": 1
117+
}
118+
},
119+
{
120+
"fileName": "bundled:///libs/lib.scripthost.d.ts",
121+
"version": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
122+
"signature": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
123+
"affectsGlobalScope": true,
124+
"impliedNodeFormat": "CommonJS",
125+
"original": {
126+
"version": "cd034f499c6cdca722b60c04b5b1b78e058487a7085a8e0d6fb50809947ee573",
127+
"affectsGlobalScope": true,
128+
"impliedNodeFormat": 1
129+
}
130+
},
131+
{
132+
"fileName": "bundled:///libs/lib.decorators.d.ts",
133+
"version": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
134+
"signature": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
135+
"affectsGlobalScope": true,
136+
"impliedNodeFormat": "CommonJS",
137+
"original": {
138+
"version": "8e7f8264d0fb4c5339605a15daadb037bf238c10b654bb3eee14208f860a32ea",
139+
"affectsGlobalScope": true,
140+
"impliedNodeFormat": 1
141+
}
142+
},
143+
{
144+
"fileName": "bundled:///libs/lib.decorators.legacy.d.ts",
145+
"version": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
146+
"signature": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
147+
"affectsGlobalScope": true,
148+
"impliedNodeFormat": "CommonJS",
149+
"original": {
150+
"version": "782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538",
151+
"affectsGlobalScope": true,
152+
"impliedNodeFormat": 1
153+
}
154+
},
155+
{
156+
"fileName": "./MessageablePerson.ts",
157+
"version": "ff666de4fdc53b5500de60a9b8c073c9327a9e9326417ef4861b8d2473c7457a",
158+
"signature": "6ec1f7bdc192ba06258caff3fa202fd577f8f354d676f548500eeb232155cbbe",
159+
"impliedNodeFormat": "CommonJS",
160+
"original": {
161+
"version": "ff666de4fdc53b5500de60a9b8c073c9327a9e9326417ef4861b8d2473c7457a",
162+
"signature": "6ec1f7bdc192ba06258caff3fa202fd577f8f354d676f548500eeb232155cbbe",
163+
"impliedNodeFormat": 1
164+
}
165+
},
166+
{
167+
"fileName": "./main.ts",
168+
"version": "36f0b00de3c707929bf1919e32e5b6053c8730bb00aa779bcdd1925414d68b8c",
169+
"signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881",
170+
"impliedNodeFormat": "CommonJS",
171+
"original": {
172+
"version": "36f0b00de3c707929bf1919e32e5b6053c8730bb00aa779bcdd1925414d68b8c",
173+
"signature": "8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881",
174+
"impliedNodeFormat": 1
175+
}
176+
}
177+
],
178+
"fileIdsList": [
179+
[
180+
"./MessageablePerson.ts"
181+
]
182+
],
183+
"options": {
184+
"declaration": true,
185+
"module": 99
186+
},
187+
"referencedMap": {
188+
"./main.ts": [
189+
"./MessageablePerson.ts"
190+
]
191+
},
192+
"size": 1629
193+
}
194+

0 commit comments

Comments
 (0)