Skip to content

Commit 220706e

Browse files
authored
Add new option "libReplacement" (#60829)
1 parent c5058f0 commit 220706e

File tree

49 files changed

+1230
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1230
-71
lines changed

src/compiler/commandLineParser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,14 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
865865
affectsBuildInfo: true,
866866
affectsSemanticDiagnostics: true,
867867
},
868+
{
869+
name: "libReplacement",
870+
type: "boolean",
871+
affectsProgramStructure: true,
872+
category: Diagnostics.Language_and_Environment,
873+
description: Diagnostics.Enable_lib_replacement,
874+
defaultValueDescription: true,
875+
},
868876

869877
// Strict Type Checks
870878
{

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -6502,6 +6502,10 @@
65026502
"category": "Error",
65036503
"code": 6807
65046504
},
6505+
"Enable lib replacement.": {
6506+
"category": "Message",
6507+
"code": 6808
6508+
},
65056509

65066510
"one of:": {
65076511
"category": "Message",

src/compiler/program.ts

+11
Original file line numberDiff line numberDiff line change
@@ -3937,6 +3937,17 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
39373937
const existing = resolvedLibProcessing?.get(libFileName);
39383938
if (existing) return existing;
39393939

3940+
if (options.libReplacement === false) {
3941+
const result: LibResolution = {
3942+
resolution: {
3943+
resolvedModule: undefined,
3944+
},
3945+
actual: combinePaths(defaultLibraryPath, libFileName),
3946+
};
3947+
(resolvedLibProcessing ??= new Map()).set(libFileName, result);
3948+
return result;
3949+
}
3950+
39403951
if (structureIsReused !== StructureIsReused.Not && oldProgram && !hasInvalidatedLibResolutions(libFileName)) {
39413952
const oldResolution = oldProgram.resolvedLibReferences?.get(libFileName);
39423953
if (oldResolution) {

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7411,6 +7411,7 @@ export interface CompilerOptions {
74117411
/** @deprecated */
74127412
keyofStringsOnly?: boolean;
74137413
lib?: string[];
7414+
libReplacement?: boolean;
74147415
/** @internal */ listEmittedFiles?: boolean;
74157416
/** @internal */ listFiles?: boolean;
74167417
/** @internal */ explainFiles?: boolean;

src/testRunner/unittests/helpers/libraryResolution.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,23 @@ function getSysForLibResolution(libRedirection?: boolean, forTsserver?: boolean)
2121
/// <reference lib="es5"/>
2222
`,
2323
"/home/src/workspace/projects/project1/tsconfig.json": jsonToReadableText({
24-
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true },
24+
compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
2525
}),
2626
"/home/src/workspace/projects/project1/typeroot1/sometype/index.d.ts": `export type TheNum = "type1";`,
2727
"/home/src/workspace/projects/project2/utils.d.ts": `export const y = 10;`,
2828
"/home/src/workspace/projects/project2/index.ts": `export const y = 10`,
2929
"/home/src/workspace/projects/project2/tsconfig.json": jsonToReadableText({
30-
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
30+
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
3131
}),
3232
"/home/src/workspace/projects/project3/utils.d.ts": `export const y = 10;`,
3333
"/home/src/workspace/projects/project3/index.ts": `export const z = 10`,
3434
"/home/src/workspace/projects/project3/tsconfig.json": jsonToReadableText({
35-
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true },
35+
compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true, libReplacement: libRedirection },
3636
}),
3737
"/home/src/workspace/projects/project4/utils.d.ts": `export const y = 10;`,
3838
"/home/src/workspace/projects/project4/index.ts": `export const z = 10`,
3939
"/home/src/workspace/projects/project4/tsconfig.json": jsonToReadableText({
40-
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true },
40+
compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true, libReplacement: libRedirection },
4141
}),
4242
[getTypeScriptLibTestLocation("dom")]: "interface DOMInterface { }",
4343
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",
@@ -71,6 +71,7 @@ function getLibResolutionEditOptions(
7171
typeRoots: ["./typeroot1", "./typeroot2"],
7272
lib: ["es5", "dom"],
7373
traceResolution: true,
74+
libReplacement: true,
7475
},
7576
}),
7677
),
@@ -90,6 +91,7 @@ function getLibResolutionEditOptions(
9091
typeRoots: ["./typeroot1"],
9192
lib: ["es5", "dom"],
9293
traceResolution: true,
94+
libReplacement: true,
9395
},
9496
}),
9597
);
@@ -235,6 +237,7 @@ export function getSysForLibResolutionUnknown(): TestServerHost {
235237
compilerOptions: {
236238
composite: true,
237239
traceResolution: true,
240+
libReplacement: true,
238241
},
239242
}),
240243
[getTypeScriptLibTestLocation("webworker")]: "interface WebWorkerInterface { }",

tests/baselines/reference/api/typescript.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7027,6 +7027,7 @@ declare namespace ts {
70277027
/** @deprecated */
70287028
keyofStringsOnly?: boolean;
70297029
lib?: string[];
7030+
libReplacement?: boolean;
70307031
locale?: string;
70317032
mapRoot?: string;
70327033
maxNodeModuleJsDepth?: number;

tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es5", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
"jsx": "react", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
"lib": ["es5","es2015.promise"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
"lib": ["es5","es2015.core"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
1515
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
1616
// "jsx": "preserve", /* Specify what JSX code is generated. */
17+
// "libReplacement": true, /* Enable lib replacement. */
1718
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
1819
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
1920
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"libReplacement": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[]

0 commit comments

Comments
 (0)