Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const libs = memoize(() => {
/** @type {{ libs: string[]; paths: Record<string, string | undefined>; }} */
const libraries = readJson("./src/lib/libs.json");
const libs = libraries.libs.map(lib => {
const relativeSources = ["header.d.ts", lib + ".d.ts"];
const relativeSources = [lib + ".d.ts"];
const relativeTarget = libraries.paths && libraries.paths[lib] || ("lib." + lib + ".d.ts");
const sources = relativeSources.map(s => path.posix.join("src/lib", s));
const target = `built/local/${relativeTarget}`;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function createBuilderProgramState(

if (canCopySemanticDiagnostics) {
if (sourceFile.isDeclarationFile && !copyDeclarationFileDiagnostics) return;
if (sourceFile.hasNoDefaultLib && !copyLibFileDiagnostics) return;
if (newProgram.isSourceFileDefaultLibrary(sourceFile) && !copyLibFileDiagnostics) return;

// Unchanged file copy diagnostics
const diagnostics = oldState!.semanticDiagnosticsPerFile.get(sourceFilePath);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21504,15 +21504,15 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
let issuedElaboration = false;
if (!targetProp) {
const indexInfo = getApplicableIndexInfo(target, nameType);
if (indexInfo && indexInfo.declaration && !getSourceFileOfNode(indexInfo.declaration).hasNoDefaultLib) {
if (indexInfo && indexInfo.declaration && !host.isSourceFileDefaultLibrary(getSourceFileOfNode(indexInfo.declaration))) {
issuedElaboration = true;
addRelatedInfo(reportedDiag, createDiagnosticForNode(indexInfo.declaration, Diagnostics.The_expected_type_comes_from_this_index_signature));
}
}

if (!issuedElaboration && (targetProp && length(targetProp.declarations) || target.symbol && length(target.symbol.declarations))) {
const targetNode = targetProp && length(targetProp.declarations) ? targetProp.declarations![0] : target.symbol.declarations![0];
if (!getSourceFileOfNode(targetNode).hasNoDefaultLib) {
if (!host.isSourceFileDefaultLibrary(getSourceFileOfNode(targetNode))) {
addRelatedInfo(
reportedDiag,
createDiagnosticForNode(
Expand Down
10 changes: 3 additions & 7 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4286,18 +4286,14 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
}

function emitSyntheticTripleSlashReferencesIfNeeded(node: Bundle) {
emitTripleSlashDirectives(!!node.hasNoDefaultLib, node.syntheticFileReferences || [], node.syntheticTypeReferences || [], node.syntheticLibReferences || []);
emitTripleSlashDirectives(node.syntheticFileReferences || [], node.syntheticTypeReferences || [], node.syntheticLibReferences || []);
}

function emitTripleSlashDirectivesIfNeeded(node: SourceFile) {
if (node.isDeclarationFile) emitTripleSlashDirectives(node.hasNoDefaultLib, node.referencedFiles, node.typeReferenceDirectives, node.libReferenceDirectives);
if (node.isDeclarationFile) emitTripleSlashDirectives(node.referencedFiles, node.typeReferenceDirectives, node.libReferenceDirectives);
}

function emitTripleSlashDirectives(hasNoDefaultLib: boolean, files: readonly FileReference[], types: readonly FileReference[], libs: readonly FileReference[]) {
if (hasNoDefaultLib) {
writeComment(`/// <reference no-default-lib="true"/>`);
writeLine();
}
function emitTripleSlashDirectives(files: readonly FileReference[], types: readonly FileReference[], libs: readonly FileReference[]) {
if (currentSourceFile && currentSourceFile.moduleName) {
writeComment(`/// <amd-module name="${currentSourceFile.moduleName}" />`);
writeLine();
Expand Down
6 changes: 2 additions & 4 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6181,16 +6181,15 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
isDeclarationFile = node.isDeclarationFile,
referencedFiles = node.referencedFiles,
typeReferenceDirectives = node.typeReferenceDirectives,
hasNoDefaultLib = node.hasNoDefaultLib,
_hasNoDefaultLib = false,
libReferenceDirectives = node.libReferenceDirectives,
) {
return node.statements !== statements
|| node.isDeclarationFile !== isDeclarationFile
|| node.referencedFiles !== referencedFiles
|| node.typeReferenceDirectives !== typeReferenceDirectives
|| node.hasNoDefaultLib !== hasNoDefaultLib
|| node.libReferenceDirectives !== libReferenceDirectives
? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, hasNoDefaultLib, libReferenceDirectives), node)
? update(cloneSourceFileWithChanges(node, statements, isDeclarationFile, referencedFiles, typeReferenceDirectives, /*hasNoDefaultLib*/ false, libReferenceDirectives), node)
: node;
}

Expand All @@ -6201,7 +6200,6 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
node.syntheticFileReferences = undefined;
node.syntheticTypeReferences = undefined;
node.syntheticLibReferences = undefined;
node.hasNoDefaultLib = undefined;
return node;
}

Expand Down
3 changes: 1 addition & 2 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10617,7 +10617,6 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
context.typeReferenceDirectives = [];
context.libReferenceDirectives = [];
context.amdDependencies = [];
context.hasNoDefaultLib = false;
context.pragmas!.forEach((entryOrList, key) => { // TODO: GH#18217
// TODO: The below should be strongly type-guarded and not need casts/explicit annotations, since entryOrList is related to
// key and key is constrained to a union; but it's not (see GH#21483 for at least partial fix) :(
Expand All @@ -10630,7 +10629,7 @@ export function processPragmasIntoFields(context: PragmaContext, reportDiagnosti
const { types, lib, path, ["resolution-mode"]: res, preserve: _preserve } = arg.arguments;
const preserve = _preserve === "true" ? true : undefined;
if (arg.arguments["no-default-lib"] === "true") {
context.hasNoDefaultLib = true;
// This has been removed; parse but ignore it.
}
else if (types) {
const parsed = parseResolutionMode(res, types.pos, types.end, reportDiagnostic);
Expand Down
50 changes: 18 additions & 32 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1577,7 +1577,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
const host = createProgramOptionsHost || createCompilerHost(options);
const configParsingHost = parseConfigHostFromCompilerHostLike(host);

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

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

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

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

// Do not process the default library if:
// - The '--noLib' flag is used.
// - A 'no-default-lib' reference comment is encountered in
// processing the root files.
if (rootNames.length && !skipDefaultLib) {
if (rootNames.length && !options.noLib) {
// If '--lib' is not specified, include default library file according to '--target'
// otherwise, using options specified in '--lib' instead of '--target' default library file
const defaultLibraryFileName = getDefaultLibraryFileName();
if (!options.lib && defaultLibraryFileName) {
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false, { kind: FileIncludeKind.LibFile });
processRootFile(defaultLibraryFileName, /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile });
}
else {
forEach(options.lib, (libFileName, index) => {
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ false, { kind: FileIncludeKind.LibFile, index });
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibFile, index });
});
}
}
Expand Down Expand Up @@ -2453,11 +2449,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
// 'lib' references has changed. Matches behavior in changesAffectModuleResolution
structureIsReused = StructureIsReused.SafeModules;
}
else if (oldSourceFile.hasNoDefaultLib !== newSourceFile.hasNoDefaultLib) {
// value of no-default-lib has changed
// this will affect if default library is injected into the list of files
structureIsReused = StructureIsReused.SafeModules;
}
// check tripleslash references
else if (!arrayIsEqualTo(oldSourceFile.referencedFiles, newSourceFile.referencedFiles, fileReferenceIsEqualTo)) {
// tripleslash references has changed
Expand Down Expand Up @@ -2687,7 +2678,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
return false;
}

if (file.hasNoDefaultLib) {
if (libFiles.has(file.path)) {
return true;
}

Expand All @@ -2703,7 +2694,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
}
else {
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);
});
Expand Down Expand Up @@ -3317,8 +3307,8 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
return configFileParsingDiagnostics || emptyArray;
}

function processRootFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason) {
processSourceFile(normalizePath(fileName), isDefaultLib, ignoreNoDefaultLib, /*packageId*/ undefined, reason);
function processRootFile(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason) {
processSourceFile(normalizePath(fileName), isDefaultLib, /*packageId*/ undefined, reason);
}

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

/** This has side effects through `findSourceFile`. */
function processSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, packageId: PackageId | undefined, reason: FileIncludeReason): void {
function processSourceFile(fileName: string, isDefaultLib: boolean, packageId: PackageId | undefined, reason: FileIncludeReason): void {
getSourceFileFromReferenceWorker(
fileName,
fileName => findSourceFile(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId), // TODO: GH#18217
fileName => findSourceFile(fileName, isDefaultLib, reason, packageId), // TODO: GH#18217
(diagnostic, ...args) => addFilePreprocessingFileExplainingDiagnostic(/*file*/ undefined, reason, diagnostic, args),
reason,
);
}

function processProjectReferenceFile(fileName: string, reason: ProjectReferenceFile) {
return processSourceFile(fileName, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false, /*packageId*/ undefined, reason);
return processSourceFile(fileName, /*isDefaultLib*/ false, /*packageId*/ undefined, reason);
}

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

// Get source file from normalized fileName
function findSourceFile(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
function findSourceFile(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
tracing?.push(tracing.Phase.Program, "findSourceFile", {
fileName,
isDefaultLib: isDefaultLib || undefined,
fileIncludeKind: (FileIncludeKind as any)[reason.kind],
});
const result = findSourceFileWorker(fileName, isDefaultLib, ignoreNoDefaultLib, reason, packageId);
const result = findSourceFileWorker(fileName, isDefaultLib, reason, packageId);
tracing?.pop();
return result;
}
Expand All @@ -3571,7 +3561,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
{ languageVersion, impliedNodeFormat: result, setExternalModuleIndicator, jsDocParsingMode: host.jsDocParsingMode };
}

function findSourceFileWorker(fileName: string, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
function findSourceFileWorker(fileName: string, isDefaultLib: boolean, reason: FileIncludeReason, packageId: PackageId | undefined): SourceFile | undefined {
const path = toPath(fileName);
if (useSourceOfProjectReferenceRedirect) {
let source = getRedirectFromOutput(path);
Expand All @@ -3590,7 +3580,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
if (realPath !== path) source = getRedirectFromOutput(realPath);
}
if (source?.source) {
const file = findSourceFile(source.source, isDefaultLib, ignoreNoDefaultLib, reason, packageId);
const file = findSourceFile(source.source, isDefaultLib, reason, packageId);
if (file) addFileToFilesByName(file, path, fileName, /*redirectedPath*/ undefined);
return file;
}
Expand Down Expand Up @@ -3712,8 +3702,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
}
}

skipDefaultLib = skipDefaultLib || (file.hasNoDefaultLib && !ignoreNoDefaultLib);

if (!options.noResolve) {
processReferencedFiles(file, isDefaultLib);
processTypeReferenceDirectives(file);
Expand Down Expand Up @@ -3793,7 +3781,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
processSourceFile(
resolveTripleslashReference(ref.fileName, file.fileName),
isDefaultLib,
/*ignoreNoDefaultLib*/ false,
/*packageId*/ undefined,
{ kind: FileIncludeKind.ReferenceFile, file: file.path, index },
);
Expand Down Expand Up @@ -3846,7 +3833,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth++;

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

if (resolvedTypeReferenceDirective.isExternalLibraryImport) currentNodeModulesDepth--;
}
Expand All @@ -3860,6 +3847,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
if (existing) return existing.actual;
const result = pathForLibFileWorker(libFileName);
(resolvedLibReferences ??= new Map()).set(libFileName, result);
libFiles.add(toPath(result.actual));
return result.actual;
}

Expand Down Expand Up @@ -3924,8 +3912,7 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
forEach(file.libReferenceDirectives, (libReference, index) => {
const libFileName = getLibFileNameFromLibReference(libReference);
if (libFileName) {
// we ignore any 'no-default-lib' reference set on this file.
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, /*ignoreNoDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
processRootFile(pathForLibFile(libFileName), /*isDefaultLib*/ true, { kind: FileIncludeKind.LibReferenceDirective, file: file.path, index });
}
else {
programDiagnostics.addFileProcessingDiagnostic({
Expand Down Expand Up @@ -3995,7 +3982,6 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
findSourceFile(
resolvedFileName,
/*isDefaultLib*/ false,
/*ignoreNoDefaultLib*/ false,
{ kind: FileIncludeKind.Import, file: file.path, index },
resolution.packageId,
);
Expand Down
Loading
Loading