From b34a453cd4b4ec063f35ba7b9d3faea82d94d54e Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 11 Dec 2014 14:35:55 -0800 Subject: [PATCH] Move grammar checking: bindingElement --- src/compiler/checker.ts | 16 +++++++++++++++- src/compiler/parser.ts | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1fe11dc638..1cff181c76c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -7895,6 +7895,12 @@ module ts { // Check variable, parameter, or property declaration function checkVariableLikeDeclaration(node: VariableLikeDeclaration) { + // Grammar checking + // TODO (yuisu) : Revisit this check once move all grammar checking + if (node.kind === SyntaxKind.BindingElement) { + checkGrammarBindingElement(node); + } + checkSourceElement(node.type); // For a computed property, just check the initializer and exit if (hasComputedNameButNotSymbol(node)) { @@ -9761,7 +9767,7 @@ module ts { break; case SyntaxKind.DeclareKeyword: - // TODO (yuisu) : Bring back the parser grammar checking + // TODO (yuisu) : Revisit this once moving ambient Context into type checking break; } } @@ -9925,6 +9931,14 @@ module ts { checkGrammarForOmittedArgument(node, arguments); } + function checkGrammarBindingElement(node: BindingElement) { + if (!checkGrammarModifiers(node) && (node.parserContextFlags & ParserContextFlags.StrictMode && isEvalOrArgumentsIdentifier(node.name))) { + // It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code + // and its Identifier is eval or arguments + reportGrammarErrorOfInvalidUseInStrictMode(node.name); + } + } + function hasParseDiagnostics(sourceFile: SourceFile): boolean { return sourceFile.parseDiagnostics.length > 0; } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index c1ebc5abd4e..5d3ac16d7ab 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4635,7 +4635,7 @@ module ts { case SyntaxKind.EnumDeclaration: return checkEnumDeclaration(node); //case SyntaxKind.BinaryExpression: return checkBinaryExpression(node); - case SyntaxKind.BindingElement: return checkBindingElement(node); + //case SyntaxKind.BindingElement: return checkBindingElement(node); case SyntaxKind.CatchClause: return checkCatchClause(node); case SyntaxKind.ClassDeclaration: return checkClassDeclaration(node); case SyntaxKind.ComputedPropertyName: return checkComputedPropertyName(node);