Ensure let and const declarations in labels are parsed correctelly

This commit is contained in:
Mohamed Hegazy
2014-10-24 10:14:36 -07:00
parent d1858d0625
commit e4a20849bb
4 changed files with 81 additions and 4 deletions

View File

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

View File

@@ -126,4 +126,24 @@ tests/cases/compiler/letDeclarations-validContexts.ts(20,7): error TS2410: All s
f2: () => {
let l29 = 0;
}
}
// labels
label: let l30 = 0;
{
label2: let l31 = 0;
}
function f3() {
label: let l32 = 0;
{
label2: let l33 = 0;
}
}
module m3 {
label: let l34 = 0;
{
label2: let l35 = 0;
}
}

View File

@@ -121,6 +121,26 @@ var o = {
f2: () => {
let l29 = 0;
}
}
// labels
label: let l30 = 0;
{
label2: let l31 = 0;
}
function f3() {
label: let l32 = 0;
{
label2: let l33 = 0;
}
}
module m3 {
label: let l34 = 0;
{
label2: let l35 = 0;
}
}
//// [letDeclarations-validContexts.js]
@@ -227,3 +247,20 @@ var o = {
let l29 = 0;
}
};
label: let l30 = 0;
{
label2: let l31 = 0;
}
function f3() {
label: let l32 = 0;
{
label2: let l33 = 0;
}
}
var m3;
(function (m3) {
label: let l34 = 0;
{
label2: let l35 = 0;
}
})(m3 || (m3 = {}));

View File

@@ -121,4 +121,24 @@ var o = {
f2: () => {
let l29 = 0;
}
}
// labels
label: let l30 = 0;
{
label2: let l31 = 0;
}
function f3() {
label: let l32 = 0;
{
label2: let l33 = 0;
}
}
module m3 {
label: let l34 = 0;
{
label2: let l35 = 0;
}
}