Skip to content

Fix incorrect lib condition again! #58945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2777,7 +2777,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
return true;
}

if (!options.noLib) {
if (options.noLib) {
return false;
}

Expand All @@ -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);
});
}
}

Expand Down
57 changes: 56 additions & 1 deletion src/testRunner/unittests/tsc/libraryResolution.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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`
/// <reference no-default-lib="true"/>
/// <reference lib="es6"/>
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,
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -442,14 +442,14 @@ 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)
/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/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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,14 +894,14 @@ 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)
/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/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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Loading