Skip to content

Commit

Permalink
Lock lib replacement behind option
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Jan 8, 2025
1 parent dd90bc2 commit 73c5a6b
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 8 deletions.
11 changes: 11 additions & 0 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4065,6 +4065,17 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const existing = resolvedLibProcessing?.get(libFileName);
if (existing) return existing;

if (!options.libReplacement) {
const result: LibResolution = {
resolution: {
resolvedModule: undefined,
},
actual: combinePaths(defaultLibraryPath, libFileName),
};
(resolvedLibProcessing ??= new Map()).set(libFileName, result);
return result;
}

if (structureIsReused !== StructureIsReused.Not && oldProgram && !hasInvalidatedLibResolutions(libFileName)) {
const oldResolution = oldProgram.resolvedLibReferences?.get(libFileName);
if (oldResolution) {
Expand Down
11 changes: 7 additions & 4 deletions src/testRunner/unittests/helpers/libraryResolution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ function getSysForLibResolution(libRedirection?: boolean, forTsserver?: boolean)
/// <reference lib="es5"/>
`,
"/home/src/workspace/projects/project1/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project1/typeroot1/sometype/index.d.ts": `export type TheNum = "type1";`,
"/home/src/workspace/projects/project2/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project2/index.ts": `export const y = 10`,
"/home/src/workspace/projects/project2/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project3/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project3/index.ts": `export const z = 10`,
"/home/src/workspace/projects/project3/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
}),
"/home/src/workspace/projects/project4/utils.d.ts": `export const y = 10;`,
"/home/src/workspace/projects/project4/index.ts": `export const z = 10`,
"/home/src/workspace/projects/project4/tsconfig.json": jsonToReadableText({
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true },
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true, libReplacement: libRedirection },
}),
[getTypeScriptLibTestLocation("dom")]: "interface DOMInterface { }",
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",
Expand Down Expand Up @@ -71,6 +71,7 @@ function getLibResolutionEditOptions(
typeRoots: ["./typeroot1", "./typeroot2"],
lib: ["es5", "dom"],
traceResolution: true,
libReplacement: true,
},
}),
),
Expand All @@ -90,6 +91,7 @@ function getLibResolutionEditOptions(
typeRoots: ["./typeroot1"],
lib: ["es5", "dom"],
traceResolution: true,
libReplacement: true,
},
}),
);
Expand Down Expand Up @@ -235,6 +237,7 @@ export function getSysForLibResolutionUnknown(): TestServerHost {
compilerOptions: {
composite: true,
traceResolution: true,
libReplacement: true,
},
}),
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",
Expand Down
3 changes: 2 additions & 1 deletion tests/cases/compiler/libTypeScriptOverrideSimple.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @traceResolution: true
// @libReplacement: true

// @Filename: /node_modules/@typescript/lib-dom/index.d.ts
interface ABC { abc: string }
Expand All @@ -8,4 +9,4 @@ const a: ABC = { abc: "Hello" }

// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
window.localStorage
3 changes: 2 additions & 1 deletion tests/cases/compiler/libTypeScriptOverrideSimpleConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @traceResolution: true
// @libReplacement: true

// @Filename: /somepath/node_modules/@typescript/lib-dom/index.d.ts
interface ABC { abc: string }
Expand All @@ -10,4 +11,4 @@ const a: ABC = { abc: "Hello" }

// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
window.localStorage
3 changes: 2 additions & 1 deletion tests/cases/compiler/libTypeScriptSubfileResolving.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @traceResolution: true
// @libReplacement: true

// @Filename: /node_modules/@typescript/lib-dom/index.d.ts
// NOOP
Expand All @@ -10,4 +11,4 @@ const a: DOMIterable = { abc: "Hello" }

// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
window.localStorage
3 changes: 2 additions & 1 deletion tests/cases/compiler/libTypeScriptSubfileResolvingConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @traceResolution: true
// @libReplacement: true

// @Filename: /somepath/node_modules/@typescript/lib-dom/index.d.ts
// NOOP
Expand All @@ -12,4 +13,4 @@ const a: DOMIterable = { abc: "Hello" }

// This should fail because libdom has been replaced
// by the module above ^
window.localStorage
window.localStorage

0 comments on commit 73c5a6b

Please sign in to comment.