allow let and const declarations in module bodies under labels

This commit is contained in:
Mohamed Hegazy
2014-10-20 15:31:33 -07:00
parent 91f40988f1
commit d5fe43b53e
4 changed files with 29 additions and 22 deletions

View File

@@ -3916,14 +3916,14 @@ module ts {
}
function parseSourceElement() {
return parseSourceElementOrModuleElement(ModifierContext.SourceElements);
return parseSourceElementOrModuleElement(ModifierContext.SourceElements, /*allowLetAndConstDeclarations*/ false);
}
function parseModuleElement() {
return parseSourceElementOrModuleElement(ModifierContext.ModuleElements);
return parseSourceElementOrModuleElement(ModifierContext.ModuleElements, /*allowLetAndConstDeclarations*/ true);
}
function parseSourceElementOrModuleElement(modifierContext: ModifierContext): Statement {
function parseSourceElementOrModuleElement(modifierContext: ModifierContext, allowLetAndConstDeclarations: boolean): Statement {
if (isDeclaration()) {
return parseDeclaration(modifierContext);
}
@@ -3931,7 +3931,7 @@ module ts {
var statementStart = scanner.getTokenPos();
var statementFirstTokenLength = scanner.getTextPos() - statementStart;
var errorCountBeforeStatement = file.syntacticErrors.length;
var statement = parseStatement(/*allowLetAndConstDeclarations*/ false);
var statement = parseStatement(allowLetAndConstDeclarations);
if (inAmbientContext && file.syntacticErrors.length === errorCountBeforeStatement) {
grammarErrorAtPos(statementStart, statementFirstTokenLength, Diagnostics.Statements_are_not_allowed_in_ambient_contexts);