Only check if method declaration has modifier when method is declared in object literal expression

This commit is contained in:
Yui T
2015-07-07 16:26:48 -07:00
parent 9344bd0a39
commit cdc999a6c5

View File

@@ -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;