Add named property symbol for known Symbol properties
This commit is contained in:
parent
07f3641af2
commit
f344654460
5 changed files with 18 additions and 7 deletions
|
@ -87,13 +87,18 @@ module ts {
|
|||
if (symbolKind & SymbolFlags.Value && !symbol.valueDeclaration) symbol.valueDeclaration = node;
|
||||
}
|
||||
|
||||
// Should not be called on a declaration with a computed property name.
|
||||
// Should not be called on a declaration with a computed property name,
|
||||
// unless it is a well known Symbol.
|
||||
function getDeclarationName(node: Declaration): string {
|
||||
if (node.name) {
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) {
|
||||
return '"' + (<LiteralExpression>node.name).text + '"';
|
||||
}
|
||||
Debug.assert(!hasDynamicName(node));
|
||||
if (node.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
var nameExpression = (<ComputedPropertyName>node.name).expression;
|
||||
Debug.assert(isWellKnownSymbolSyntactically(nameExpression));
|
||||
return "__@" + (<PropertyAccessExpression>nameExpression).name.text;
|
||||
}
|
||||
return (<Identifier | LiteralExpression>node.name).text;
|
||||
}
|
||||
switch (node.kind) {
|
||||
|
|
|
@ -706,9 +706,15 @@ module ts {
|
|||
return type;
|
||||
}
|
||||
|
||||
// A reserved member name starts with two underscores followed by a non-underscore
|
||||
// A reserved member name starts with two underscores, but the third character cannot be an underscore
|
||||
// or the @ symbol. A third underscore indicates an escaped form of an identifer that started
|
||||
// with at least two underscores. The @ character indicates that the name is denoted by a well known ES
|
||||
// Symbol instance.
|
||||
function isReservedMemberName(name: string) {
|
||||
return name.charCodeAt(0) === CharacterCodes._ && name.charCodeAt(1) === CharacterCodes._ && name.charCodeAt(2) !== CharacterCodes._;
|
||||
return name.charCodeAt(0) === CharacterCodes._ &&
|
||||
name.charCodeAt(1) === CharacterCodes._ &&
|
||||
name.charCodeAt(2) !== CharacterCodes._ &&
|
||||
name.charCodeAt(2) !== CharacterCodes.at;
|
||||
}
|
||||
|
||||
function getNamedMembers(members: SymbolTable): Symbol[] {
|
||||
|
|
|
@ -848,7 +848,7 @@ module ts {
|
|||
!isWellKnownSymbolSyntactically((<ComputedPropertyName>declaration.name).expression);
|
||||
}
|
||||
|
||||
export function isWellKnownSymbolSyntactically(node: Node): boolean {
|
||||
export function isWellKnownSymbolSyntactically(node: Expression): boolean {
|
||||
return node.kind === SyntaxKind.PropertyAccessExpression && isESSymbolIdentifier((<PropertyAccessExpression>node).expression);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
=== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolProperty8.ts ===
|
||||
var x: {
|
||||
>x : {}
|
||||
>x : { [Symbol.toPrimitive](): string; }
|
||||
|
||||
[Symbol.toPrimitive](): string
|
||||
>Symbol.toPrimitive : Symbol
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
=== tests/cases/conformance/parser/ecmascript6/Symbols/parserSymbolProperty9.ts ===
|
||||
var x: {
|
||||
>x : {}
|
||||
>x : { [Symbol.toPrimitive]: string; }
|
||||
|
||||
[Symbol.toPrimitive]: string
|
||||
>Symbol.toPrimitive : Symbol
|
||||
|
|
Loading…
Reference in a new issue