From beb375a9cac75ba29abb707e6736e2d645ddb2f0 Mon Sep 17 00:00:00 2001 From: Sheetal Nandi Date: Thu, 20 Jun 2024 13:18:39 -0700 Subject: [PATCH] Fix incorrect lib condition again! (#58945) --- src/compiler/program.ts | 8 +- .../unittests/tsc/libraryResolution.ts | 57 +++- .../with-config-with-redirection.js | 10 +- .../tsbuild/libraryResolution/with-config.js | 10 +- .../with-config-with-redirection.js | 10 +- .../libraryResolution/with-config.js | 10 +- .../libraryResolution/when-noLib-toggles.js | 267 ++++++++++++++++++ ...of-the-file-skips-default-lib-inclusion.js | 141 +++++++++ .../with-config-with-redirection.js | 2 +- .../tsc/libraryResolution/with-config.js | 2 +- .../with-config-with-redirection.js | 4 +- .../tscWatch/libraryResolution/with-config.js | 4 +- .../without-config-with-redirection.js | 4 +- .../libraryResolution/without-config.js | 4 +- 14 files changed, 496 insertions(+), 37 deletions(-) create mode 100644 tests/baselines/reference/tsc/libraryResolution/when-noLib-toggles.js create mode 100644 tests/baselines/reference/tsc/libraryResolution/when-one-of-the-file-skips-default-lib-inclusion.js diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 7410d46298b..da5ae9592cc 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -2777,7 +2777,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg return true; } - if (!options.noLib) { + if (options.noLib) { return false; } @@ -2788,7 +2788,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg return equalityComparer(file.fileName, getDefaultLibraryFileName()); } else { - return some(options.lib, libFileName => equalityComparer(file.fileName, resolvedLibReferences!.get(libFileName)!.actual)); + return some(options.lib, libFileName => { + // We might not have resolved lib if one of the root file included contained no-default-lib = true + const resolvedLib = resolvedLibReferences!.get(libFileName); + return !!resolvedLib && equalityComparer(file.fileName, resolvedLib.actual); + }); } } diff --git a/src/testRunner/unittests/tsc/libraryResolution.ts b/src/testRunner/unittests/tsc/libraryResolution.ts index 23d73ceb48d..3cf17a08cd5 100644 --- a/src/testRunner/unittests/tsc/libraryResolution.ts +++ b/src/testRunner/unittests/tsc/libraryResolution.ts @@ -1,9 +1,16 @@ +import { dedent } from "../../_namespaces/Utils.js"; +import { jsonToReadableText } from "../helpers.js"; +import { libContent } from "../helpers/contents.js"; import { getCommandLineArgsForLibResolution, getFsForLibResolution, getFsForLibResolutionUnknown, } from "../helpers/libraryResolution.js"; -import { verifyTsc } from "../helpers/tsc.js"; +import { + noChangeRun, + verifyTsc, +} from "../helpers/tsc.js"; +import { loadProjectFromFiles } from "../helpers/vfs.js"; describe("unittests:: tsc:: libraryResolution:: library file resolution", () => { function verify(libRedirection?: true, withoutConfig?: true) { @@ -27,4 +34,52 @@ describe("unittests:: tsc:: libraryResolution:: library file resolution", () => commandLineArgs: getCommandLineArgsForLibResolution(/*withoutConfig*/ undefined), baselinePrograms: true, }); + + verifyTsc({ + scenario: "libraryResolution", + subScenario: "when noLib toggles", + fs: () => + loadProjectFromFiles({ + "/src/a.d.ts": `declare const a = "hello";`, + "/src/b.ts": `const b = 10;`, + "/src/tsconfig.json": jsonToReadableText({ + compilerOptions: { + declaration: true, + incremental: true, + lib: ["es6"], + }, + }), + "/lib/lib.es2015.d.ts": libContent, + }), + commandLineArgs: ["-p", "/src/tsconfig.json"], + edits: [ + { + ...noChangeRun, + commandLineArgs: ["-p", "/src/tsconfig.json", "--noLib"], + }, + ], + baselinePrograms: true, + }); + + verifyTsc({ + scenario: "libraryResolution", + subScenario: "when one of the file skips default lib inclusion", + fs: () => + loadProjectFromFiles({ + "/src/a.d.ts": dedent` + /// + /// + declare const a = "hello"; + `, + "/src/b.d.ts": `export const b = 10;`, + "/src/tsconfig.json": jsonToReadableText({ + compilerOptions: { + lib: ["es6", "dom"], + }, + }), + "/lib/lib.es2015.d.ts": libContent, + }), + commandLineArgs: ["-p", "/src/tsconfig.json", "-i", "--explainFiles"], + baselinePrograms: true, + }); }); diff --git a/tests/baselines/reference/tsbuild/libraryResolution/with-config-with-redirection.js b/tests/baselines/reference/tsbuild/libraryResolution/with-config-with-redirection.js index 3458fb16b2c..398b621b1de 100644 --- a/tests/baselines/reference/tsbuild/libraryResolution/with-config-with-redirection.js +++ b/tests/baselines/reference/tsbuild/libraryResolution/with-config-with-redirection.js @@ -442,7 +442,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts during emit) /home/src/projects/project1/file2.ts (computed .d.ts during emit) @@ -450,6 +449,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project2/index.ts", @@ -481,9 +481,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project2/index.ts (computed .d.ts during emit) /home/src/projects/project2/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project3/index.ts", @@ -515,9 +515,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project3/index.ts (computed .d.ts during emit) /home/src/projects/project3/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project4/index.ts", @@ -552,10 +552,10 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-esnext/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/project4/index.ts (computed .d.ts during emit) /home/src/projects/project4/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) //// [/home/src/projects/project1/file.d.ts] diff --git a/tests/baselines/reference/tsbuild/libraryResolution/with-config.js b/tests/baselines/reference/tsbuild/libraryResolution/with-config.js index c3633b71f80..1e8a07c34f3 100644 --- a/tests/baselines/reference/tsbuild/libraryResolution/with-config.js +++ b/tests/baselines/reference/tsbuild/libraryResolution/with-config.js @@ -457,7 +457,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) @@ -466,6 +465,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/index.ts (computed .d.ts during emit) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project2/index.ts", @@ -497,9 +497,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/project2/index.ts (computed .d.ts during emit) /home/src/projects/project2/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project3/index.ts", @@ -531,9 +531,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/project3/index.ts (computed .d.ts during emit) /home/src/projects/project3/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project4/index.ts", @@ -568,10 +568,10 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.esnext.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) -/home/src/lib/lib.webworker.d.ts (used version) /home/src/projects/project4/index.ts (computed .d.ts during emit) /home/src/projects/project4/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) +/home/src/lib/lib.webworker.d.ts (used version) //// [/home/src/projects/project1/file.d.ts] diff --git a/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config-with-redirection.js b/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config-with-redirection.js index cd1481045a6..5471f68b606 100644 --- a/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config-with-redirection.js +++ b/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config-with-redirection.js @@ -894,7 +894,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts during emit) /home/src/projects/project1/file2.ts (computed .d.ts during emit) @@ -902,6 +901,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project2/index.ts", @@ -935,9 +935,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project2/index.ts (computed .d.ts during emit) /home/src/projects/project2/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project3/index.ts", @@ -971,9 +971,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project3/index.ts (computed .d.ts during emit) /home/src/projects/project3/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) Program root files: [ "/home/src/projects/project4/index.ts", @@ -1010,9 +1010,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-esnext/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/project4/index.ts (computed .d.ts during emit) /home/src/projects/project4/utils.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) exitCode:: ExitStatus.undefined diff --git a/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config.js b/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config.js index fcce8c8fc92..b5ad77dbc59 100644 --- a/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config.js +++ b/tests/baselines/reference/tsbuildWatch/libraryResolution/with-config.js @@ -909,7 +909,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) @@ -918,6 +917,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/index.ts (computed .d.ts during emit) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project2/index.ts", @@ -951,9 +951,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/project2/index.ts (computed .d.ts during emit) /home/src/projects/project2/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project3/index.ts", @@ -987,9 +987,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/project3/index.ts (computed .d.ts during emit) /home/src/projects/project3/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) Program root files: [ "/home/src/projects/project4/index.ts", @@ -1026,9 +1026,9 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.esnext.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) -/home/src/lib/lib.webworker.d.ts (used version) /home/src/projects/project4/index.ts (computed .d.ts during emit) /home/src/projects/project4/utils.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) +/home/src/lib/lib.webworker.d.ts (used version) exitCode:: ExitStatus.undefined diff --git a/tests/baselines/reference/tsc/libraryResolution/when-noLib-toggles.js b/tests/baselines/reference/tsc/libraryResolution/when-noLib-toggles.js new file mode 100644 index 00000000000..f143d7bb7aa --- /dev/null +++ b/tests/baselines/reference/tsc/libraryResolution/when-noLib-toggles.js @@ -0,0 +1,267 @@ +currentDirectory:: / useCaseSensitiveFileNames: false +Input:: +//// [/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/lib/lib.es2015.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/src/a.d.ts] +declare const a = "hello"; + +//// [/src/b.ts] +const b = 10; + +//// [/src/tsconfig.json] +{ + "compilerOptions": { + "declaration": true, + "incremental": true, + "lib": [ + "es6" + ] + } +} + + + +Output:: +/lib/tsc -p /src/tsconfig.json +exitCode:: ExitStatus.Success +Program root files: [ + "/src/a.d.ts", + "/src/b.ts" +] +Program options: { + "declaration": true, + "incremental": true, + "lib": [ + "lib.es2015.d.ts" + ], + "project": "/src/tsconfig.json", + "configFilePath": "/src/tsconfig.json" +} +Program structureReused: Not +Program files:: +/lib/lib.es2015.d.ts +/src/a.d.ts +/src/b.ts + +Semantic diagnostics in builder refreshed for:: +/lib/lib.es2015.d.ts +/src/a.d.ts +/src/b.ts + +Shape signatures in builder refreshed for:: +/lib/lib.es2015.d.ts (used version) +/src/a.d.ts (used version) +/src/b.ts (computed .d.ts during emit) + + +//// [/src/b.d.ts] +declare const b = 10; + + +//// [/src/b.js] +var b = 10; + + +//// [/src/tsconfig.tsbuildinfo] +{"fileNames":["../lib/lib.es2015.d.ts","./a.d.ts","./b.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"-5371488691-declare const a = \"hello\";","affectsGlobalScope":true},{"version":"2387014439-const b = 10;","signature":"-1009346399-declare const b = 10;\n","affectsGlobalScope":true}],"root":[2,3],"options":{"declaration":true},"version":"FakeTSVersion"} + +//// [/src/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "fileNames": [ + "../lib/lib.es2015.d.ts", + "./a.d.ts", + "./b.ts" + ], + "fileInfos": { + "../lib/lib.es2015.d.ts": { + "original": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./a.d.ts": { + "original": { + "version": "-5371488691-declare const a = \"hello\";", + "affectsGlobalScope": true + }, + "version": "-5371488691-declare const a = \"hello\";", + "signature": "-5371488691-declare const a = \"hello\";", + "affectsGlobalScope": true + }, + "./b.ts": { + "original": { + "version": "2387014439-const b = 10;", + "signature": "-1009346399-declare const b = 10;\n", + "affectsGlobalScope": true + }, + "version": "2387014439-const b = 10;", + "signature": "-1009346399-declare const b = 10;\n", + "affectsGlobalScope": true + } + }, + "root": [ + [ + 2, + "./a.d.ts" + ], + [ + 3, + "./b.ts" + ] + ], + "options": { + "declaration": true + }, + "version": "FakeTSVersion", + "size": 819 +} + + + +Change:: no-change-run +Input:: + + +Output:: +/lib/tsc -p /src/tsconfig.json --noLib +error TS2318: Cannot find global type 'Array'. + +error TS2318: Cannot find global type 'Boolean'. + +error TS2318: Cannot find global type 'Function'. + +error TS2318: Cannot find global type 'IArguments'. + +error TS2318: Cannot find global type 'Number'. + +error TS2318: Cannot find global type 'Object'. + +error TS2318: Cannot find global type 'RegExp'. + +error TS2318: Cannot find global type 'String'. + +src/tsconfig.json:5:5 - error TS5053: Option 'lib' cannot be specified with option 'noLib'. + +5 "lib": [ +   ~~~~~ + + +Found 9 errors in the same file, starting at: src/tsconfig.json:5 + +exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated +Program root files: [ + "/src/a.d.ts", + "/src/b.ts" +] +Program options: { + "declaration": true, + "incremental": true, + "lib": [ + "lib.es2015.d.ts" + ], + "project": "/src/tsconfig.json", + "noLib": true, + "configFilePath": "/src/tsconfig.json" +} +Program structureReused: Not +Program files:: +/src/a.d.ts +/src/b.ts + +No cached semantic diagnostics in the builder:: + +Shape signatures in builder refreshed for:: +/src/a.d.ts (used version) +/src/b.ts (computed .d.ts) + + +//// [/src/b.d.ts] file written with same contents +//// [/src/b.js] file written with same contents +//// [/src/tsconfig.tsbuildinfo] +{"fileNames":["./a.d.ts","./b.ts"],"fileInfos":[{"version":"-5371488691-declare const a = \"hello\";","affectsGlobalScope":true},{"version":"2387014439-const b = 10;","signature":"-1009346399-declare const b = 10;\n","affectsGlobalScope":true}],"root":[1,2],"options":{"declaration":true},"semanticDiagnosticsPerFile":[1,2],"version":"FakeTSVersion"} + +//// [/src/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "fileNames": [ + "./a.d.ts", + "./b.ts" + ], + "fileInfos": { + "./a.d.ts": { + "original": { + "version": "-5371488691-declare const a = \"hello\";", + "affectsGlobalScope": true + }, + "version": "-5371488691-declare const a = \"hello\";", + "signature": "-5371488691-declare const a = \"hello\";", + "affectsGlobalScope": true + }, + "./b.ts": { + "original": { + "version": "2387014439-const b = 10;", + "signature": "-1009346399-declare const b = 10;\n", + "affectsGlobalScope": true + }, + "version": "2387014439-const b = 10;", + "signature": "-1009346399-declare const b = 10;\n", + "affectsGlobalScope": true + } + }, + "root": [ + [ + 1, + "./a.d.ts" + ], + [ + 2, + "./b.ts" + ] + ], + "options": { + "declaration": true + }, + "semanticDiagnosticsPerFile": [ + [ + "./a.d.ts", + "not cached" + ], + [ + "./b.ts", + "not cached" + ] + ], + "version": "FakeTSVersion", + "size": 350 +} + diff --git a/tests/baselines/reference/tsc/libraryResolution/when-one-of-the-file-skips-default-lib-inclusion.js b/tests/baselines/reference/tsc/libraryResolution/when-one-of-the-file-skips-default-lib-inclusion.js new file mode 100644 index 00000000000..53a8e63bef9 --- /dev/null +++ b/tests/baselines/reference/tsc/libraryResolution/when-one-of-the-file-skips-default-lib-inclusion.js @@ -0,0 +1,141 @@ +currentDirectory:: / useCaseSensitiveFileNames: false +Input:: +//// [/lib/lib.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/lib/lib.es2015.d.ts] +/// +interface Boolean {} +interface Function {} +interface CallableFunction {} +interface NewableFunction {} +interface IArguments {} +interface Number { toExponential: any; } +interface Object {} +interface RegExp {} +interface String { charAt: any; } +interface Array { length: number; [n: number]: T; } +interface ReadonlyArray {} +declare const console: { log(msg: any): void; }; + +//// [/src/a.d.ts] +/// +/// +declare const a = "hello"; + + +//// [/src/b.d.ts] +export const b = 10; + +//// [/src/tsconfig.json] +{ + "compilerOptions": { + "lib": [ + "es6", + "dom" + ] + } +} + + + +Output:: +/lib/tsc -p /src/tsconfig.json -i --explainFiles +lib/lib.es2015.d.ts + Library referenced via 'es6' from file 'src/a.d.ts' +src/a.d.ts + Matched by default include pattern '**/*' +src/b.d.ts + Matched by default include pattern '**/*' +exitCode:: ExitStatus.Success +Program root files: [ + "/src/a.d.ts", + "/src/b.d.ts" +] +Program options: { + "lib": [ + "lib.es2015.d.ts", + "lib.dom.d.ts" + ], + "project": "/src/tsconfig.json", + "incremental": true, + "explainFiles": true, + "configFilePath": "/src/tsconfig.json" +} +Program structureReused: Not +Program files:: +/lib/lib.es2015.d.ts +/src/a.d.ts +/src/b.d.ts + +Semantic diagnostics in builder refreshed for:: +/lib/lib.es2015.d.ts +/src/a.d.ts +/src/b.d.ts + +Shape signatures in builder refreshed for:: +/lib/lib.es2015.d.ts (used version) +/src/b.d.ts (used version) +/src/a.d.ts (used version) + + +//// [/src/tsconfig.tsbuildinfo] +{"fileNames":["../lib/lib.es2015.d.ts","./a.d.ts","./b.d.ts"],"fileInfos":[{"version":"3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true},{"version":"10808475215-/// \n/// \ndeclare const a = \"hello\";\n","affectsGlobalScope":true},"-13368947479-export const b = 10;"],"root":[2,3],"version":"FakeTSVersion"} + +//// [/src/tsconfig.tsbuildinfo.readable.baseline.txt] +{ + "fileNames": [ + "../lib/lib.es2015.d.ts", + "./a.d.ts", + "./b.d.ts" + ], + "fileInfos": { + "../lib/lib.es2015.d.ts": { + "original": { + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "version": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "signature": "3858781397-/// \ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array { length: number; [n: number]: T; }\ninterface ReadonlyArray {}\ndeclare const console: { log(msg: any): void; };", + "affectsGlobalScope": true + }, + "./a.d.ts": { + "original": { + "version": "10808475215-/// \n/// \ndeclare const a = \"hello\";\n", + "affectsGlobalScope": true + }, + "version": "10808475215-/// \n/// \ndeclare const a = \"hello\";\n", + "signature": "10808475215-/// \n/// \ndeclare const a = \"hello\";\n", + "affectsGlobalScope": true + }, + "./b.d.ts": { + "version": "-13368947479-export const b = 10;", + "signature": "-13368947479-export const b = 10;" + } + }, + "root": [ + [ + 2, + "./a.d.ts" + ], + [ + 3, + "./b.d.ts" + ] + ], + "version": "FakeTSVersion", + "size": 785 +} + diff --git a/tests/baselines/reference/tsc/libraryResolution/with-config-with-redirection.js b/tests/baselines/reference/tsc/libraryResolution/with-config-with-redirection.js index 9d33ed99912..35d03cae679 100644 --- a/tests/baselines/reference/tsc/libraryResolution/with-config-with-redirection.js +++ b/tests/baselines/reference/tsc/libraryResolution/with-config-with-redirection.js @@ -331,7 +331,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts during emit) /home/src/projects/project1/file2.ts (computed .d.ts during emit) @@ -339,6 +338,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) //// [/home/src/projects/project1/file.d.ts] diff --git a/tests/baselines/reference/tsc/libraryResolution/with-config.js b/tests/baselines/reference/tsc/libraryResolution/with-config.js index eca7f112c67..805104d081f 100644 --- a/tests/baselines/reference/tsc/libraryResolution/with-config.js +++ b/tests/baselines/reference/tsc/libraryResolution/with-config.js @@ -335,7 +335,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) @@ -344,6 +343,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/index.ts (computed .d.ts during emit) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) //// [/home/src/projects/project1/file.d.ts] diff --git a/tests/baselines/reference/tscWatch/libraryResolution/with-config-with-redirection.js b/tests/baselines/reference/tscWatch/libraryResolution/with-config-with-redirection.js index ad9ceac0e9e..0b3d485734c 100644 --- a/tests/baselines/reference/tscWatch/libraryResolution/with-config-with-redirection.js +++ b/tests/baselines/reference/tscWatch/libraryResolution/with-config-with-redirection.js @@ -531,7 +531,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts during emit) /home/src/projects/project1/file2.ts (computed .d.ts during emit) @@ -539,6 +538,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) exitCode:: ExitStatus.undefined @@ -2436,7 +2436,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.webworker.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/file2.ts (computed .d.ts) @@ -2732,7 +2731,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/file2.ts (computed .d.ts) diff --git a/tests/baselines/reference/tscWatch/libraryResolution/with-config.js b/tests/baselines/reference/tscWatch/libraryResolution/with-config.js index 9a4f6c5dfdc..d3c89775e9e 100644 --- a/tests/baselines/reference/tscWatch/libraryResolution/with-config.js +++ b/tests/baselines/reference/tscWatch/libraryResolution/with-config.js @@ -535,7 +535,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) @@ -544,6 +543,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/index.ts (computed .d.ts during emit) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/typeroot1/sometype/index.d.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) exitCode:: ExitStatus.undefined @@ -2417,7 +2417,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/file2.ts (computed .d.ts) /home/src/projects/project1/index.ts (computed .d.ts) @@ -2724,7 +2723,6 @@ Semantic diagnostics in builder refreshed for:: Shape signatures in builder refreshed for:: /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/file2.ts (computed .d.ts) /home/src/projects/project1/index.ts (computed .d.ts) diff --git a/tests/baselines/reference/tscWatch/libraryResolution/without-config-with-redirection.js b/tests/baselines/reference/tscWatch/libraryResolution/without-config-with-redirection.js index 8c888d505b6..93f2a70c74c 100644 --- a/tests/baselines/reference/tscWatch/libraryResolution/without-config-with-redirection.js +++ b/tests/baselines/reference/tscWatch/libraryResolution/without-config-with-redirection.js @@ -362,13 +362,13 @@ project1/file2.ts Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/file.ts (used version) /home/src/projects/project1/index.ts (used version) /home/src/projects/project1/file2.ts (used version) /home/src/projects/node_modules/@typescript/lib-es5/index.d.ts (used version) +/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) exitCode:: ExitStatus.undefined @@ -1106,7 +1106,6 @@ No cached semantic diagnostics in the builder:: Shape signatures in builder refreshed for:: /home/src/lib/lib.webworker.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/index.ts (computed .d.ts) @@ -1268,7 +1267,6 @@ No cached semantic diagnostics in the builder:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) /home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts (used version) -/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts (used version) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) /home/src/projects/project1/index.ts (computed .d.ts) diff --git a/tests/baselines/reference/tscWatch/libraryResolution/without-config.js b/tests/baselines/reference/tscWatch/libraryResolution/without-config.js index ca28625b0b7..7fe78260f97 100644 --- a/tests/baselines/reference/tscWatch/libraryResolution/without-config.js +++ b/tests/baselines/reference/tscWatch/libraryResolution/without-config.js @@ -362,7 +362,6 @@ project1/file2.ts Shape signatures in builder refreshed for:: /home/src/lib/lib.es5.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.webworker.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/core.d.ts (used version) @@ -370,6 +369,7 @@ Shape signatures in builder refreshed for:: /home/src/projects/project1/file.ts (used version) /home/src/projects/project1/index.ts (used version) /home/src/projects/project1/file2.ts (used version) +/home/src/lib/lib.dom.d.ts (used version) exitCode:: ExitStatus.undefined @@ -1102,7 +1102,6 @@ No cached semantic diagnostics in the builder:: Shape signatures in builder refreshed for:: /home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts) @@ -1274,7 +1273,6 @@ No cached semantic diagnostics in the builder:: Shape signatures in builder refreshed for:: /home/src/lib/lib.webworker.d.ts (used version) -/home/src/lib/lib.dom.d.ts (used version) /home/src/lib/lib.scripthost.d.ts (used version) /home/src/projects/project1/utils.d.ts (used version) /home/src/projects/project1/file.ts (computed .d.ts)