mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 11:24:29 -05:00
Fix incorrect lib condition again! (#58945)
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user