Skip to content

Commit 8192d55

Browse files
authoredSep 28, 2022
Pick correct compilerOptions when checking if we can share emitSignatures (#50910)
* Pick correct compilerOptions when checking if we can share emitSignatures Fixes #50902 * Add a note * Rewording
1 parent 16faef1 commit 8192d55

File tree

3 files changed

+154
-1
lines changed

3 files changed

+154
-1
lines changed
 

‎src/compiler/builder.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ namespace ts {
173173
const oldCompilerOptions = useOldState ? oldState!.compilerOptions : undefined;
174174
const canCopySemanticDiagnostics = useOldState && oldState!.semanticDiagnosticsPerFile && !!state.semanticDiagnosticsPerFile &&
175175
!compilerOptionsAffectSemanticDiagnostics(compilerOptions, oldCompilerOptions!);
176+
// We can only reuse emit signatures (i.e. .d.ts signatures) if the .d.ts file is unchanged,
177+
// which will eg be depedent on change in options like declarationDir and outDir options are unchanged.
178+
// We need to look in oldState.compilerOptions, rather than oldCompilerOptions (i.e.we need to disregard useOldState) because
179+
// oldCompilerOptions can be undefined if there was change in say module from None to some other option
180+
// which would make useOldState as false since we can now use reference maps that are needed to track what to emit, what to check etc
181+
// but that option change does not affect d.ts file name so emitSignatures should still be reused.
176182
const canCopyEmitSignatures = compilerOptions.composite &&
177183
oldState?.emitSignatures &&
178184
!outFilePath &&
179-
!compilerOptionsAffectDeclarationPath(compilerOptions, oldCompilerOptions!);
185+
!compilerOptionsAffectDeclarationPath(compilerOptions, oldState.compilerOptions);
180186
if (useOldState) {
181187
// Copy old state's changed files set
182188
oldState!.changedFilesSet?.forEach(value => state.changedFilesSet.add(value));

‎src/testRunner/unittests/tsc/composite.ts

+21
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,26 @@ namespace ts {
8181
}),
8282
commandLineArgs: ["--composite", "false", "--p", "src/project", "--tsBuildInfoFile", "null"],
8383
});
84+
85+
verifyTscWithEdits({
86+
scenario: "composite",
87+
subScenario: "converting to modules",
88+
fs: () => loadProjectFromFiles({
89+
"/src/project/src/main.ts": "const x = 10;",
90+
"/src/project/tsconfig.json": JSON.stringify({
91+
compilerOptions: {
92+
module: "none",
93+
composite: true,
94+
},
95+
}),
96+
}),
97+
commandLineArgs: ["-p", "/src/project"],
98+
edits: [
99+
{
100+
subScenario: "convert to modules",
101+
modifyFs: fs => replaceText(fs, "/src/project/tsconfig.json", "none", "es2015"),
102+
}
103+
]
104+
});
84105
});
85106
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/project/src/main.ts]
18+
const x = 10;
19+
20+
//// [/src/project/tsconfig.json]
21+
{"compilerOptions":{"module":"none","composite":true}}
22+
23+
24+
25+
Output::
26+
/lib/tsc -p /src/project
27+
exitCode:: ExitStatus.Success
28+
29+
30+
//// [/src/project/src/main.d.ts]
31+
declare const x = 10;
32+
33+
34+
//// [/src/project/src/main.js]
35+
var x = 10;
36+
37+
38+
//// [/src/project/tsconfig.tsbuildinfo]
39+
{"program":{"fileNames":["../../lib/lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"5029505981-const x = 10;","signature":"-3198459068-declare const x = 10;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"module":0},"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"}
40+
41+
//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt]
42+
{
43+
"program": {
44+
"fileNames": [
45+
"../../lib/lib.d.ts",
46+
"./src/main.ts"
47+
],
48+
"fileInfos": {
49+
"../../lib/lib.d.ts": {
50+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
51+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
52+
"affectsGlobalScope": true
53+
},
54+
"./src/main.ts": {
55+
"version": "5029505981-const x = 10;",
56+
"signature": "-3198459068-declare const x = 10;\r\n",
57+
"affectsGlobalScope": true
58+
}
59+
},
60+
"options": {
61+
"composite": true,
62+
"module": 0
63+
},
64+
"semanticDiagnosticsPerFile": [
65+
"../../lib/lib.d.ts",
66+
"./src/main.ts"
67+
],
68+
"latestChangedDtsFile": "./src/main.d.ts"
69+
},
70+
"version": "FakeTSVersion",
71+
"size": 816
72+
}
73+
74+
75+
76+
Change:: convert to modules
77+
Input::
78+
//// [/src/project/tsconfig.json]
79+
{"compilerOptions":{"module":"es2015","composite":true}}
80+
81+
82+
83+
Output::
84+
/lib/tsc -p /src/project
85+
exitCode:: ExitStatus.Success
86+
87+
88+
//// [/src/project/src/main.js] file written with same contents
89+
//// [/src/project/tsconfig.tsbuildinfo]
90+
{"program":{"fileNames":["../../lib/lib.d.ts","./src/main.ts"],"fileInfos":[{"version":"3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"5029505981-const x = 10;","signature":"-3198459068-declare const x = 10;\r\n","affectsGlobalScope":true}],"options":{"composite":true,"module":5},"referencedMap":[],"exportedModulesMap":[],"semanticDiagnosticsPerFile":[1,2],"latestChangedDtsFile":"./src/main.d.ts"},"version":"FakeTSVersion"}
91+
92+
//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt]
93+
{
94+
"program": {
95+
"fileNames": [
96+
"../../lib/lib.d.ts",
97+
"./src/main.ts"
98+
],
99+
"fileInfos": {
100+
"../../lib/lib.d.ts": {
101+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
102+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
103+
"affectsGlobalScope": true
104+
},
105+
"./src/main.ts": {
106+
"version": "5029505981-const x = 10;",
107+
"signature": "-3198459068-declare const x = 10;\r\n",
108+
"affectsGlobalScope": true
109+
}
110+
},
111+
"options": {
112+
"composite": true,
113+
"module": 5
114+
},
115+
"referencedMap": {},
116+
"exportedModulesMap": {},
117+
"semanticDiagnosticsPerFile": [
118+
"../../lib/lib.d.ts",
119+
"./src/main.ts"
120+
],
121+
"latestChangedDtsFile": "./src/main.d.ts"
122+
},
123+
"version": "FakeTSVersion",
124+
"size": 859
125+
}
126+

0 commit comments

Comments
 (0)