Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,10 @@ namespace ts {
return true;
}

if (isComputedPropertyName(current) && isPropertySignature(current.parent) && current.parent.name === current) {
return true;
}

const initializerOfProperty = current.parent &&
current.parent.kind === SyntaxKind.PropertyDeclaration &&
(<PropertyDeclaration>current.parent).initializer === current;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts(6,4): error TS2449: Class 'C' used before its declaration.
tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts(13,3): error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type.
tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts(13,4): error TS2449: Class 'D' used before its declaration.


==== tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts (3 errors) ====
interface C {
[C.a](): void;
[C.b]: void;
}
class C {
[C.c] = 1;
~
!!! error TS2449: Class 'C' used before its declaration.
static readonly a = Symbol();
static readonly b = Symbol();
static readonly c = Symbol();
}

class D {
[D.a] = 0;
~~~~~
!!! error TS1166: A computed property name in a class property declaration must refer to an expression whose type is a literal type or a 'unique symbol' type.
~
!!! error TS2449: Class 'D' used before its declaration.
static a = "a";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//// [unnecessaryReferenceChecksWithPropertySignature.ts]
interface C {
[C.a](): void;
[C.b]: void;
}
class C {
[C.c] = 1;
static readonly a = Symbol();
static readonly b = Symbol();
static readonly c = Symbol();
}

class D {
[D.a] = 0;
static a = "a";
}

//// [unnecessaryReferenceChecksWithPropertySignature.js]
var _a, _b;
class C {
constructor() {
this[_a] = 1;
}
}
_a = C.c;
C.a = Symbol();
C.b = Symbol();
C.c = Symbol();
class D {
constructor() {
this[_b] = 0;
}
}
_b = D.a;
D.a = "a";
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
=== tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts ===
interface C {
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))

[C.a](): void;
>[C.a] : Symbol(C[C.a], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 13))
>C.a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 12))
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
>a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 12))

[C.b]: void;
>[C.b] : Symbol(C[C.b], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 1, 16))
>C.b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 6, 31))
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
>b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 6, 31))
}
class C {
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))

[C.c] = 1;
>[C.c] : Symbol(C[C.c], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 4, 9))
>C.c : Symbol(C.c, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 7, 31))
>C : Symbol(C, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 0, 0), Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 3, 1))
>c : Symbol(C.c, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 7, 31))

static readonly a = Symbol();
>a : Symbol(C.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 5, 12))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

static readonly b = Symbol();
>b : Symbol(C.b, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 6, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))

static readonly c = Symbol();
>c : Symbol(C.c, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 7, 31))
>Symbol : Symbol(Symbol, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --))
}

class D {
>D : Symbol(D, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 9, 1))

[D.a] = 0;
>[D.a] : Symbol(D[D.a], Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 11, 9))
>D.a : Symbol(D.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 12, 12))
>D : Symbol(D, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 9, 1))
>a : Symbol(D.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 12, 12))

static a = "a";
>a : Symbol(D.a, Decl(unnecessaryReferenceChecksWithPropertySignature.ts, 12, 12))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
=== tests/cases/compiler/unnecessaryReferenceChecksWithPropertySignature.ts ===
interface C {
>C : C

[C.a](): void;
>[C.a] : () => void
>C.a : unique symbol
>C : typeof C
>a : unique symbol

[C.b]: void;
>[C.b] : void
>C.b : unique symbol
>C : typeof C
>b : unique symbol
}
class C {
>C : C

[C.c] = 1;
>[C.c] : number
>C.c : unique symbol
>C : typeof C
>c : unique symbol
>1 : 1

static readonly a = Symbol();
>a : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

static readonly b = Symbol();
>b : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor

static readonly c = Symbol();
>c : unique symbol
>Symbol() : unique symbol
>Symbol : SymbolConstructor
}

class D {
>D : D

[D.a] = 0;
>[D.a] : number
>D.a : string
>D : typeof D
>a : string
>0 : 0

static a = "a";
>a : string
>"a" : "a"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// @target: es6

interface C {
[C.a](): void;
[C.b]: void;
}
class C {
[C.c] = 1;
static readonly a = Symbol();
static readonly b = Symbol();
static readonly c = Symbol();
}

class D {
[D.a] = 0;
static a = "a";
}