Skip to content

Commit c04133d

Browse files
committed
Remove no-default-lib support
1 parent e9bcbe6 commit c04133d

40 files changed

+85
-1394
lines changed

Herebyfile.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const libs = memoize(() => {
5252
/** @type {{ libs: string[]; paths: Record<string, string | undefined>; }} */
5353
const libraries = readJson("./src/lib/libs.json");
5454
const libs = libraries.libs.map(lib => {
55-
const relativeSources = ["header.d.ts", lib + ".d.ts"];
55+
const relativeSources = [lib + ".d.ts"];
5656
const relativeTarget = libraries.paths && libraries.paths[lib] || ("lib." + lib + ".d.ts");
5757
const sources = relativeSources.map(s => path.posix.join("src/lib", s));
5858
const target = `built/local/${relativeTarget}`;

src/compiler/builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function createBuilderProgramState(
412412

413413
if (canCopySemanticDiagnostics) {
414414
if (sourceFile.isDeclarationFile && !copyDeclarationFileDiagnostics) return;
415-
if (sourceFile.hasNoDefaultLib && !copyLibFileDiagnostics) return;
415+
if (newProgram.isSourceFileDefaultLibrary(sourceFile) && !copyLibFileDiagnostics) return;
416416

417417
// Unchanged file copy diagnostics
418418
const diagnostics = oldState!.semanticDiagnosticsPerFile.get(sourceFilePath);

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21504,15 +21504,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2150421504
let issuedElaboration = false;
2150521505
if (!targetProp) {
2150621506
const indexInfo = getApplicableIndexInfo(target, nameType);
21507-
if (indexInfo && indexInfo.declaration && !getSourceFileOfNode(indexInfo.declaration).hasNoDefaultLib) {
21507+
if (indexInfo && indexInfo.declaration && !host.isSourceFileDefaultLibrary(getSourceFileOfNode(indexInfo.declaration))) {
2150821508
issuedElaboration = true;
2150921509
addRelatedInfo(reportedDiag, createDiagnosticForNode(indexInfo.declaration, Diagnostics.The_expected_type_comes_from_this_index_signature));
2151021510
}
2151121511
}
2151221512

2151321513
if (!issuedElaboration && (targetProp && length(targetProp.declarations) || target.symbol && length(target.symbol.declarations))) {
2151421514
const targetNode = targetProp && length(targetProp.declarations) ? targetProp.declarations![0] : target.symbol.declarations![0];
21515-
if (!getSourceFileOfNode(targetNode).hasNoDefaultLib) {
21515+
if (!host.isSourceFileDefaultLibrary(getSourceFileOfNode(targetNode))) {
2151621516
addRelatedInfo(
2151721517
reportedDiag,
2151821518
createDiagnosticForNode(

src/compiler/emitter.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4286,18 +4286,14 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
42864286
}
42874287

42884288
function emitSyntheticTripleSlashReferencesIfNeeded(node: Bundle) {
4289-
emitTripleSlashDirectives(!!node.hasNoDefaultLib, node.syntheticFileReferences || [], node.syntheticTypeReferences || [], node.syntheticLibReferences || []);
4289+
emitTripleSlashDirectives(node.syntheticFileReferences || [], node.syntheticTypeReferences || [], node.syntheticLibReferences || []);
42904290
}
42914291

42924292
function emitTripleSlashDirectivesIfNeeded(node: SourceFile) {
4293-
if (node.isDeclarationFile) emitTripleSlashDirectives(node.hasNoDefaultLib, node.referencedFiles, node.typeReferenceDirectives, node.libReferenceDirectives);
4293+
if (node.isDeclarationFile) emitTripleSlashDirectives(node.referencedFiles, node.typeReferenceDirectives, node.libReferenceDirectives);
42944294
}
42954295

4296-
function emitTripleSlashDirectives(hasNoDefaultLib: boolean, files: readonly FileReference[], types: readonly FileReference[], libs: readonly FileReference[]) {
4297-
if (hasNoDefaultLib) {
4298-
writeComment(`/// <reference no-default-lib="true"/>`);
4299-
writeLine();
4300-
}
4296+
function emitTripleSlashDirectives(files: readonly FileReference[], types: readonly FileReference[], libs: readonly FileReference[]) {
43014297
if (currentSourceFile && currentSourceFile.moduleName) {
43024298
writeComment(`/// <amd-module name="${currentSourceFile.moduleName}" />`);
43034299
writeLine();

src/compiler/factory/nodeFactory.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6181,16 +6181,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
61816181
isDeclarationFile = node.isDeclarationFile,
61826182
referencedFiles = node.referencedFiles,
61836183
typeReferenceDirectives = node.typeReferenceDirectives,
6184-
hasNoDefaultLib = node.hasNoDefaultLib,
6184+
_hasNoDefaultLib = false,
61856185
libReferenceDirectives = node.libReferenceDirectives,
61866186
) {
61876187
return node.statements !== statements
61886188
|| node.isDeclarationFile !== isDeclarationFile
61896189
|| node.referencedFiles !== referencedFiles
61906190
|| node.typeReferenceDirectives !== typeReferenceDirectives
6191-
|| node.hasNoDefaultLib !== hasNoDefaultLib
61926191
|| node.libReferenceDirectives !== libReferenceDirectives
6193-
? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, hasNoDefaultLib, libReferenceDirectives), node)
6192+
? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, /*hasNoDefaultLib*/ false, libReferenceDirectives), node)
61946193
: node;
61956194
}
61966195

@@ -6201,7 +6200,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
62016200
node.syntheticFileReferences = undefined;
62026201
node.syntheticTypeReferences = undefined;
62036202
node.syntheticLibReferences = undefined;
6204-
node.hasNoDefaultLib = undefined;
62056203
return node;
62066204
}
62076205

src/compiler/parser.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10617,7 +10617,6 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
1061710617
context.typeReferenceDirectives = [];
1061810618
context.libReferenceDirectives = [];
1061910619
context.amdDependencies = [];
10620-
context.hasNoDefaultLib = false;
1062110620
context.pragmas!.forEach((entryOrList, key) => { // TODO: GH#18217
1062210621
// TODO: The below should be strongly type-guarded and not need casts/explicit annotations, since entryOrList is related to
1062310622
// key and key is constrained to a union; but it's not (see GH#21483 for at least partial fix) :(
@@ -10630,7 +10629,7 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
1063010629
const { types, lib, path, ["resolution-mode"]: res, preserve: _preserve } = arg.arguments;
1063110630
const preserve = _preserve === "true" ? true : undefined;
1063210631
if (arg.arguments["no-default-lib"] === "true") {
10633-
context.hasNoDefaultLib = true;
10632+
// This has been removed; parse but ignore it.
1063410633
}
1063510634
else if (types) {
1063610635
const parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);

src/compiler/program.ts

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
15771577
const host = createProgramOptionsHost || createCompilerHost(options);
15781578
const configParsingHost = parseConfigHostFromCompilerHostLike(host);
15791579

1580-
let skipDefaultLib = options.noLib;
15811580
const getDefaultLibraryFileName = memoize(() => host.getDefaultLibFileName(options));
15821581
const defaultLibraryPath = host.getDefaultLibLocation ? host.getDefaultLibLocation() : getDirectoryPath(getDefaultLibraryFileName());
15831582

@@ -1708,6 +1707,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
17081707
* - undefined otherwise
17091708
*/
17101709
const filesByName = new Map<Path, SourceFile | false | undefined>();
1710+
const libFiles = new Set<Path>();
17111711
let missingFileNames = new Map<Path, string>();
17121712
// stores 'filename -> file association' ignoring case
17131713
// used to track cases when two file names differ only in casing
@@ -1779,7 +1779,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
17791779
}
17801780

17811781
tracing?.push(tracing.Phase.Program, "processRootFiles", { count: rootNames.length });
1782-
forEach(rootNames, (name, index) => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, { kind: FileIncludeKind.RootFile, index }));
1782+
forEach(rootNames, (name, index) => processRootFile(name, /*isDefaultLib*/ false, { kind: FileIncludeKind.RootFile, index }));
17831783
tracing?.pop();
17841784

17851785
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
@@ -1808,20 +1808,16 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
18081808
tracing?.pop();
18091809
}
18101810

1811-
// Do not process the default library if:
1812-
// - The '--noLib' flag is used.
1813-
// - A 'no-default-lib' reference comment is encountered in
1814-
// processing the root files.
1815-
if (rootNames.length && !skipDefaultLib) {
1811+
if (rootNames.length && !options.noLib) {
18161812
// If '--lib' is not specified, include default library file according to '--target'
18171813
// otherwise, using options specified in '--lib' instead of '--target' default library file
18181814
const defaultLibraryFileName = getDefaultLibraryFileName();
18191815
if (!options.lib && defaultLibraryFileName) {
1820-
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false, { kind: FileIncludeKind.LibFile });
1816+
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile });
18211817
}
18221818
else {
18231819
forEach(options.lib, (libFileName, index) => {
1824-
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false, { kind: FileIncludeKind.LibFile, index });
1820+
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile, index });
18251821
});
18261822
}
18271823
}
@@ -2453,11 +2449,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
24532449
// 'lib' references has changed. Matches behavior in changesAffectModuleResolution
24542450
structureIsReused = StructureIsReused.SafeModules;
24552451
}
2456-
else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
2457-
// value of no-default-lib has changed
2458-
// this will affect if default library is injected into the list of files
2459-
structureIsReused = StructureIsReused.SafeModules;
2460-
}
24612452
// check tripleslash references
24622453
else if (!arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
24632454
// tripleslash references has changed
@@ -2687,7 +2678,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
26872678
return false;
26882679
}
26892680

