Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isDeclarationName: support ComputedPropertyName #22123

Merged
2 commits merged into from
Feb 22, 2018
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23094,7 +23094,7 @@ namespace ts {
const rootChain = () => chainDiagnosticMessages(
/*details*/ undefined,
Diagnostics.Property_0_in_type_1_is_not_assignable_to_the_same_property_in_base_type_2,
unescapeLeadingUnderscores(declaredProp.escapedName),
symbolToString(declaredProp),
typeToString(typeWithThis),
typeToString(baseWithThis)
);
Expand Down
11 changes: 2 additions & 9 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1860,16 +1860,9 @@ namespace ts {
return false;
}

// True if the given identifier, string literal, or number literal is the name of a declaration node
// True if `name` is the name of a declaration node
export function isDeclarationName(name: Node): boolean {
switch (name.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.StringLiteral:
case SyntaxKind.NumericLiteral:
return isDeclaration(name.parent) && name.parent.name === name;
default:
return false;
}
return !isSourceFile(name) && !isBindingPattern(name) && isDeclaration(name.parent) && name.parent.name === name;
}

// See GH#16030
Expand Down
2 changes: 1 addition & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1532,7 +1532,7 @@ namespace Harness {
}

if (typesError && symbolsError) {
throw new Error(typesError.message + Harness.IO.newLine() + symbolsError.message);
throw new Error(typesError.stack + Harness.IO.newLine() + symbolsError.stack);
}

if (typesError) {
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/ES5For-ofTypeCheck10.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class StringIterator {
};
}
[Symbol.iterator]() {
>[Symbol.iterator] : Symbol(StringIterator[Symbol.iterator], Decl(ES5For-ofTypeCheck10.ts, 7, 5))

return this;
>this : Symbol(StringIterator, Decl(ES5For-ofTypeCheck10.ts, 0, 0))
}
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5For-ofTypeCheck10.types
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class StringIterator {
};
}
[Symbol.iterator]() {
>[Symbol.iterator] : () => this
>Symbol.iterator : any
>Symbol : any
>iterator : any
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty1.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var obj = {
>obj : Symbol(obj, Decl(ES5SymbolProperty1.ts, 5, 3))

[Symbol.foo]: 0
>[Symbol.foo] : Symbol([Symbol.foo], Decl(ES5SymbolProperty1.ts, 5, 11))
>Symbol.foo : Symbol(SymbolConstructor.foo, Decl(ES5SymbolProperty1.ts, 0, 29))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty1.ts, 3, 3))
>foo : Symbol(SymbolConstructor.foo, Decl(ES5SymbolProperty1.ts, 0, 29))
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty1.types
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var obj = {
>{ [Symbol.foo]: 0} : { [Symbol.foo]: number; }

[Symbol.foo]: 0
>[Symbol.foo] : number
>Symbol.foo : string
>Symbol : SymbolConstructor
>foo : string
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module M {
>C : Symbol(C, Decl(ES5SymbolProperty2.ts, 1, 20))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty2.ts, 3, 20))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty2.ts, 1, 7))
}
(new C)[Symbol.iterator];
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty2.types
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module M {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : any
>Symbol : any
>iterator : any
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty3.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class C {
>C : Symbol(C, Decl(ES5SymbolProperty3.ts, 0, 16))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty3.ts, 2, 9))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty3.ts, 0, 3))
}

Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty3.types
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class C {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : any
>Symbol : any
>iterator : any
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty4.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : Symbol(C, Decl(ES5SymbolProperty4.ts, 0, 33))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty4.ts, 2, 9))
>Symbol.iterator : Symbol(iterator, Decl(ES5SymbolProperty4.ts, 0, 13))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty4.ts, 0, 3))
>iterator : Symbol(iterator, Decl(ES5SymbolProperty4.ts, 0, 13))
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty4.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : string
>Symbol : { iterator: string; }
>iterator : string
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty5.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : Symbol(C, Decl(ES5SymbolProperty5.ts, 0, 33))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty5.ts, 2, 9))
>Symbol.iterator : Symbol(iterator, Decl(ES5SymbolProperty5.ts, 0, 13))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty5.ts, 0, 3))
>iterator : Symbol(iterator, Decl(ES5SymbolProperty5.ts, 0, 13))
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty5.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : symbol
>Symbol : { iterator: symbol; }
>iterator : symbol
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class C {
>C : Symbol(C, Decl(ES5SymbolProperty6.ts, 0, 0))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty6.ts, 0, 9))
}

