@@ -51,6 +51,7 @@ namespace ts {
5151 const emitResolver = createResolver();
5252
5353 const undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
54+ undefinedSymbol.declarations = [];
5455 const argumentsSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "arguments");
5556
5657 const checker: TypeChecker = {
@@ -234,6 +235,10 @@ namespace ts {
234235 ResolvedReturnType
235236 }
236237
238+ const builtinGlobals: SymbolTable = {
239+ [undefinedSymbol.name]: undefinedSymbol
240+ };
241+
237242 initializeTypeChecker();
238243
239244 return checker;
@@ -360,6 +365,24 @@ namespace ts {
360365 }
361366 }
362367
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+
363386 function getSymbolLinks(symbol: Symbol): SymbolLinks {
364387 if (symbol.flags & SymbolFlags.Transient) return <TransientSymbol>symbol;
365388 const id = getSymbolId(symbol);
@@ -15327,10 +15350,12 @@ namespace ts {
1532715350 }
1532815351 });
1532915352
15353+ // Setup global builtins
15354+ addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
15355+
1533015356 getSymbolLinks(undefinedSymbol).type = undefinedType;
1533115357 getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
1533215358 getSymbolLinks(unknownSymbol).type = unknownType;
15333- globals[undefinedSymbol.name] = undefinedSymbol;
1533415359
1533515360 // Initialize special types
1533615361 globalArrayType = <GenericType>getGlobalType("Array", /*arity*/ 1);
0 commit comments