Skip to content

Commit 7b80d7a

Browse files
committed
Eliminate builtinGlobals
1 parent 886a41e commit 7b80d7a

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

src/compiler/checker.ts

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,9 +2255,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
22552255
var identityRelation = new Map<string, RelationComparisonResult>();
22562256
var enumRelation = new Map<string, RelationComparisonResult>();
22572257

2258-
var builtinGlobals = createSymbolTable();
2259-
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);
2260-
22612258
// Extensions suggested for path imports when module resolution is node16 or higher.
22622259
// The first element of each tuple is the extension a file has.
22632260
// The second element of each tuple is the extension that should be used in a path import.
@@ -2720,24 +2717,19 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
27202717
}
27212718
}
27222719

2723-
function addToSymbolTable(target: SymbolTable, source: SymbolTable, message: DiagnosticMessage) {
2724-
source.forEach((sourceSymbol, id) => {
2725-
const targetSymbol = target.get(id);
2726-
if (targetSymbol) {
2727-
// Error on redeclarations
2728-
forEach(targetSymbol.declarations, addDeclarationDiagnostic(unescapeLeadingUnderscores(id), message));
2729-
}
2730-
else {
2731-
target.set(id, sourceSymbol);
2732-
}
2733-
});
2734-
2735-
function addDeclarationDiagnostic(id: string, message: DiagnosticMessage) {
2736-
return (declaration: Declaration) => {
2737-
if (!isTypeDeclaration(declaration) && declaration.kind !== SyntaxKind.ClassDeclaration) {
2738-
diagnostics.add(createDiagnosticForNode(declaration, message, id));
2720+
function addUndefinedToGlobalsOrErrorOnRedeclaration() {
2721+
const name = undefinedSymbol.escapedName;
2722+
const targetSymbol = globals.get(name);
2723+
if (targetSymbol) {
2724+
forEach(targetSymbol.declarations, declaration => {
2725+
// checkTypeNameIsReserved will have added better diagnostics for undefined.
2726+
if (!isTypeDeclaration(declaration)) {
2727+
diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, unescapeLeadingUnderscores(name)));
27392728
}
2740-
};
2729+
});
2730+
}
2731+
else {
2732+
globals.set(name, undefinedSymbol);
27412733
}
27422734
}
27432735

@@ -48754,7 +48746,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4875448746
}
4875548747
if (!isExternalOrCommonJsModule(file)) {
4875648748
// It is an error for a non-external-module (i.e. script) to declare its own `globalThis`.
48757-
// We can't use `builtinGlobals` for this due to synthetic expando-namespace generation in JS files.
4875848749
const fileGlobalThisSymbol = file.locals!.get("globalThis" as __String);
4875948750
if (fileGlobalThisSymbol?.declarations) {
4876048751
for (const declaration of fileGlobalThisSymbol.declarations) {
@@ -48800,8 +48791,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4880048791
}
4880148792
}
4880248793

48803-
// Setup global builtins
48804-
addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
48794+
addUndefinedToGlobalsOrErrorOnRedeclaration();
4880548795

4880648796
getSymbolLinks(undefinedSymbol).type = undefinedWideningType;
4880748797
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments" as __String, /*arity*/ 0, /*reportErrors*/ true);

0 commit comments

Comments
 (0)