Merge pull request #5193 from Microsoft/namespace-before-ambient-derived-class-finds-heritage

Namespace before ambient derived class finds heritage
This commit is contained in:
Nathan Shively-Sanders
2015-11-13 08:50:10 -08:00
6 changed files with 162 additions and 11 deletions
+8 -3
View File
@@ -175,9 +175,14 @@ namespace ts {
symbol.members = {};
}
if (symbolFlags & SymbolFlags.Value && !symbol.valueDeclaration) {
symbol.valueDeclaration = node;
}
if (symbolFlags & SymbolFlags.Value) {
const valueDeclaration = symbol.valueDeclaration;
if (!valueDeclaration ||
(valueDeclaration.kind !== node.kind && valueDeclaration.kind === SyntaxKind.ModuleDeclaration)) {
// other kinds of value declarations take precedence over modules
symbol.valueDeclaration = node;
}
}
}
// Should not be called on a declaration with a computed property name,
+6 -1
View File
@@ -295,7 +295,12 @@ namespace ts {
target.constEnumOnlyModule = false;
}
target.flags |= source.flags;
if (!target.valueDeclaration && source.valueDeclaration) target.valueDeclaration = source.valueDeclaration;
if (source.valueDeclaration &&
(!target.valueDeclaration ||
(target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) {
// other kinds of value declarations take precedence over modules
target.valueDeclaration = source.valueDeclaration;
}
forEach(source.declarations, node => {
target.declarations.push(node);
});
@@ -1,6 +1,40 @@
//// [ambientClassDeclarationWithExtends.ts]
//// [tests/cases/compiler/ambientClassDeclarationWithExtends.ts] ////
//// [ambientClassDeclarationExtends_singleFile.ts]
declare class A { }
declare class B extends A { }
declare class C {
public foo;
}
namespace D { var x; }
declare class D extends C { }
var d: C = new D();
//// [ambientClassDeclarationExtends_file1.ts]
declare class E {
public bar;
}
namespace F { var y; }
//// [ambientClassDeclarationExtends_file2.ts]
declare class F extends E { }
var f: E = new F();
//// [ambientClassDeclarationWithExtends.js]
//// [ambientClassDeclarationExtends_singleFile.js]
var D;
(function (D) {
var x;
})(D || (D = {}));
var d = new D();
//// [ambientClassDeclarationExtends_file1.js]
var F;
(function (F) {
var y;
})(F || (F = {}));
//// [ambientClassDeclarationExtends_file2.js]
var f = new F();
@@ -1,8 +1,50 @@
=== tests/cases/compiler/ambientClassDeclarationWithExtends.ts ===
=== tests/cases/compiler/ambientClassDeclarationExtends_singleFile.ts ===
declare class A { }
>A : Symbol(A, Decl(ambientClassDeclarationWithExtends.ts, 0, 0))
>A : Symbol(A, Decl(ambientClassDeclarationExtends_singleFile.ts, 0, 0))
declare class B extends A { }
>B : Symbol(B, Decl(ambientClassDeclarationWithExtends.ts, 0, 19))
>A : Symbol(A, Decl(ambientClassDeclarationWithExtends.ts, 0, 0))
>B : Symbol(B, Decl(ambientClassDeclarationExtends_singleFile.ts, 0, 19))
>A : Symbol(A, Decl(ambientClassDeclarationExtends_singleFile.ts, 0, 0))
declare class C {
>C : Symbol(C, Decl(ambientClassDeclarationExtends_singleFile.ts, 1, 29))
public foo;
>foo : Symbol(foo, Decl(ambientClassDeclarationExtends_singleFile.ts, 3, 17))
}
namespace D { var x; }
>D : Symbol(D, Decl(ambientClassDeclarationExtends_singleFile.ts, 5, 1), Decl(ambientClassDeclarationExtends_singleFile.ts, 6, 22))
>x : Symbol(x, Decl(ambientClassDeclarationExtends_singleFile.ts, 6, 17))
declare class D extends C { }
>D : Symbol(D, Decl(ambientClassDeclarationExtends_singleFile.ts, 5, 1), Decl(ambientClassDeclarationExtends_singleFile.ts, 6, 22))
>C : Symbol(C, Decl(ambientClassDeclarationExtends_singleFile.ts, 1, 29))
var d: C = new D();
>d : Symbol(d, Decl(ambientClassDeclarationExtends_singleFile.ts, 9, 3))
>C : Symbol(C, Decl(ambientClassDeclarationExtends_singleFile.ts, 1, 29))
>D : Symbol(D, Decl(ambientClassDeclarationExtends_singleFile.ts, 5, 1), Decl(ambientClassDeclarationExtends_singleFile.ts, 6, 22))
=== tests/cases/compiler/ambientClassDeclarationExtends_file1.ts ===
declare class E {
>E : Symbol(E, Decl(ambientClassDeclarationExtends_file1.ts, 0, 0))
public bar;
>bar : Symbol(bar, Decl(ambientClassDeclarationExtends_file1.ts, 1, 17))
}
namespace F { var y; }
>F : Symbol(F, Decl(ambientClassDeclarationExtends_file1.ts, 3, 1), Decl(ambientClassDeclarationExtends_file2.ts, 0, 0))
>y : Symbol(y, Decl(ambientClassDeclarationExtends_file1.ts, 4, 17))
=== tests/cases/compiler/ambientClassDeclarationExtends_file2.ts ===
declare class F extends E { }
>F : Symbol(F, Decl(ambientClassDeclarationExtends_file1.ts, 3, 1), Decl(ambientClassDeclarationExtends_file2.ts, 0, 0))
>E : Symbol(E, Decl(ambientClassDeclarationExtends_file1.ts, 0, 0))
var f: E = new F();
>f : Symbol(f, Decl(ambientClassDeclarationExtends_file2.ts, 2, 3))
>E : Symbol(E, Decl(ambientClassDeclarationExtends_file1.ts, 0, 0))
>F : Symbol(F, Decl(ambientClassDeclarationExtends_file1.ts, 3, 1), Decl(ambientClassDeclarationExtends_file2.ts, 0, 0))
@@ -1,4 +1,4 @@
=== tests/cases/compiler/ambientClassDeclarationWithExtends.ts ===
=== tests/cases/compiler/ambientClassDeclarationExtends_singleFile.ts ===
declare class A { }
>A : A
@@ -6,3 +6,47 @@ declare class B extends A { }
>B : B
>A : A
declare class C {
>C : C
public foo;
>foo : any
}
namespace D { var x; }
>D : typeof D
>x : any
declare class D extends C { }
>D : D
>C : C
var d: C = new D();
>d : C
>C : C
>new D() : D
>D : typeof D
=== tests/cases/compiler/ambientClassDeclarationExtends_file1.ts ===
declare class E {
>E : E
public bar;
>bar : any
}
namespace F { var y; }
>F : typeof F
>y : any
=== tests/cases/compiler/ambientClassDeclarationExtends_file2.ts ===
declare class F extends E { }
>F : F
>E : E
var f: E = new F();
>f : E
>E : E
>new F() : F
>F : typeof F
@@ -1,2 +1,23 @@
// @Filename: ambientClassDeclarationExtends_singleFile.ts
declare class A { }
declare class B extends A { }
declare class C {
public foo;
}
namespace D { var x; }
declare class D extends C { }
var d: C = new D();
// @Filename: ambientClassDeclarationExtends_file1.ts
declare class E {
public bar;
}
namespace F { var y; }
// @Filename: ambientClassDeclarationExtends_file2.ts
declare class F extends E { }
var f: E = new F();