Parse classDeclaration in strict mode code for ES6

This commit is contained in:
Yui T
2015-03-12 15:19:45 -07:00
parent 56839604da
commit 0672923323
6 changed files with 128 additions and 2 deletions

View File

@@ -11891,7 +11891,11 @@ module ts {
var identifier = <Identifier>name;
if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) {
var nameText = declarationNameToString(identifier);
return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText);
// Always report 'eval' and 'arguments' invalid usage in strict mode code regardless of parser diagnostics
var sourceFile = getSourceFileOfNode(identifier);
diagnostics.add(createDiagnosticForNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText));
return true;
}
}
}

View File

@@ -4372,6 +4372,12 @@ module ts {
function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement {
var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
// From ES6 Specification, "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are reserved words within strict mode code
if (inStrictModeContext() && (token > SyntaxKind.LastReservedWord)) {
parseErrorAtCurrentToken(Diagnostics.Invalid_use_of_0_in_strict_mode, tokenToString(token));
}
var name = parsePropertyName();
// Note: this is not legal as per the grammar. But we allow it in the parser and
@@ -4517,6 +4523,12 @@ module ts {
}
function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration {
// In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code
if (languageVersion >= ScriptTarget.ES6) {
var savedStrictModeContext = inStrictModeContext();
setStrictModeContext(true);
}
var node = <ClassDeclaration>createNode(SyntaxKind.ClassDeclaration, fullStart);
setModifiers(node, modifiers);
parseExpected(SyntaxKind.ClassKeyword);
@@ -4537,7 +4549,15 @@ module ts {
else {
node.members = createMissingList<ClassElement>();
}
return finishNode(node);
var finishedNode = finishNode(node);
if (languageVersion >= ScriptTarget.ES6) {
setStrictModeContext(savedStrictModeContext);
return finishedNode;
}
else {
return finishedNode;
}
}
function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray<HeritageClause> {