allow let and const declarations in module bodies under labels
This commit is contained in:
parent
91f40988f1
commit
d5fe43b53e
4 changed files with 29 additions and 22 deletions
|
@ -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);
|
||||
|
|
|
@ -122,6 +122,8 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols
|
|||
let l = false;
|
||||
var b2: boolean = l;
|
||||
}
|
||||
|
||||
lable: let l2 = 0;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
|
|
@ -117,6 +117,8 @@ module m {
|
|||
let l = false;
|
||||
var b2: boolean = l;
|
||||
}
|
||||
|
||||
lable: let l2 = 0;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
@ -251,6 +253,7 @@ var m;
|
|||
let l = false;
|
||||
var b2 = l;
|
||||
}
|
||||
lable: let l2 = 0;
|
||||
})(m || (m = {}));
|
||||
// methods
|
||||
var C = (function () {
|
||||
|
|
|
@ -117,6 +117,8 @@ module m {
|
|||
let l = false;
|
||||
var b2: boolean = l;
|
||||
}
|
||||
|
||||
lable: let l2 = 0;
|
||||
}
|
||||
|
||||
// methods
|
||||
|
|
Loading…
Reference in a new issue