From cdc999a6c51e819e7962f5acfd0c2bbf73f2814e Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 7 Jul 2015 16:26:48 -0700 Subject: [PATCH] Only check if method declaration has modifier when method is declared in object literal expression --- src/compiler/checker.ts | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7083feabb2c..f4bbc71793e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11444,9 +11444,10 @@ namespace ts { forEach(node.declarationList.declarations, checkSourceElement); } - function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node: Node) { + function checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node: Node) { if (node.modifiers) { - if (inObjectLiteralExpression(node)) { + if (node.parent.kind === SyntaxKind.ObjectLiteralExpression){ + // If this method declaration is a property of object-literal-expression if (isAsyncFunctionLike(node)) { if (node.modifiers.length > 1) { return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); @@ -11459,18 +11460,6 @@ namespace ts { } } - function inObjectLiteralExpression(node: Node) { - while (node) { - if (node.kind === SyntaxKind.ObjectLiteralExpression) { - return true; - } - - node = node.parent; - } - - return false; - } - function checkExpressionStatement(node: ExpressionStatement) { // Grammar checking checkGrammarStatementInAmbientContext(node); @@ -15026,7 +15015,7 @@ namespace ts { } function checkGrammarMethod(node: MethodDeclaration) { - if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || + if (checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node) || checkGrammarFunctionLikeDeclaration(node) || checkGrammarForGenerator(node)) { return true;