@@ -355,13 +355,6 @@ namespace ts {
355355 target[id] = source[id];
356356 }
357357 else {
358- if (target === globals && source !== builtinGlobals) {
359- if (hasProperty(builtinGlobals, id) && source[id].declarations && source[id].declarations.length) {
360- // Error on builtin redeclarations
361- forEach(source[id].declarations, addDeclarationDiagnostic.bind(undefined, id));
362- continue;
363- }
364- }
365358 let symbol = target[id];
366359 if (!(symbol.flags & SymbolFlags.Merged)) {
367360 target[id] = symbol = cloneSymbol(symbol);
@@ -370,9 +363,23 @@ namespace ts {
370363 }
371364 }
372365 }
366+ }
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+ }
373380
374- function addDeclarationDiagnostic(id: string, declaration: Declaration ) {
375- diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0 , id));
381+ function addDeclarationDiagnostic(id: string, message: DiagnosticMessage ) {
382+ return (declaration: Declaration) => diagnostics.add(createDiagnosticForNode(declaration, message , id));
376383 }
377384 }
378385
@@ -15340,16 +15347,16 @@ namespace ts {
1534015347 bindSourceFile(file, compilerOptions);
1534115348 });
1534215349
15343- // Setup global builtins
15344- mergeSymbolTable(globals, builtinGlobals);
15345-
1534615350 // Initialize global symbol table
1534715351 forEach(host.getSourceFiles(), file => {
1534815352 if (!isExternalOrCommonJsModule(file)) {
1534915353 mergeSymbolTable(globals, file.locals);
1535015354 }
1535115355 });
1535215356
15357+ // Setup global builtins
15358+ addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
15359+
1535315360 getSymbolLinks(undefinedSymbol).type = undefinedType;
1535415361 getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
1535515362 getSymbolLinks(unknownSymbol).type = unknownType;
0 commit comments