Fix get type from short-hand property assignment

This commit is contained in:
Yui T 2014-11-10 10:51:08 -08:00
parent 8a779e1e85
commit e9122b4d85
3 changed files with 11 additions and 2 deletions

View File

@ -1665,6 +1665,13 @@ module ts {
}
return type;
}
// If it is a short-hand property assignment; Use the type of the identifier
if (declaration.kind === SyntaxKind.ShortHandPropertyAssignment) {
var type = checkIdentifier(<Identifier>(declaration.name));
return type
}
// Rest parameters default to type any[], other parameters default to type any
var type = declaration.flags & NodeFlags.Rest ? createArrayType(anyType) : anyType;
checkImplicitAny(type);

View File

@ -574,6 +574,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.FunctionDeclaration:

View File

@ -1969,7 +1969,7 @@ module ts {
/** Returns true if node is a name of an object literal property, e.g. "a" in x = { "a": 1 } */
function isNameOfPropertyAssignment(node: Node): boolean {
return (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.StringLiteral || node.kind === SyntaxKind.NumericLiteral) &&
node.parent.kind === SyntaxKind.PropertyAssignment && (<PropertyDeclaration>node.parent).name === node;
(node.parent.kind === SyntaxKind.PropertyAssignment || node.parent.kind === SyntaxKind.ShortHandPropertyAssignment) && (<PropertyDeclaration>node.parent).name === node;
}
function isLiteralNameOfPropertyDeclarationOrIndexAccess(node: Node): boolean {
@ -2648,7 +2648,7 @@ module ts {
var existingMemberNames: Map<boolean> = {};
forEach(existingMembers, m => {
if (m.kind !== SyntaxKind.PropertyAssignment) {
if (m.kind !== SyntaxKind.PropertyAssignment && m.kind !== SyntaxKind.ShortHandPropertyAssignment) {
// Ignore omitted expressions for missing members in the object literal
return;
}
@ -4569,6 +4569,7 @@ module ts {
case SyntaxKind.VariableDeclaration:
case SyntaxKind.Property:
case SyntaxKind.PropertyAssignment:
case SyntaxKind.ShortHandPropertyAssignment:
case SyntaxKind.EnumMember:
case SyntaxKind.Method:
case SyntaxKind.Constructor: