mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Merge pull request #3772 from Microsoft/allowModifier
Allow modifier on class member for classDeclaration/classExpression inside function
This commit is contained in:
@@ -11448,31 +11448,18 @@ namespace ts {
|
||||
forEach(node.declarationList.declarations, checkSourceElement);
|
||||
}
|
||||
|
||||
function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node: Node) {
|
||||
if (node.modifiers) {
|
||||
if (inBlockOrObjectLiteralExpression(node)) {
|
||||
if (isAsyncFunctionLike(node)) {
|
||||
if (node.modifiers.length > 1) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
}
|
||||
else {
|
||||
function checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node: Node) {
|
||||
// We only disallow modifier on a method declaration if it is a property of object-literal-expression
|
||||
if (node.modifiers && node.parent.kind === SyntaxKind.ObjectLiteralExpression){
|
||||
if (isAsyncFunctionLike(node)) {
|
||||
if (node.modifiers.length > 1) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function inBlockOrObjectLiteralExpression(node: Node) {
|
||||
while (node) {
|
||||
if (node.kind === SyntaxKind.Block || node.kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
return true;
|
||||
else {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkExpressionStatement(node: ExpressionStatement) {
|
||||
@@ -15030,7 +15017,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function checkGrammarMethod(node: MethodDeclaration) {
|
||||
if (checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) ||
|
||||
if (checkGrammarDisallowedModifiersOnObjectLiteralExpressionMethod(node) ||
|
||||
checkGrammarFunctionLikeDeclaration(node) ||
|
||||
checkGrammarForGenerator(node)) {
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user