-
Notifications
You must be signed in to change notification settings - Fork 12.2k
/
incremental.ts
276 lines (262 loc) · 12.7 KB
/
incremental.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
namespace ts {
describe("unittests:: tsc:: incremental::", () => {
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: "when passing filename for buildinfo on commandline",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
},
"include": [
"src/**/*.ts"
]
}`,
}),
commandLineArgs: ["--incremental", "--p", "src/project", "--tsBuildInfoFile", "src/project/.tsbuildinfo"],
incrementalScenarios: noChangeOnlyRuns
});
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: "when passing rootDir from commandline",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"incremental": true,
"outDir": "dist",
},
}`,
}),
commandLineArgs: ["--p", "src/project", "--rootDir", "src/project/src"],
incrementalScenarios: noChangeOnlyRuns
});
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: "with only dts files",
fs: () => loadProjectFromFiles({
"/src/project/src/main.d.ts": "export const x = 10;",
"/src/project/src/another.d.ts": "export const y = 10;",
"/src/project/tsconfig.json": "{}",
}),
commandLineArgs: ["--incremental", "--p", "src/project"],
incrementalScenarios: [
noChangeRun,
{
buildKind: BuildKind.IncrementalDtsUnchanged,
modifyFs: fs => appendText(fs, "/src/project/src/main.d.ts", "export const xy = 100;")
}
]
});
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: "when passing rootDir is in the tsconfig",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "export const x = 10;",
"/src/project/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"incremental": true,
"outDir": "./built",
"rootDir": "./"
},
}`,
}),
commandLineArgs: ["--p", "src/project"],
incrementalScenarios: noChangeOnlyRuns
});
describe("with noEmitOnError", () => {
let projFs: vfs.FileSystem;
before(() => {
projFs = loadProjectFromDisk("tests/projects/noEmitOnError");
});
after(() => {
projFs = undefined!;
});
function verifyNoEmitOnError(subScenario: string, fixModifyFs: TscIncremental["modifyFs"], modifyFs?: TscIncremental["modifyFs"]) {
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario,
fs: () => projFs,
commandLineArgs: ["--incremental", "-p", "src"],
modifyFs,
incrementalScenarios: [
noChangeRun,
{
buildKind: BuildKind.IncrementalDtsUnchanged,
modifyFs: fixModifyFs
},
noChangeRun,
],
baselinePrograms: true
});
}
verifyNoEmitOnError(
"with noEmitOnError syntax errors",
fs => fs.writeFileSync("/src/src/main.ts", `import { A } from "../shared/types/db";
const a = {
lastName: 'sdsd'
};`, "utf-8")
);
verifyNoEmitOnError(
"with noEmitOnError semantic errors",
fs => fs.writeFileSync("/src/src/main.ts", `import { A } from "../shared/types/db";
const a: string = "hello";`, "utf-8"),
fs => fs.writeFileSync("/src/src/main.ts", `import { A } from "../shared/types/db";
const a: string = 10;`, "utf-8"),
);
});
describe("when noEmit changes between compilation", () => {
verifyNoEmitChanges({ incremental: true });
verifyNoEmitChanges({ incremental: true, declaration: true });
verifyNoEmitChanges({ composite: true });
function verifyNoEmitChanges(compilerOptions: CompilerOptions) {
const noChangeRunWithNoEmit: TscIncremental = {
subScenario: "No Change run with noEmit",
commandLineArgs: ["--p", "src/project", "--noEmit"],
...noChangeRun,
};
const noChangeRunWithEmit: TscIncremental = {
subScenario: "No Change run with emit",
commandLineArgs: ["--p", "src/project"],
...noChangeRun,
};
let optionsString = "";
for (const key in compilerOptions) {
if (hasProperty(compilerOptions, key)) {
optionsString += ` ${key}`;
}
}
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: `noEmit changes${optionsString}`,
commandLineArgs: ["--p", "src/project"],
fs,
incrementalScenarios: [
noChangeRunWithNoEmit,
noChangeRunWithNoEmit,
{
subScenario: "Introduce error but still noEmit",
commandLineArgs: ["--p", "src/project", "--noEmit"],
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop", "prop1"),
buildKind: BuildKind.IncrementalDtsChange
},
{
subScenario: "Fix error and emit",
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop1", "prop"),
buildKind: BuildKind.IncrementalDtsChange
},
noChangeRunWithEmit,
noChangeRunWithNoEmit,
noChangeRunWithNoEmit,
noChangeRunWithEmit,
{
subScenario: "Introduce error and emit",
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop", "prop1"),
buildKind: BuildKind.IncrementalDtsChange
},
noChangeRunWithEmit,
noChangeRunWithNoEmit,
noChangeRunWithNoEmit,
noChangeRunWithEmit,
{
subScenario: "Fix error and no emit",
commandLineArgs: ["--p", "src/project", "--noEmit"],
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop1", "prop"),
buildKind: BuildKind.IncrementalDtsChange
},
noChangeRunWithEmit,
noChangeRunWithNoEmit,
noChangeRunWithNoEmit,
noChangeRunWithEmit,
],
});
verifyTscSerializedIncrementalEdits({
scenario: "incremental",
subScenario: `noEmit changes with initial noEmit${optionsString}`,
commandLineArgs: ["--p", "src/project", "--noEmit"],
fs,
incrementalScenarios: [
noChangeRunWithEmit,
{
subScenario: "Introduce error with emit",
commandLineArgs: ["--p", "src/project"],
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop", "prop1"),
buildKind: BuildKind.IncrementalDtsChange
},
{
subScenario: "Fix error and no emit",
modifyFs: fs => replaceText(fs, "/src/project/src/class.ts", "prop1", "prop"),
buildKind: BuildKind.IncrementalDtsChange
},
noChangeRunWithEmit,
],
});
function fs() {
return loadProjectFromFiles({
"/src/project/src/class.ts": Utils.dedent`
export class classC {
prop = 1;
}`,
"/src/project/src/indirectClass.ts": Utils.dedent`
import { classC } from './class';
export class indirectClass {
classC = new classC();
}`,
"/src/project/src/directUse.ts": Utils.dedent`
import { indirectClass } from './indirectClass';
new indirectClass().classC.prop;`,
"/src/project/src/indirectUse.ts": Utils.dedent`
import { indirectClass } from './indirectClass';
new indirectClass().classC.prop;`,
"/src/project/src/noChangeFile.ts": Utils.dedent`
export function writeLog(s: string) {
}`,
"/src/project/src/noChangeFileWithEmitSpecificError.ts": Utils.dedent`
function someFunc(arguments: boolean, ...rest: any[]) {
}`,
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions }),
});
}
}
});
const jsxLibraryContent = `
export {};
declare global {
namespace JSX {
interface Element {}
interface IntrinsicElements {
div: {
propA?: boolean;
};
}
}
}`;
verifyTsc({
scenario: "react-jsx-emit-mode",
subScenario: "with no backing types found doesn't crash",
fs: () => loadProjectFromFiles({
"/src/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
"/src/project/node_modules/@types/react/index.d.ts": jsxLibraryContent, // doesn't contain a jsx-runtime definition
"/src/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } })
}),
commandLineArgs: ["--p", "src/project"]
});
verifyTsc({
scenario: "react-jsx-emit-mode",
subScenario: "with no backing types found doesn't crash under --strict",
fs: () => loadProjectFromFiles({
"/src/project/node_modules/react/jsx-runtime.js": "export {}", // js needs to be present so there's a resolution result
"/src/project/node_modules/@types/react/index.d.ts": jsxLibraryContent, // doesn't contain a jsx-runtime definition
"/src/project/src/index.tsx": `export const App = () => <div propA={true}></div>;`,
"/src/project/tsconfig.json": JSON.stringify({ compilerOptions: { module: "commonjs", jsx: "react-jsx", incremental: true, jsxImportSource: "react" } })
}),
commandLineArgs: ["--p", "src/project", "--strict"]
});
});
}