Skip to content

Commit

Permalink
Pick correct compilerOptions when checking if we can share emitSignat…
Browse files Browse the repository at this point in the history
…ures

Fixes #50902
  • Loading branch information
sheetalkamat committed Sep 22, 2022
1 parent bbec17d commit 14f9cbf
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/builder.ts
Expand Up @@ -176,7 +176,7 @@ namespace ts {
const canCopyEmitSignatures = compilerOptions.composite &&
oldState?.emitSignatures &&
!outFilePath &&
!compilerOptionsAffectDeclarationPath(compilerOptions, oldCompilerOptions!);
!compilerOptionsAffectDeclarationPath(compilerOptions, oldState.compilerOptions);
if (useOldState) {
// Copy old state's changed files set
oldState!.changedFilesSet?.forEach(value => state.changedFilesSet.add(value));
Expand Down
21 changes: 21 additions & 0 deletions src/testRunner/unittests/tsc/composite.ts
Expand Up @@ -81,5 +81,26 @@ namespace ts {
}),
commandLineArgs: ["--composite", "false", "--p", "src/project", "--tsBuildInfoFile", "null"],
});

verifyTscWithEdits({
scenario: "composite",
subScenario: "converting to modules",
fs: () => loadProjectFromFiles({
"/src/project/src/main.ts": "const x = 10;",
"/src/project/tsconfig.json": JSON.stringify({
compilerOptions: {
module: "none",
composite: true,
},
}),
}),
commandLineArgs: ["-p", "/src/project"],
edits: [
{
subScenario: "convert to modules",
modifyFs: fs => replaceText(fs, "/src/project/tsconfig.json", "none", "es2015"),
}
]
});
});
}
126 changes: 126 additions & 0 deletions tests/baselines/reference/tsc/composite/converting-to-modules.js
@@ -0,0 +1,126 @@
Input::
//// [/lib/lib.d.ts]
/// <reference no-default-lib="true"/>
interface Boolean {}
interface Function {}
interface CallableFunction {}
interface NewableFunction {}
interface IArguments {}
interface Number { toExponential: any; }
interface Object {}
interface RegExp {}
interface String { charAt: any; }
interface Array<T> { length: number; [n: number]: T; }
interface ReadonlyArray<T> {}
declare const console: { log(msg: any): void; };

//// [/src/project/src/main.ts]
const x = 10;

//// [/src/project/tsconfig.json]
{"compilerOptions":{"module":"none","composite":true}}



Output::
/lib/tsc -p /src/project
exitCode:: ExitStatus.Success


//// [/src/project/src/main.d.ts]
declare const x = 10;


//// [/src/project/src/main.js]
var x = 10;


//// [/src/project/tsconfig.tsbuildinfo]
{"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"}

//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt]
{
"program": {
"fileNames": [
"../../lib/lib.d.ts",
"./src/main.ts"
],
"fileInfos": {
"../../lib/lib.d.ts": {
"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; };",
"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; };",
"affectsGlobalScope": true
},
"./src/main.ts": {
"version": "5029505981-const x = 10;",
"signature": "-3198459068-declare const x = 10;\r\n",
"affectsGlobalScope": true
}
},
"options": {
"composite": true,
"module": 0
},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"./src/main.ts"
],
"latestChangedDtsFile": "./src/main.d.ts"
},
"version": "FakeTSVersion",
"size": 816
}



Change:: convert to modules
Input::
//// [/src/project/tsconfig.json]
{"compilerOptions":{"module":"es2015","composite":true}}



Output::
/lib/tsc -p /src/project
exitCode:: ExitStatus.Success


//// [/src/project/src/main.js] file written with same contents
//// [/src/project/tsconfig.tsbuildinfo]
{"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"}

//// [/src/project/tsconfig.tsbuildinfo.readable.baseline.txt]
{
"program": {
"fileNames": [
"../../lib/lib.d.ts",
"./src/main.ts"
],
"fileInfos": {
"../../lib/lib.d.ts": {
"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; };",
"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; };",
"affectsGlobalScope": true
},
"./src/main.ts": {
"version": "5029505981-const x = 10;",
"signature": "-3198459068-declare const x = 10;\r\n",
"affectsGlobalScope": true
}
},
"options": {
"composite": true,
"module": 5
},
"referencedMap": {},
"exportedModulesMap": {},
"semanticDiagnosticsPerFile": [
"../../lib/lib.d.ts",
"./src/main.ts"
],
"latestChangedDtsFile": "./src/main.d.ts"
},
"version": "FakeTSVersion",
"size": 859
}

0 comments on commit 14f9cbf

Please sign in to comment.