Fix incorrect lib condition again! (#58945)

This commit is contained in:
Sheetal Nandi
2024-06-20 13:18:39 -07:00
committed by GitHub
parent ef079c9dd3
commit beb375a9ca
14 changed files with 496 additions and 37 deletions

View File

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

View File

@@ -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`
/// <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,
});
});