2690-
if (file.hasNoDefaultLib) {
2681+
if (libFiles.has(file.path)) {
26912682
return true;
26922683
}
26932684

@@ -2703,7 +2694,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
27032694
}
27042695
else {
27052696
return some(options.lib, libFileName => {
2706-
// We might not have resolved lib if one of the root file included contained no-default-lib = true
27072697
const resolvedLib = resolvedLibReferences!.get(libFileName);
27082698
return !!resolvedLib && equalityComparer(file.fileName, resolvedLib.actual);
27092699
});
@@ -3317,8 +3307,8 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
33173307
return configFileParsingDiagnostics || emptyArray;
33183308
}
33193309

3320-
function processRootFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason) {
3321-
processSourceFile(normalizePath(fileName), isDefaultLib, ignoreNoDefaultLib, /*packageId*/ undefined, reason);
3310+
function processRootFile(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason) {
3311+
processSourceFile(normalizePath(fileName), isDefaultLib, /*packageId*/ undefined, reason);
33223312
}
33233313

33243314
function fileReferenceIsEqualTo(a: FileReference, b: FileReference): boolean {
@@ -3512,17 +3502,17 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35123502
}
35133503

35143504
/** This has side effects through `findSourceFile`. */
3515-
function processSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, packageId: PackageId | undefined, reason: FileIncludeReason): void {
3505+
function processSourceFile(fileName: string, isDefaultLib: boolean, packageId: PackageId | undefined, reason: FileIncludeReason): void {
35163506
getSourceFileFromReferenceWorker(
35173507
fileName,
3518-
fileName => findSourceFile(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId), // TODO: GH#18217
3508+
fileName => findSourceFile(fileName, isDefaultLib, reason, packageId), // TODO: GH#18217
35193509
(diagnostic, ...args) => addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, diagnostic, args),
35203510
reason,
35213511
);
35223512
}
35233513