(new C)[Symbol.iterator]
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty6.types
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class C {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : any
>Symbol : any
>iterator : any
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty7.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : Symbol(C, Decl(ES5SymbolProperty7.ts, 0, 30))

[Symbol.iterator]() { }
>[Symbol.iterator] : Symbol(C[Symbol.iterator], Decl(ES5SymbolProperty7.ts, 2, 9))
>Symbol.iterator : Symbol(iterator, Decl(ES5SymbolProperty7.ts, 0, 13))
>Symbol : Symbol(Symbol, Decl(ES5SymbolProperty7.ts, 0, 3))
>iterator : Symbol(iterator, Decl(ES5SymbolProperty7.ts, 0, 13))
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/ES5SymbolProperty7.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class C {
>C : C

[Symbol.iterator]() { }
>[Symbol.iterator] : () => void
>Symbol.iterator : any
>Symbol : { iterator: any; }
>iterator : any
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/FunctionDeclaration8_es6.symbols
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts ===
var v = { [yield]: foo }
>v : Symbol(v, Decl(FunctionDeclaration8_es6.ts, 0, 3))
>[yield] : Symbol([yield], Decl(FunctionDeclaration8_es6.ts, 0, 9))

1 change: 1 addition & 0 deletions tests/baselines/reference/FunctionDeclaration8_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var v = { [yield]: foo }
>v : { [x: number]: any; }
>{ [yield]: foo } : { [x: number]: any; }
>[yield] : any
>yield : any
>foo : any

1 change: 1 addition & 0 deletions tests/baselines/reference/FunctionDeclaration9_es6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ function * foo() {

var v = { [yield]: foo }
>v : Symbol(v, Decl(FunctionDeclaration9_es6.ts, 1, 5))
>[yield] : Symbol([yield], Decl(FunctionDeclaration9_es6.ts, 1, 11))
>foo : Symbol(foo, Decl(FunctionDeclaration9_es6.ts, 0, 0))
}
1 change: 1 addition & 0 deletions tests/baselines/reference/FunctionDeclaration9_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function * foo() {
var v = { [yield]: foo }
>v : { [x: number]: () => IterableIterator<any>; }
>{ [yield]: foo } : { [x: number]: () => IterableIterator<any>; }
>[yield] : () => IterableIterator<any>
>yield : any
>foo : () => IterableIterator<any>
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts ===
var v = { *[foo()]() { } }
>v : Symbol(v, Decl(FunctionPropertyAssignments5_es6.ts, 0, 3))
>[foo()] : Symbol([foo()], Decl(FunctionPropertyAssignments5_es6.ts, 0, 9))

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var v = { *[foo()]() { } }
>v : { [x: number]: () => IterableIterator<any>; }
>{ *[foo()]() { } } : { [x: number]: () => IterableIterator<any>; }
>[foo()] : () => IterableIterator<any>
>foo() : any
>foo : any

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ class C {
>C : Symbol(C, Decl(MemberFunctionDeclaration3_es6.ts, 0, 0))

*[foo]() { }
>[foo] : Symbol(C[foo], Decl(MemberFunctionDeclaration3_es6.ts, 0, 9))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ class C {
>C : C

*[foo]() { }
>[foo] : () => IterableIterator<any>
>foo : any
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var foo = async (): Promise<void> => {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncArrowFunction8_es2017.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncArrowFunction8_es2017.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncArrowFunction8_es2017.ts, 0, 3))
}
1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction8_es2017.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var foo = async (): Promise<void> => {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction8_es5.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var foo = async (): Promise<void> => {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncArrowFunction8_es5.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncArrowFunction8_es5.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncArrowFunction8_es5.ts, 0, 3))
}
1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction8_es5.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var foo = async (): Promise<void> => {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction8_es6.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ var foo = async (): Promise<void> => {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncArrowFunction8_es6.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncArrowFunction8_es6.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncArrowFunction8_es6.ts, 0, 3))
}
1 change: 1 addition & 0 deletions tests/baselines/reference/asyncArrowFunction8_es6.types
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var foo = async (): Promise<void> => {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/async/es2017/functionDeclarations/asyncFunctionDeclaration8_es2017.ts ===
var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration8_es2017.ts, 0, 3))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration8_es2017.ts, 0, 9))

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var v = { [await]: foo }
>v : { [x: number]: any; }
>{ [await]: foo } : { [x: number]: any; }
>[await] : any
>await : any
>foo : any

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/async/es5/functionDeclarations/asyncFunctionDeclaration8_es5.ts ===
var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration8_es5.ts, 0, 3))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration8_es5.ts, 0, 9))

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var v = { [await]: foo }
>v : { [x: number]: any; }
>{ [await]: foo } : { [x: number]: any; }
>[await] : any
>await : any
>foo : any

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
=== tests/cases/conformance/async/es6/functionDeclarations/asyncFunctionDeclaration8_es6.ts ===
var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration8_es6.ts, 0, 3))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration8_es6.ts, 0, 9))

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
var v = { [await]: foo }
>v : { [x: number]: any; }
>{ [await]: foo } : { [x: number]: any; }
>[await] : any
>await : any
>foo : any

Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ async function foo(): Promise<void> {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration9_es2017.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration9_es2017.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncFunctionDeclaration9_es2017.ts, 0, 0))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async function foo(): Promise<void> {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ async function foo(): Promise<void> {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration9_es5.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration9_es5.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncFunctionDeclaration9_es5.ts, 0, 0))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async function foo(): Promise<void> {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ async function foo(): Promise<void> {

var v = { [await]: foo }
>v : Symbol(v, Decl(asyncFunctionDeclaration9_es6.ts, 1, 5))
>[await] : Symbol([await], Decl(asyncFunctionDeclaration9_es6.ts, 1, 11))
>foo : Symbol(foo, Decl(asyncFunctionDeclaration9_es6.ts, 0, 0))
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ async function foo(): Promise<void> {
var v = { [await]: foo }
>v : { [x: number]: () => Promise<void>; }
>{ [await]: foo } : { [x: number]: () => Promise<void>; }
>[await] : () => Promise<void>
>await : any
> : any
>foo : () => Promise<void>
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/capturedLetConstInLoop13.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Main {
>bar : Symbol(Main.bar, Decl(capturedLetConstInLoop13.ts, 13, 5))

[name + ".a"]: () => { this.foo(name); },
>[name + ".a"] : Symbol([name + ".a"], Decl(capturedLetConstInLoop13.ts, 9, 22))
>name : Symbol(name, Decl(capturedLetConstInLoop13.ts, 7, 16))
>this.foo : Symbol(Main.foo, Decl(capturedLetConstInLoop13.ts, 15, 33))
>this : Symbol(Main, Decl(capturedLetConstInLoop13.ts, 0, 0))
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/capturedLetConstInLoop13.types
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Main {
>{ [name + ".a"]: () => { this.foo(name); }, } : { [x: string]: () => void; }

[name + ".a"]: () => { this.foo(name); },
>[name + ".a"] : () => void
>name + ".a" : string
>name : string
>".a" : ".a"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ function foo(y = class {static c = x}, x = 1) {
function foo2(y = class {[x] = x}, x = 1) {
>foo2 : Symbol(foo2, Decl(capturedParametersInInitializers2.ts, 2, 1))
>y : Symbol(y, Decl(capturedParametersInInitializers2.ts, 3, 14))
>[x] : Symbol((Anonymous class)[x], Decl(capturedParametersInInitializers2.ts, 3, 25))
>x : Symbol(x, Decl(capturedParametersInInitializers2.ts, 3, 34))
>x : Symbol(x, Decl(capturedParametersInInitializers2.ts, 3, 34))
>x : Symbol(x, Decl(capturedParametersInInitializers2.ts, 3, 34))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function foo2(y = class {[x] = x}, x = 1) {
>foo2 : (y?: typeof (Anonymous class), x?: number) => void
>y : typeof (Anonymous class)
>class {[x] = x} : typeof (Anonymous class)
>[x] : number
>x : number
>x : number
>x : number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const obj = {

/** @type {number} */
['b' + 'ar1']: 42,
>['b' + 'ar1'] : Symbol(['b' + 'ar1'], Decl(0.js, 12, 6))

/** @type {function(number): number} */
arrowFunc: (num) => num + 42
>arrowFunc : Symbol(arrowFunc, Decl(0.js, 14, 20))
Expand Down
Loading