mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Validate that only module level declarations have modifiers
This commit is contained in:
+16
-8
@@ -8968,7 +8968,6 @@ module ts {
|
||||
function checkFunctionDeclaration(node: FunctionDeclaration): void {
|
||||
if (produceDiagnostics) {
|
||||
checkFunctionLikeDeclaration(node) ||
|
||||
checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) ||
|
||||
checkGrammarFunctionName(node.name) ||
|
||||
checkGrammarForGenerator(node);
|
||||
|
||||
@@ -9330,7 +9329,7 @@ module ts {
|
||||
|
||||
function checkVariableStatement(node: VariableStatement) {
|
||||
// Grammar checking
|
||||
checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
|
||||
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node);
|
||||
|
||||
forEach(node.declarationList.declarations, checkSourceElement);
|
||||
}
|
||||
@@ -12247,19 +12246,28 @@ module ts {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.VariableStatement:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ExportDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
case SyntaxKind.Parameter:
|
||||
break;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.VariableStatement:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
if (node.modifiers && node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== SyntaxKind.ConstKeyword) &&
|
||||
node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) {
|
||||
return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user