35243514
function processProjectReferenceFile(fileName: string, reason: ProjectReferenceFile) {
3525-
return processSourceFile(fileName, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined, reason);
3515+
return processSourceFile(fileName, /*isDefaultLib*/ false, /*packageId*/ undefined, reason);
35263516
}
35273517

35283518
function reportFileNamesDifferOnlyInCasingError(fileName: string, existingFile: SourceFile, reason: FileIncludeReason): void {
@@ -3548,13 +3538,13 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35483538
}
35493539

35503540
// Get source file from normalized fileName
3551-
function findSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
3541+
function findSourceFile(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
35523542
tracing?.push(tracing.Phase.Program, "findSourceFile", {
35533543
fileName,
35543544
isDefaultLib: isDefaultLib || undefined,
35553545
fileIncludeKind: (FileIncludeKind as any)[reason.kind],
35563546
});
3557-
const result = findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId);
3547+
const result = findSourceFileWorker(fileName, isDefaultLib, reason, packageId);
35583548
tracing?.pop();
35593549
return result;
35603550
}
@@ -3571,7 +3561,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35713561
{ languageVersion, impliedNodeFormat: result, setExternalModuleIndicator, jsDocParsingMode: host.jsDocParsingMode };
35723562
}
35733563

3574-
function findSourceFileWorker(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
3564+
function findSourceFileWorker(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
35753565
const path = toPath(fileName);
35763566
if (useSourceOfProjectReferenceRedirect) {
35773567
let source = getRedirectFromOutput(path);
@@ -3590,7 +3580,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
35903580
if (realPath !== path) source = getRedirectFromOutput(realPath);
35913581
}
35923582
if (source?.source) {
3593-
const file = findSourceFile(source.source, isDefaultLib, ignoreNoDefaultLib, reason, packageId);
3583+
const file = findSourceFile(source.source, isDefaultLib, reason, packageId);
35943584
if (file) addFileToFilesByName(file, path, fileName, /*redirectedPath*/ undefined);
35953585
return file;
35963586
}
@@ -3712,8 +3702,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37123702
}
37133703
}
37143704

