Skip to content

Commit c98c763

Browse files
committed
Fix #5651: Get the correct meaning for expressions in extends clauses
1 parent baa0401 commit c98c763

5 files changed

+129
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,7 @@ namespace ts {
16421642
function isEntityNameVisible(entityName: EntityName | Expression, enclosingDeclaration: Node): SymbolVisibilityResult {
16431643
// get symbol of the first identifier of the entityName
16441644
let meaning: SymbolFlags;
1645-
if (entityName.parent.kind === SyntaxKind.TypeQuery) {
1645+
if (entityName.parent.kind === SyntaxKind.TypeQuery || isExpressionWithTypeArgumentsInClassExtendsClause(entityName.parent)) {
16461646
// Typeof value
16471647
meaning = SymbolFlags.Value | SymbolFlags.ExportValue;
16481648
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//// [declarationEmit_expressionInExtends.ts]
2+
3+
var x: {
4+
new<T>(s: any): Q;
5+
}
6+
7+
class Q {
8+
s: string;
9+
}
10+
11+
class B extends x<string> {
12+
}
13+
14+
var q: B;
15+
q.s;
16+
17+
//// [declarationEmit_expressionInExtends.js]
18+
var __extends = (this && this.__extends) || function (d, b) {
19+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
20+
function __() { this.constructor = d; }
21+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
22+
};
23+
var x;
24+
var Q = (function () {
25+
function Q() {
26+
}
27+
return Q;
28+
}());
29+
var B = (function (_super) {
30+
__extends(B, _super);
31+
function B() {
32+
_super.apply(this, arguments);
33+
}
34+
return B;
35+
}(x));
36+
var q;
37+
q.s;
38+
39+
40+
//// [declarationEmit_expressionInExtends.d.ts]
41+
declare var x: {
42+
new <T>(s: any): Q;
43+
};
44+
declare class Q {
45+
s: string;
46+
}
47+
declare class B extends x<string> {
48+
}
49+
declare var q: B;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/declarationEmit_expressionInExtends.ts ===
2+
3+
var x: {
4+
>x : Symbol(x, Decl(declarationEmit_expressionInExtends.ts, 1, 3))
5+
6+
new<T>(s: any): Q;
7+
>T : Symbol(T, Decl(declarationEmit_expressionInExtends.ts, 2, 8))
8+
>s : Symbol(s, Decl(declarationEmit_expressionInExtends.ts, 2, 11))
9+
>Q : Symbol(Q, Decl(declarationEmit_expressionInExtends.ts, 3, 1))
10+
}
11+
12+
class Q {
13+
>Q : Symbol(Q, Decl(declarationEmit_expressionInExtends.ts, 3, 1))
14+
15+
s: string;
16+
>s : Symbol(s, Decl(declarationEmit_expressionInExtends.ts, 5, 9))
17+
}
18+
19+
class B extends x<string> {
20+
>B : Symbol(B, Decl(declarationEmit_expressionInExtends.ts, 7, 1))
21+
>x : Symbol(x, Decl(declarationEmit_expressionInExtends.ts, 1, 3))
22+
}
23+
24+
var q: B;
25+
>q : Symbol(q, Decl(declarationEmit_expressionInExtends.ts, 12, 3))
26+
>B : Symbol(B, Decl(declarationEmit_expressionInExtends.ts, 7, 1))
27+
28+
q.s;
29+
>q.s : Symbol(Q.s, Decl(declarationEmit_expressionInExtends.ts, 5, 9))
30+
>q : Symbol(q, Decl(declarationEmit_expressionInExtends.ts, 12, 3))
31+
>s : Symbol(Q.s, Decl(declarationEmit_expressionInExtends.ts, 5, 9))
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
=== tests/cases/compiler/declarationEmit_expressionInExtends.ts ===
2+
3+
var x: {
4+
>x : new <T>(s: any) => Q
5+
6+
new<T>(s: any): Q;
7+
>T : T
8+
>s : any
9+
>Q : Q
10+
}
11+
12+
class Q {
13+
>Q : Q
14+
15+
s: string;
16+
>s : string
17+
}
18+
19+
class B extends x<string> {
20+
>B : B
21+
>x : Q
22+
}
23+
24+
var q: B;
25+
>q : B
26+
>B : B
27+
28+
q.s;
29+
>q.s : string
30+
>q : B
31+
>s : string
32+
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @declaration: true
2+
3+
var x: {
4+
new<T>(s: any): Q;
5+
}
6+
7+
class Q {
8+
s: string;
9+
}
10+
11+
class B extends x<string> {
12+
}
13+
14+
var q: B;
15+
q.s;

0 commit comments

Comments
 (0)