From 7fe811e6b220cb3b0daa6c931ec7fe73e478efcb Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 10 Dec 2015 16:02:46 -0800 Subject: [PATCH] Defer checks of accessor bodies in object literals --- src/compiler/checker.ts | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 50a3aee9955..c3dc5935775 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11297,6 +11297,8 @@ namespace ts { // Grammar checking accessors checkGrammarFunctionLikeDeclaration(node) || checkGrammarAccessor(node) || checkGrammarComputedPropertyName(node.name); + checkDecorators(node); + checkSignatureDeclaration(node); if (node.kind === SyntaxKind.GetAccessor) { if (!isInAmbientContext(node) && nodeIsPresent(node.body) && (node.flags & NodeFlags.HasImplicitReturn)) { if (node.flags & NodeFlags.HasExplicitReturn) { @@ -11309,7 +11311,12 @@ namespace ts { } } } - + // Do not use hasDynamicName here, because that returns false for well known symbols. + // We want to perform checkComputedPropertyName for all computed properties, including + // well known symbols. + if (node.name.kind === SyntaxKind.ComputedPropertyName) { + checkComputedPropertyName(node.name); + } if (!hasDynamicName(node)) { // TypeScript 1.0 spec (April 2014): 8.4.3 // Accessors for the same member name must specify the same accessibility. @@ -11333,8 +11340,16 @@ namespace ts { } getTypeOfAccessors(getSymbolOfNode(node)); } + if (node.parent.kind !== SyntaxKind.ObjectLiteralExpression) { + checkSourceElement(node.body); + } + } - checkFunctionLikeDeclaration(node); + function checkObjectLiteralAccessorBody(node: AccessorDeclaration) { + if (node.body) { + checkSourceElement(node.body); + checkFunctionAndClassExpressionBodies(node.body); + } } function checkMissingDeclaration(node: Node) { @@ -14379,11 +14394,16 @@ namespace ts { } break; case SyntaxKind.Constructor: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: forEach((node).parameters, checkFunctionAndClassExpressionBodies); break; + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + forEach((node).parameters, checkFunctionAndClassExpressionBodies); + if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) { + checkObjectLiteralAccessorBody(node); + } + break; case SyntaxKind.WithStatement: checkFunctionAndClassExpressionBodies((node).expression); break;