3715-
skipDefaultLib = skipDefaultLib || (file.hasNoDefaultLib && !ignoreNoDefaultLib);
3716-
37173705
if (!options.noResolve) {
37183706
processReferencedFiles(file, isDefaultLib);
37193707
processTypeReferenceDirectives(file);
@@ -3727,6 +3715,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37273715

37283716
if (isDefaultLib) {
37293717
processingDefaultLibFiles!.push(file);
3718+
libFiles.add(file.path);
37303719
}
37313720
else {
37323721
processingOtherFiles!.push(file);
@@ -3793,7 +3782,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
37933782
processSourceFile(
37943783
resolveTripleslashReference(ref.fileName, file.fileName),
37953784
isDefaultLib,
3796-
/*ignoreNoDefaultLib*/ false,
37973785
/*packageId*/ undefined,
37983786
{ kind: FileIncludeKind.ReferenceFile, file: file.path, index },
37993787
);
@@ -3846,7 +3834,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
38463834
if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth++;
38473835

38483836
// resolved from the primary path
3849-
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, reason); // TODO: GH#18217
3837+
processSourceFile(resolvedTypeReferenceDirective.resolvedFileName!, /*isDefaultLib*/ false, resolvedTypeReferenceDirective.packageId, reason); // TODO: GH#18217
38503838

38513839
if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth--;
38523840
}
@@ -3924,8 +3912,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
39243912
forEach(file.libReferenceDirectives, (libReference, index) => {
39253913
const libFileName = getLibFileNameFromLibReference(libReference);
39263914
if (libFileName) {
3927-
// we ignore any 'no-default-lib' reference set on this file.
3928-
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
3915+
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
39293916
}
39303917
else {
39313918
programDiagnostics.addFileProcessingDiagnostic({
@@ -3995,7 +3982,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
39953982
findSourceFile(
39963983
resolvedFileName,
39973984
/*isDefaultLib*/ false,
3998-
/*ignoreNoDefaultLib*/ false,
39993985
{ kind: FileIncludeKind.Import, file: file.path, index },
40003986
resolution.packageId,
40013987
);

0 commit comments

Comments
 (0)