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);

View file

@ -105,12 +105,12 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols
var F2 = () => {
let l = 0;
n = l;
n = l;
};
var F3 = function () {
let l = 0;
n = l;
n = l;
};
// modules
@ -120,8 +120,10 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols
{
let l = false;
var b2: boolean = l;
var b2: boolean = l;
}
lable: let l2 = 0;
}
// methods
@ -152,10 +154,10 @@ tests/cases/compiler/letDeclarations-scopes.ts(28,7): error TS2410: All symbols
var o = {
f() {
let l = 0;
n = l;
n = l;
},
f2: () => {
f2: () => {
let l = 0;
n = l;
n = l;
}
}

View file

@ -100,12 +100,12 @@ function F() {
var F2 = () => {
let l = 0;
n = l;
n = l;
};
var F3 = function () {
let l = 0;
n = l;
n = l;
};
// modules
@ -115,8 +115,10 @@ module m {
{
let l = false;
var b2: boolean = l;
var b2: boolean = l;
}
lable: let l2 = 0;
}
// methods
@ -147,11 +149,11 @@ class C {
var o = {
f() {
let l = 0;
n = l;
n = l;
},
f2: () => {
f2: () => {
let l = 0;
n = l;
n = l;
}
}
@ -251,6 +253,7 @@ var m;
let l = false;
var b2 = l;
}
lable: let l2 = 0;
})(m || (m = {}));
// methods
var C = (function () {

View file

@ -100,12 +100,12 @@ function F() {
var F2 = () => {
let l = 0;
n = l;
n = l;
};
var F3 = function () {
let l = 0;
n = l;
n = l;
};
// modules
@ -115,8 +115,10 @@ module m {
{
let l = false;
var b2: boolean = l;
var b2: boolean = l;
}
lable: let l2 = 0;
}
// methods
@ -147,10 +149,10 @@ class C {
var o = {
f() {
let l = 0;
n = l;
n = l;
},
f2: () => {
f2: () => {
let l = 0;
n = l;
n = l;
}
}