Skip to content

Commit cdc999a

Browse files
author
Yui T
committed
Only check if method declaration has modifier when method is declared in object literal expression
1 parent 9344bd0 commit cdc999a

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11444,9 +11444,10 @@ namespace ts {
1144411444
forEach(node.declarationList.declarations, checkSourceElement);
1144511445
}
1144611446

11447-
function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node: Node) {
11447+
function checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node: Node) {
1144811448
if (node.modifiers) {
11449-
if (inObjectLiteralExpression(node)) {
11449+
if (node.parent.kind === SyntaxKind.ObjectLiteralExpression){
11450+
// If this method declaration is a property of object-literal-expression
1145011451
if (isAsyncFunctionLike(node)) {
1145111452
if (node.modifiers.length > 1) {
1145211453
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
@@ -11459,18 +11460,6 @@ namespace ts {
1145911460
}
1146011461
}
1146111462

11462-
function inObjectLiteralExpression(node: Node) {
11463-
while (node) {
11464-
if (node.kind === SyntaxKind.ObjectLiteralExpression) {
11465-
return true;
11466-
}
11467-
11468-
node = node.parent;
11469-
}
11470-
11471-
return false;
11472-
}
11473-
1147411463
function checkExpressionStatement(node: ExpressionStatement) {
1147511464
// Grammar checking
1147611465
checkGrammarStatementInAmbientContext(node);
@@ -15026,7 +15015,7 @@ namespace ts {
1502615015
}
1502715016

1502815017
function checkGrammarMethod(node: MethodDeclaration) {
15029-
if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) ||
15018+
if (checkGrammarDisallowedModifiersOnMethodInObjectLiteralExpression(node) ||
1503015019
checkGrammarFunctionLikeDeclaration(node) ||
1503115020
checkGrammarForGenerator(node)) {
1503215021
return true;

0 commit comments

Comments
 (0)