From 4c0122d879eeb9c2b6517c84b3c0c71e21ad2eb0 Mon Sep 17 00:00:00 2001 From: Jason Freeman Date: Mon, 12 Jan 2015 17:21:55 -0800 Subject: [PATCH] Move computed property checks so that they will be checked in classes and interfaces --- src/compiler/checker.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 15df97de4c9..e15dcb37d70 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5421,7 +5421,7 @@ module ts { memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment || isObjectLiteralMethod(memberDecl)) { if (memberDecl.kind === SyntaxKind.PropertyAssignment) { - var type = checkExpression((memberDecl).initializer, contextualMapper); + var type = checkPropertyAssignment(memberDecl, contextualMapper); } else if (memberDecl.kind === SyntaxKind.MethodDeclaration) { var type = checkObjectLiteralMethod(memberDecl, contextualMapper); @@ -5454,10 +5454,7 @@ module ts { checkAccessorDeclaration(memberDecl); } - if (hasComputedNameButNotSymbol(memberDecl)) { - checkComputedPropertyName(memberDecl.name); - } - else { + if (!hasComputedNameButNotSymbol(memberDecl)) { properties[member.name] = member; } } @@ -7050,10 +7047,22 @@ module ts { return links.resolvedType; } + function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type { + if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); + } + + return checkExpression((node).initializer, contextualMapper); + } + function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type { // Grammar checking checkGrammarMethod(node); + if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); + } + var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper); return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper); } @@ -7862,7 +7871,12 @@ module ts { function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void { checkSignatureDeclaration(node); - if (!hasComputedNameButNotSymbol(node)) { + if (hasComputedNameButNotSymbol(node)) { + // This check will account for methods in class/interface declarations, + // as well as accessors in classes/object literals + checkComputedPropertyName(node.name); + } + else { // first we want to check the local symbol that contain this declaration // - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol // - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode @@ -8092,6 +8106,7 @@ module ts { checkSourceElement(node.type); // For a computed property, just check the initializer and exit if (hasComputedNameButNotSymbol(node)) { + checkComputedPropertyName(node.name); if (node.initializer) { checkExpressionCached(node.initializer); }