diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 09672f5c09c..ad23e11fb27 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1444,12 +1444,6 @@ namespace ts { return result; } break; - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: - if (result = callback(getSymbolOfNode(location).members)) { - return result; - } - break; } } @@ -1515,7 +1509,9 @@ namespace ts { } if (symbol) { - return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable); + if (!(isPropertyOrMethodDeclarationSymbol(symbol))) { + return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable); + } } } @@ -1548,6 +1544,24 @@ namespace ts { return qualify; } + function isPropertyOrMethodDeclarationSymbol(symbol: Symbol) { + if (symbol.declarations && symbol.declarations.length) { + for (const declaration of symbol.declarations) { + switch (declaration.kind) { + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + continue; + default: + return false; + } + } + return true; + } + return false; + } + function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult { if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) { const initialSymbol = symbol; diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict.js b/tests/baselines/reference/declarationEmit_classMemberNameConflict.js new file mode 100644 index 00000000000..55acb13d2b9 --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict.js @@ -0,0 +1,112 @@ +//// [declarationEmit_classMemberNameConflict.ts] + +export class C1 { + C1() { } // has to be the same as the class name + + bar() { + return function (t: typeof C1) { + }; + } +} + +export class C2 { + C2: any // has to be the same as the class name + + bar() { + return function (t: typeof C2) { + }; + } +} + +export class C3 { + get C3() { return 0; } // has to be the same as the class name + + bar() { + return function (t: typeof C3) { + }; + } +} + +export class C4 { + set C4(v) { } // has to be the same as the class name + + bar() { + return function (t: typeof C4) { + }; + } +} + +//// [declarationEmit_classMemberNameConflict.js] +"use strict"; +var C1 = (function () { + function C1() { + } + C1.prototype.C1 = function () { }; // has to be the same as the class name + C1.prototype.bar = function () { + return function (t) { + }; + }; + return C1; +}()); +exports.C1 = C1; +var C2 = (function () { + function C2() { + } + C2.prototype.bar = function () { + return function (t) { + }; + }; + return C2; +}()); +exports.C2 = C2; +var C3 = (function () { + function C3() { + } + Object.defineProperty(C3.prototype, "C3", { + get: function () { return 0; } // has to be the same as the class name + , + enumerable: true, + configurable: true + }); + C3.prototype.bar = function () { + return function (t) { + }; + }; + return C3; +}()); +exports.C3 = C3; +var C4 = (function () { + function C4() { + } + Object.defineProperty(C4.prototype, "C4", { + set: function (v) { } // has to be the same as the class name + , + enumerable: true, + configurable: true + }); + C4.prototype.bar = function () { + return function (t) { + }; + }; + return C4; +}()); +exports.C4 = C4; + + +//// [declarationEmit_classMemberNameConflict.d.ts] +export declare class C1 { + C1(): void; + bar(): (t: typeof C1) => void; +} +export declare class C2 { + C2: any; + bar(): (t: typeof C2) => void; +} +export declare class C3 { + readonly C3: number; + bar(): (t: typeof C3) => void; +} +export declare class C4 { + C4: any; + bar(): (t: typeof C4) => void; +} diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict.symbols b/tests/baselines/reference/declarationEmit_classMemberNameConflict.symbols new file mode 100644 index 00000000000..2b8959289a8 --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict.symbols @@ -0,0 +1,70 @@ +=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts === + +export class C1 { +>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0)) + + C1() { } // has to be the same as the class name +>C1 : Symbol(C1.C1, Decl(declarationEmit_classMemberNameConflict.ts, 1, 17)) + + bar() { +>bar : Symbol(C1.bar, Decl(declarationEmit_classMemberNameConflict.ts, 2, 12)) + + return function (t: typeof C1) { +>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 5, 25)) +>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0)) + + }; + } +} + +export class C2 { +>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1)) + + C2: any // has to be the same as the class name +>C2 : Symbol(C2.C2, Decl(declarationEmit_classMemberNameConflict.ts, 10, 17)) + + bar() { +>bar : Symbol(C2.bar, Decl(declarationEmit_classMemberNameConflict.ts, 11, 11)) + + return function (t: typeof C2) { +>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 14, 25)) +>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1)) + + }; + } +} + +export class C3 { +>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1)) + + get C3() { return 0; } // has to be the same as the class name +>C3 : Symbol(C3.C3, Decl(declarationEmit_classMemberNameConflict.ts, 19, 17)) + + bar() { +>bar : Symbol(C3.bar, Decl(declarationEmit_classMemberNameConflict.ts, 20, 26)) + + return function (t: typeof C3) { +>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 23, 25)) +>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1)) + + }; + } +} + +export class C4 { +>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1)) + + set C4(v) { } // has to be the same as the class name +>C4 : Symbol(C4.C4, Decl(declarationEmit_classMemberNameConflict.ts, 28, 17)) +>v : Symbol(v, Decl(declarationEmit_classMemberNameConflict.ts, 29, 11)) + + bar() { +>bar : Symbol(C4.bar, Decl(declarationEmit_classMemberNameConflict.ts, 29, 17)) + + return function (t: typeof C4) { +>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 32, 25)) +>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1)) + + }; + } +} diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict.types b/tests/baselines/reference/declarationEmit_classMemberNameConflict.types new file mode 100644 index 00000000000..c76072413e5 --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict.types @@ -0,0 +1,75 @@ +=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts === + +export class C1 { +>C1 : C1 + + C1() { } // has to be the same as the class name +>C1 : () => void + + bar() { +>bar : () => (t: typeof C1) => void + + return function (t: typeof C1) { +>function (t: typeof C1) { } : (t: typeof C1) => void +>t : typeof C1 +>C1 : typeof C1 + + }; + } +} + +export class C2 { +>C2 : C2 + + C2: any // has to be the same as the class name +>C2 : any + + bar() { +>bar : () => (t: typeof C2) => void + + return function (t: typeof C2) { +>function (t: typeof C2) { } : (t: typeof C2) => void +>t : typeof C2 +>C2 : typeof C2 + + }; + } +} + +export class C3 { +>C3 : C3 + + get C3() { return 0; } // has to be the same as the class name +>C3 : number +>0 : number + + bar() { +>bar : () => (t: typeof C3) => void + + return function (t: typeof C3) { +>function (t: typeof C3) { } : (t: typeof C3) => void +>t : typeof C3 +>C3 : typeof C3 + + }; + } +} + +export class C4 { +>C4 : C4 + + set C4(v) { } // has to be the same as the class name +>C4 : any +>v : any + + bar() { +>bar : () => (t: typeof C4) => void + + return function (t: typeof C4) { +>function (t: typeof C4) { } : (t: typeof C4) => void +>t : typeof C4 +>C4 : typeof C4 + + }; + } +} diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict2.js b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.js new file mode 100644 index 00000000000..03dc5cdbafd --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.js @@ -0,0 +1,59 @@ +//// [declarationEmit_classMemberNameConflict2.ts] + +const Bar = 'bar'; + +enum Hello { + World +} + +enum Hello1 { + World1 +} + +class Foo { + // Same names + string => OK + Bar = Bar; + + // Same names + enum => OK + Hello = Hello; + + // Different names + enum => OK + Hello2 = Hello1; +} + +//// [declarationEmit_classMemberNameConflict2.js] +var Bar = 'bar'; +var Hello; +(function (Hello) { + Hello[Hello["World"] = 0] = "World"; +})(Hello || (Hello = {})); +var Hello1; +(function (Hello1) { + Hello1[Hello1["World1"] = 0] = "World1"; +})(Hello1 || (Hello1 = {})); +var Foo = (function () { + function Foo() { + // Same names + string => OK + this.Bar = Bar; + // Same names + enum => OK + this.Hello = Hello; + // Different names + enum => OK + this.Hello2 = Hello1; + } + return Foo; +}()); + + +//// [declarationEmit_classMemberNameConflict2.d.ts] +declare const Bar: string; +declare enum Hello { + World = 0, +} +declare enum Hello1 { + World1 = 0, +} +declare class Foo { + Bar: string; + Hello: typeof Hello; + Hello2: typeof Hello1; +} diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict2.symbols b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.symbols new file mode 100644 index 00000000000..e7c4b6f060c --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.symbols @@ -0,0 +1,37 @@ +=== tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts === + +const Bar = 'bar'; +>Bar : Symbol(Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 5)) + +enum Hello { +>Hello : Symbol(Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 18)) + + World +>World : Symbol(Hello.World, Decl(declarationEmit_classMemberNameConflict2.ts, 3, 12)) +} + +enum Hello1 { +>Hello1 : Symbol(Hello1, Decl(declarationEmit_classMemberNameConflict2.ts, 5, 1)) + + World1 +>World1 : Symbol(Hello1.World1, Decl(declarationEmit_classMemberNameConflict2.ts, 7, 13)) +} + +class Foo { +>Foo : Symbol(Foo, Decl(declarationEmit_classMemberNameConflict2.ts, 9, 1)) + + // Same names + string => OK + Bar = Bar; +>Bar : Symbol(Foo.Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 11, 11)) +>Bar : Symbol(Bar, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 5)) + + // Same names + enum => OK + Hello = Hello; +>Hello : Symbol(Foo.Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 13, 14)) +>Hello : Symbol(Hello, Decl(declarationEmit_classMemberNameConflict2.ts, 1, 18)) + + // Different names + enum => OK + Hello2 = Hello1; +>Hello2 : Symbol(Foo.Hello2, Decl(declarationEmit_classMemberNameConflict2.ts, 16, 18)) +>Hello1 : Symbol(Hello1, Decl(declarationEmit_classMemberNameConflict2.ts, 5, 1)) +} diff --git a/tests/baselines/reference/declarationEmit_classMemberNameConflict2.types b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.types new file mode 100644 index 00000000000..9f8ddd8a2d5 --- /dev/null +++ b/tests/baselines/reference/declarationEmit_classMemberNameConflict2.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts === + +const Bar = 'bar'; +>Bar : string +>'bar' : string + +enum Hello { +>Hello : Hello + + World +>World : Hello +} + +enum Hello1 { +>Hello1 : Hello1 + + World1 +>World1 : Hello1 +} + +class Foo { +>Foo : Foo + + // Same names + string => OK + Bar = Bar; +>Bar : string +>Bar : string + + // Same names + enum => OK + Hello = Hello; +>Hello : typeof Hello +>Hello : typeof Hello + + // Different names + enum => OK + Hello2 = Hello1; +>Hello2 : typeof Hello1 +>Hello1 : typeof Hello1 +} diff --git a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.types b/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.types deleted file mode 100644 index e87560c6a3d..00000000000 --- a/tests/baselines/reference/moduleAugmentationCollidingNamesInAugmentation1.types +++ /dev/null @@ -1,69 +0,0 @@ -=== tests/cases/compiler/map1.ts === - -import { Observable } from "./observable" ->Observable : typeof Observable - -(Observable.prototype).map = function() { } ->(Observable.prototype).map = function() { } : () => void ->(Observable.prototype).map : any ->(Observable.prototype) : any ->Observable.prototype : any ->Observable.prototype : Observable ->Observable : typeof Observable ->prototype : Observable ->map : any ->function() { } : () => void - -declare module "./observable" { - interface I {x0} ->I : I ->x0 : any -} - -=== tests/cases/compiler/map2.ts === -import { Observable } from "./observable" ->Observable : typeof Observable - -(Observable.prototype).map = function() { } ->(Observable.prototype).map = function() { } : () => void ->(Observable.prototype).map : any ->(Observable.prototype) : any ->Observable.prototype : any ->Observable.prototype : Observable ->Observable : typeof Observable ->prototype : Observable ->map : any ->function() { } : () => void - -declare module "./observable" { - interface I {x1} ->I : I ->x1 : any -} - - -=== tests/cases/compiler/observable.ts === -export declare class Observable { ->Observable : Observable ->T : T - - filter(pred: (e:T) => boolean): Observable; ->filter : (pred: (e: T) => boolean) => Observable ->pred : (e: T) => boolean ->e : T ->T : T ->Observable : Observable ->T : T -} - -=== tests/cases/compiler/main.ts === -import { Observable } from "./observable" ->Observable : typeof Observable - -import "./map1"; -import "./map2"; - -let x: Observable; ->x : Observable ->Observable : Observable - diff --git a/tests/cases/compiler/declarationEmit_classMemberNameConflict.ts b/tests/cases/compiler/declarationEmit_classMemberNameConflict.ts new file mode 100644 index 00000000000..16f096d43ca --- /dev/null +++ b/tests/cases/compiler/declarationEmit_classMemberNameConflict.ts @@ -0,0 +1,39 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +export class C1 { + C1() { } // has to be the same as the class name + + bar() { + return function (t: typeof C1) { + }; + } +} + +export class C2 { + C2: any // has to be the same as the class name + + bar() { + return function (t: typeof C2) { + }; + } +} + +export class C3 { + get C3() { return 0; } // has to be the same as the class name + + bar() { + return function (t: typeof C3) { + }; + } +} + +export class C4 { + set C4(v) { } // has to be the same as the class name + + bar() { + return function (t: typeof C4) { + }; + } +} \ No newline at end of file diff --git a/tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts b/tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts new file mode 100644 index 00000000000..90b488ebec7 --- /dev/null +++ b/tests/cases/compiler/declarationEmit_classMemberNameConflict2.ts @@ -0,0 +1,24 @@ +// @target: es5 +// @module: commonjs +// @declaration: true + +const Bar = 'bar'; + +enum Hello { + World +} + +enum Hello1 { + World1 +} + +class Foo { + // Same names + string => OK + Bar = Bar; + + // Same names + enum => OK + Hello = Hello; + + // Different names + enum => OK + Hello2 = Hello1; +} \ No newline at end of file