@@ -2255,9 +2255,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
2255
2255
var identityRelation = new Map<string, RelationComparisonResult>();
2256
2256
var enumRelation = new Map<string, RelationComparisonResult>();
2257
2257
2258
- var builtinGlobals = createSymbolTable();
2259
- builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol);
2260
-
2261
2258
// Extensions suggested for path imports when module resolution is node16 or higher.
2262
2259
// The first element of each tuple is the extension a file has.
2263
2260
// 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 {
2720
2717
}
2721
2718
}
2722
2719
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)));
2739
2728
}
2740
- };
2729
+ });
2730
+ }
2731
+ else {
2732
+ globals.set(name, undefinedSymbol);
2741
2733
}
2742
2734
}
2743
2735
@@ -48754,7 +48746,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
48754
48746
}
48755
48747
if (!isExternalOrCommonJsModule(file)) {
48756
48748
// 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.
48758
48749
const fileGlobalThisSymbol = file.locals!.get("globalThis" as __String);
48759
48750
if (fileGlobalThisSymbol?.declarations) {
48760
48751
for (const declaration of fileGlobalThisSymbol.declarations) {
@@ -48800,8 +48791,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
48800
48791
}
48801
48792
}
48802
48793
48803
- // Setup global builtins
48804
- addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
48794
+ addUndefinedToGlobalsOrErrorOnRedeclaration();
48805
48795
48806
48796
getSymbolLinks(undefinedSymbol).type = undefinedWideningType;
48807
48797
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments" as __String, /*arity*/ 0, /*reportErrors*/ true);
0 commit comments