break down tests, make more clear whats doing done, remove specific logic from mergeSymbolTable
This commit is contained in:
parent
63fef5083a
commit
00576527bd
|
@ -355,13 +355,6 @@ namespace ts {
|
|||
target[id] = source[id];
|
||||
}
|
||||
else {
|
||||
if (target === globals && source !== builtinGlobals) {
|
||||
if (hasProperty(builtinGlobals, id) && source[id].declarations && source[id].declarations.length) {
|
||||
// Error on builtin redeclarations
|
||||
forEach(source[id].declarations, addDeclarationDiagnostic.bind(undefined, id));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
let symbol = target[id];
|
||||
if (!(symbol.flags & SymbolFlags.Merged)) {
|
||||
target[id] = symbol = cloneSymbol(symbol);
|
||||
|
@ -370,9 +363,23 @@ namespace ts {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addDeclarationDiagnostic(id: string, declaration: Declaration) {
|
||||
diagnostics.add(createDiagnosticForNode(declaration, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0, id));
|
||||
function addToSymbolTable(target: SymbolTable, source: SymbolTable, message: DiagnosticMessage) {
|
||||
for (const id in source) {
|
||||
if (hasProperty(source, id)) {
|
||||
if (hasProperty(target, id)) {
|
||||
// Error on redeclarations
|
||||
forEach(target[id].declarations, addDeclarationDiagnostic(id, message));
|
||||
}
|
||||
else {
|
||||
target[id] = source[id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function addDeclarationDiagnostic(id: string, message: DiagnosticMessage) {
|
||||
return (declaration: Declaration) => diagnostics.add(createDiagnosticForNode(declaration, message, id));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15340,9 +15347,6 @@ namespace ts {
|
|||
bindSourceFile(file, compilerOptions);
|
||||
});
|
||||
|
||||
// Setup global builtins
|
||||
mergeSymbolTable(globals, builtinGlobals);
|
||||
|
||||
// Initialize global symbol table
|
||||
forEach(host.getSourceFiles(), file => {
|
||||
if (!isExternalOrCommonJsModule(file)) {
|
||||
|
@ -15350,6 +15354,9 @@ namespace ts {
|
|||
}
|
||||
});
|
||||
|
||||
// Setup global builtins
|
||||
addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0);
|
||||
|
||||
getSymbolLinks(undefinedSymbol).type = undefinedType;
|
||||
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments");
|
||||
getSymbolLinks(unknownSymbol).type = unknownType;
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
// @filename: a.ts
|
||||
type undefined = string;
|
||||
var undefined = void 0;
|
||||
var undefined = null;
|
||||
function p(undefined = 42) {
|
||||
return undefined;
|
||||
}
|
||||
// @filename: b.ts
|
||||
class undefined {
|
||||
foo: string;
|
||||
}
|
||||
interface undefined {
|
||||
member: number;
|
||||
}
|
||||
namespace undefined {
|
||||
export var x = 42;
|
||||
}
|
||||
var x: undefined;
|
||||
var x: typeof undefined;
|
4
tests/cases/compiler/undefinedTypeAssignment1.ts
Normal file
4
tests/cases/compiler/undefinedTypeAssignment1.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
type undefined = string;
|
||||
function p(undefined = "wat") {
|
||||
return undefined;
|
||||
}
|
1
tests/cases/compiler/undefinedTypeAssignment2.ts
Normal file
1
tests/cases/compiler/undefinedTypeAssignment2.ts
Normal file
|
@ -0,0 +1 @@
|
|||
var undefined = void 0;
|
1
tests/cases/compiler/undefinedTypeAssignment3.ts
Normal file
1
tests/cases/compiler/undefinedTypeAssignment3.ts
Normal file
|
@ -0,0 +1 @@
|
|||
var undefined = null;
|
11
tests/cases/compiler/undefinedTypeAssignment4.ts
Normal file
11
tests/cases/compiler/undefinedTypeAssignment4.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
class undefined {
|
||||
foo: string;
|
||||
}
|
||||
interface undefined {
|
||||
member: number;
|
||||
}
|
||||
namespace undefined {
|
||||
export var x = 42;
|
||||
}
|
||||
var x: undefined;
|
||||
var y: typeof undefined;
|
Loading…
Reference in a new issue