@@ -51,6 +51,7 @@ namespace ts {
51
51
const emitResolver = createResolver();
52
52
53
53
const undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
54
+ undefinedSymbol.declarations = [];
54
55
const argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
55
56
56
57
const checker: TypeChecker = {
@@ -234,6 +235,10 @@ namespace ts {
234
235
ResolvedReturnType
235
236
}
236
237
238
+ const builtinGlobals: SymbolTable = {
239
+ [undefinedSymbol.name]: undefinedSymbol
240
+ };
241
+
237
242
initializeTypeChecker();
238
243
239
244
return checker;
@@ -360,6 +365,24 @@ namespace ts {
360
365
}
361
366
}
362
367
368
+ function addToSymbolTable(target: SymbolTable, source: SymbolTable, message: DiagnosticMessage) {
369
+ for (const id in source) {
370
+ if (hasProperty(source, id)) {
371
+ if (hasProperty(target, id)) {
372
+ // Error on redeclarations
373
+ forEach(target[id].declarations, addDeclarationDiagnostic(id, message));
374
+ }
375
+ else {
376
+ target[id] = source[id];
377
+ }
378
+ }
379
+ }
380
+
381
+ function addDeclarationDiagnostic(id: string, message: DiagnosticMessage) {
382
+ return (declaration: Declaration) => diagnostics.add(createDiagnosticForNode(declaration, message, id));
383
+ }
384
+ }
385
+
363
386
function getSymbolLinks(symbol: Symbol): SymbolLinks {
364
387
if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
365
388
const id = getSymbolId(symbol);
@@ -15327,10 +15350,12 @@ namespace ts {
15327
15350
}
15328
15351
});
15329
15352
15353
+ // Setup global builtins
15354
+ addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
15355
+
15330
15356
getSymbolLinks(undefinedSymbol).type = undefinedType;
15331
15357
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
15332
15358
getSymbolLinks(unknownSymbol).type = unknownType;
15333
- globals[undefinedSymbol.name] = undefinedSymbol;
15334
15359
15335
15360
// Initialize special types
15336
15361
globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1);
0 commit comments