Skip to content

Commit c984361

Browse files
committed
fix unnecessary Reference Check with property signature
1 parent aa26a59 commit c984361

5 files changed

Lines changed: 88 additions & 0 deletions

src/compiler/checker.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,10 @@ namespace ts {
11751175
return true;
11761176
}
11771177

1178+
if (isComputedPropertyName(current) && isPropertySignature(current.parent) && current.parent.name === current) {
1179+
return true;
1180+
}
1181+
11781182
const initializerOfProperty = current.parent &&
11791183
current.parent.kind === SyntaxKind.PropertyDeclaration &&
11801184
(<PropertyDeclaration>current.parent).initializer === current;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//// [unnecessaryReferenceChecksWithPropertySignature.ts]
2+
interface C {
3+
[C.a](): void;
4+
[C.b]: void;
5+
}
6+
class C {
7+
static readonly a = Symbol();
8+
static readonly b = Symbol();
9+
}
10+
11+
12+
//// [unnecessaryReferenceChecksWithPropertySignature.js]
13+
class C {
14+
}
15+
C.a = Symbol();
16+
C.b = Symbol();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts ===
2+
interface C {
3+
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
4+
5+
[C.a](): void;
6+
>[C.a] : Symbol(C[C.a], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 13))
7+
>C.a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 4, 9))
8+
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
9+
>a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 4, 9))
10+
11+
[C.b]: void;
12+
>[C.b] : Symbol(C[C.b], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 1, 16))
13+
>C.b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 31))
14+
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
15+
>b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 31))
16+
}
17+
class C {
18+
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
19+
20+
static readonly a = Symbol();
21+
>a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 4, 9))
22+
>Symbol : Symbol(Symbol, Decl(lib.es6.d.ts, --, --), Decl(lib.es6.d.ts, --, --), Decl(lib.es6.d.ts, --, --))
23+
24+
static readonly b = Symbol();
25+
>b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 31))
26+
>Symbol : Symbol(Symbol, Decl(lib.es6.d.ts, --, --), Decl(lib.es6.d.ts, --, --), Decl(lib.es6.d.ts, --, --))
27+
}
28+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
=== tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts ===
2+
interface C {
3+
>C : C
4+
5+
[C.a](): void;
6+
>[C.a] : () => void
7+
>C.a : unique symbol
8+
>C : typeof C
9+
>a : unique symbol
10+
11+
[C.b]: void;
12+
>[C.b] : void
13+
>C.b : unique symbol
14+
>C : typeof C
15+
>b : unique symbol
16+
}
17+
class C {
18+
>C : C
19+
20+
static readonly a = Symbol();
21+
>a : unique symbol
22+
>Symbol() : unique symbol
23+
>Symbol : SymbolConstructor
24+
25+
static readonly b = Symbol();
26+
>b : unique symbol
27+
>Symbol() : unique symbol
28+
>Symbol : SymbolConstructor
29+
}
30+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// @target: es6
2+
3+
interface C {
4+
[C.a](): void;
5+
[C.b]: void;
6+
}
7+
class C {
8+
static readonly a = Symbol();
9+
static readonly b = Symbol();
10+
}

0 commit comments

Comments
 (0)