Skip to content

Commit 90402e7

Browse files
committed
Force inclusion of ES6, DOM iterable variants
1 parent 6f6efb4 commit 90402e7

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

src/compiler/program.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
18161816
}
18171817
else {
18181818
forEach(options.lib, (libFileName, index) => {
1819-
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile, index });
1819+
for (const p of pathsForLibFile(libFileName)) {
1820+
processRootFile(p, /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile, index });
1821+
}
18201822
});
18211823
}
18221824
}
@@ -3818,6 +3820,22 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
38183820
}
38193821
}
38203822

3823+
function pathsForLibFile(libFileName: string): string[] {
3824+
const names = [libFileName];
3825+
// Force the inclusion of ES6 and DOM's iterable libs.
3826+
switch (libFileName) {
3827+
case "lib.dom.d.ts":
3828+
names.push("lib.dom.iterable.d.ts");
3829+
// TODO: auto add dom.asynciterable.d.ts in es2018?
3830+
break;
3831+
case "lib.es5.d.ts":
3832+
names.push("lib.es2015.d.ts");
3833+
break;
3834+
}
3835+
3836+
return names.map(pathForLibFile);
3837+
}
3838+
38213839
function pathForLibFile(libFileName: string): string {
38223840
const existing = resolvedLibReferences?.get(libFileName);
38233841
if (existing) return existing.actual;
@@ -3888,7 +3906,12 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
38883906
forEach(file.libReferenceDirectives, (libReference, index) => {
38893907
const libFileName = getLibFileNameFromLibReference(libReference);
38903908
if (libFileName) {
3891-
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
3909+
for (const p of pathsForLibFile(libFileName)) {
3910+
if (file.fileName === p) {
3911+
continue;
3912+
}
3913+
processRootFile(p, /*isDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
3914+
}
38923915
}
38933916
else {
38943917
programDiagnostics.addFileProcessingDiagnostic({

src/compiler/utilitiesPublic.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -325,22 +325,7 @@ export const targetToLibMap: Map<ScriptTarget, string> = new Map([
325325

326326
export function getDefaultLibFileName(options: CompilerOptions): string {
327327
const target = getEmitScriptTarget(options);
328-
switch (target) {
329-
case ScriptTarget.ESNext:
330-
case ScriptTarget.ES2024:
331-
case ScriptTarget.ES2023:
332-
case ScriptTarget.ES2022:
333-
case ScriptTarget.ES2021:
334-
case ScriptTarget.ES2020:
335-
case ScriptTarget.ES2019:
336-
case ScriptTarget.ES2018:
337-
case ScriptTarget.ES2017:
338-
case ScriptTarget.ES2016:
339-
case ScriptTarget.ES2015:
340-
return targetToLibMap.get(target)!;
341-
default:
342-
return "lib.d.ts";
343-
}
328+
return targetToLibMap.get(target) ?? "lib.d.ts";
344329
}
345330

346331
export function textSpanEnd(span: TextSpan): number {

0 commit comments

Comments
 (0)