Skip to content

Commit e0ab009

Browse files
committed
Remove members from getAccessibleSymbolChain walk
1 parent 1156141 commit e0ab009

10 files changed

+475
-76
lines changed

src/compiler/checker.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,12 +1444,6 @@ namespace ts {
14441444
return result;
14451445
}
14461446
break;
1447-
case SyntaxKind.ClassDeclaration:
1448-
case SyntaxKind.InterfaceDeclaration:
1449-
if (result = callback(getSymbolOfNode(location).members)) {
1450-
return result;
1451-
}
1452-
break;
14531447
}
14541448
}
14551449

@@ -1515,7 +1509,9 @@ namespace ts {
15151509
}
15161510

15171511
if (symbol) {
1518-
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
1512+
if (!(isPropertyOrMethodDeclarationSymbol(symbol))) {
1513+
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
1514+
}
15191515
}
15201516
}
15211517

@@ -1548,6 +1544,24 @@ namespace ts {
15481544
return qualify;
15491545
}
15501546

1547+
function isPropertyOrMethodDeclarationSymbol(symbol: Symbol) {
1548+
if (symbol.declarations && symbol.declarations.length) {
1549+
for (const declaration of symbol.declarations) {
1550+
switch (declaration.kind) {
1551+
case SyntaxKind.PropertyDeclaration:
1552+
case SyntaxKind.MethodDeclaration:
1553+
case SyntaxKind.GetAccessor:
1554+
case SyntaxKind.SetAccessor:
1555+
continue;
1556+
default:
1557+
return false;
1558+
}
1559+
}
1560+
return true;
1561+
}
1562+
return false;
1563+
}
1564+
15511565
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult {
15521566
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
15531567
const initialSymbol = symbol;
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
//// [declarationEmit_classMemberNameConflict.ts]
2+
3+
export class C1 {
4+
C1() { } // has to be the same as the class name
5+
6+
bar() {
7+
return function (t: typeof C1) {
8+
};
9+
}
10+
}
11+
12+
export class C2 {
13+
C2: any // has to be the same as the class name
14+
15+
bar() {
16+
return function (t: typeof C2) {
17+
};
18+
}
19+
}
20+
21+
export class C3 {
22+
get C3() { return 0; } // has to be the same as the class name
23+
24+
bar() {
25+
return function (t: typeof C3) {
26+
};
27+
}
28+
}
29+
30+
export class C4 {
31+
set C4(v) { } // has to be the same as the class name
32+
33+
bar() {
34+
return function (t: typeof C4) {
35+
};
36+
}
37+
}
38+
39+
//// [declarationEmit_classMemberNameConflict.js]
40+
"use strict";
41+
var C1 = (function () {
42+
function C1() {
43+
}
44+
C1.prototype.C1 = function () { }; // has to be the same as the class name
45+
C1.prototype.bar = function () {
46+
return function (t) {
47+
};
48+
};
49+
return C1;
50+
}());
51+
exports.C1 = C1;
52+
var C2 = (function () {
53+
function C2() {
54+
}
55+
C2.prototype.bar = function () {
56+
return function (t) {
57+
};
58+
};
59+
return C2;
60+
}());
61+
exports.C2 = C2;
62+
var C3 = (function () {
63+
function C3() {
64+
}
65+
Object.defineProperty(C3.prototype, "C3", {
66+
get: function () { return 0; } // has to be the same as the class name
67+
,
68+
enumerable: true,
69+
configurable: true
70+
});
71+
C3.prototype.bar = function () {
72+
return function (t) {
73+
};
74+
};
75+
return C3;
76+
}());
77+
exports.C3 = C3;
78+
var C4 = (function () {
79+
function C4() {
80+
}
81+
Object.defineProperty(C4.prototype, "C4", {
82+
set: function (v) { } // has to be the same as the class name
83+
,
84+
enumerable: true,
85+
configurable: true
86+
});
87+
C4.prototype.bar = function () {
88+
return function (t) {
89+
};
90+
};
91+
return C4;
92+
}());
93+
exports.C4 = C4;
94+
95+
96+
//// [declarationEmit_classMemberNameConflict.d.ts]
97+
export declare class C1 {
98+
C1(): void;
99+
bar(): (t: typeof C1) => void;
100+
}
101+
export declare class C2 {
102+
C2: any;
103+
bar(): (t: typeof C2) => void;
104+
}
105+
export declare class C3 {
106+
readonly C3: number;
107+
bar(): (t: typeof C3) => void;
108+
}
109+
export declare class C4 {
110+
C4: any;
111+
bar(): (t: typeof C4) => void;
112+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts ===
2+
3+
export class C1 {
4+
>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0))
5+
6+
C1() { } // has to be the same as the class name
7+
>C1 : Symbol(C1.C1, Decl(declarationEmit_classMemberNameConflict.ts, 1, 17))
8+
9+
bar() {
10+
>bar : Symbol(C1.bar, Decl(declarationEmit_classMemberNameConflict.ts, 2, 12))
11+
12+
return function (t: typeof C1) {
13+
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 5, 25))
14+
>C1 : Symbol(C1, Decl(declarationEmit_classMemberNameConflict.ts, 0, 0))
15+
16+
};
17+
}
18+
}
19+
20+
export class C2 {
21+
>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1))
22+
23+
C2: any // has to be the same as the class name
24+
>C2 : Symbol(C2.C2, Decl(declarationEmit_classMemberNameConflict.ts, 10, 17))
25+
26+
bar() {
27+
>bar : Symbol(C2.bar, Decl(declarationEmit_classMemberNameConflict.ts, 11, 11))
28+
29+
return function (t: typeof C2) {
30+
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 14, 25))
31+
>C2 : Symbol(C2, Decl(declarationEmit_classMemberNameConflict.ts, 8, 1))
32+
33+
};
34+
}
35+
}
36+
37+
export class C3 {
38+
>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1))
39+
40+
get C3() { return 0; } // has to be the same as the class name
41+
>C3 : Symbol(C3.C3, Decl(declarationEmit_classMemberNameConflict.ts, 19, 17))
42+
43+
bar() {
44+
>bar : Symbol(C3.bar, Decl(declarationEmit_classMemberNameConflict.ts, 20, 26))
45+
46+
return function (t: typeof C3) {
47+
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 23, 25))
48+
>C3 : Symbol(C3, Decl(declarationEmit_classMemberNameConflict.ts, 17, 1))
49+
50+
};
51+
}
52+
}
53+
54+
export class C4 {
55+
>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1))
56+
57+
set C4(v) { } // has to be the same as the class name
58+
>C4 : Symbol(C4.C4, Decl(declarationEmit_classMemberNameConflict.ts, 28, 17))
59+
>v : Symbol(v, Decl(declarationEmit_classMemberNameConflict.ts, 29, 11))
60+
61+
bar() {
62+
>bar : Symbol(C4.bar, Decl(declarationEmit_classMemberNameConflict.ts, 29, 17))
63+
64+
return function (t: typeof C4) {
65+
>t : Symbol(t, Decl(declarationEmit_classMemberNameConflict.ts, 32, 25))
66+
>C4 : Symbol(C4, Decl(declarationEmit_classMemberNameConflict.ts, 26, 1))
67+
68+
};
69+
}
70+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
=== tests/cases/compiler/declarationEmit_classMemberNameConflict.ts ===
2+
3+
export class C1 {
4+
>C1 : C1
5+
6+
C1() { } // has to be the same as the class name
7+
>C1 : () => void
8+
9+
bar() {
10+
>bar : () => (t: typeof C1) => void
11+
12+
return function (t: typeof C1) {
13+
>function (t: typeof C1) { } : (t: typeof C1) => void
14+
>t : typeof C1
15+
>C1 : typeof C1
16+
17+
};
18+
}
19+
}
20+
21+
export class C2 {
22+
>C2 : C2
23+
24+
C2: any // has to be the same as the class name
25+
>C2 : any
26+
27+
bar() {
28+
>bar : () => (t: typeof C2) => void
29+
30+
return function (t: typeof C2) {
31+
>function (t: typeof C2) { } : (t: typeof C2) => void
32+
>t : typeof C2
33+
>C2 : typeof C2
34+
35+
};
36+
}
37+
}
38+
39+
export class C3 {
40+
>C3 : C3
41+
42+
get C3() { return 0; } // has to be the same as the class name
43+
>C3 : number
44+
>0 : number
45+
46+
bar() {
47+
>bar : () => (t: typeof C3) => void
48+
49+
return function (t: typeof C3) {
50+
>function (t: typeof C3) { } : (t: typeof C3) => void
51+
>t : typeof C3
52+
>C3 : typeof C3
53+
54+
};
55+
}
56+
}
57+
58+
export class C4 {
59+
>C4 : C4
60+
61+
set C4(v) { } // has to be the same as the class name
62+
>C4 : any
63+
>v : any
64+
65+
bar() {
66+
>bar : () => (t: typeof C4) => void
67+
68+
return function (t: typeof C4) {
69+
>function (t: typeof C4) { } : (t: typeof C4) => void
70+
>t : typeof C4
71+
>C4 : typeof C4
72+
73+
};
74+
}
75+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//// [declarationEmit_classMemberNameConflict2.ts]
2+
3+
const Bar = 'bar';
4+
5+
enum Hello {
6+
World
7+
}
8+
9+
enum Hello1 {
10+
World1
11+
}
12+
13+
class Foo {
14+
// Same names + string => OK
15+
Bar = Bar;
16+
17+
// Same names + enum => OK
18+
Hello = Hello;
19+
20+
// Different names + enum => OK
21+
Hello2 = Hello1;
22+
}
23+
24+
//// [declarationEmit_classMemberNameConflict2.js]
25+
var Bar = 'bar';
26+
var Hello;
27+
(function (Hello) {
28+
Hello[Hello["World"] = 0] = "World";
29+
})(Hello || (Hello = {}));
30+
var Hello1;
31+
(function (Hello1) {
32+
Hello1[Hello1["World1"] = 0] = "World1";
33+
})(Hello1 || (Hello1 = {}));
34+
var Foo = (function () {
35+
function Foo() {
36+
// Same names + string => OK
37+
this.Bar = Bar;
38+
// Same names + enum => OK
39+
this.Hello = Hello;
40+
// Different names + enum => OK
41+
this.Hello2 = Hello1;
42+
}
43+
return Foo;
44+
}());
45+
46+
47+
//// [declarationEmit_classMemberNameConflict2.d.ts]
48+
declare const Bar: string;
49+
declare enum Hello {
50+
World = 0,
51+
}
52+
declare enum Hello1 {
53+
World1 = 0,
54+
}
55+
declare class Foo {
56+
Bar: string;
57+
Hello: typeof Hello;
58+
Hello2: typeof Hello1;
59+
}

0 commit comments

Comments
 (0)