Skip to content

Commit 0057652

Browse files
committed
break down tests, make more clear whats doing done, remove specific logic from mergeSymbolTable
1 parent 63fef50 commit 0057652

File tree

6 files changed

+36
-31
lines changed

6 files changed

+36
-31
lines changed

src/compiler/checker.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

tests/cases/compiler/undefinedTypeAssignment.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type undefined = string;
2+
function p(undefined = "wat") {
3+
return undefined;
4+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var undefined = void 0;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
var undefined = null;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class undefined {
2+
foo: string;
3+
}
4+
interface undefined {
5+
member: number;
6+
}
7+
namespace undefined {
8+
export var x = 42;
9+
}
10+
var x: undefined;
11+
var y: typeof undefined;

0 commit comments

Comments
 (0)