mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 01:33:15 -05:00
Parse classDeclaration in strict mode code for ES6
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user