Skip to content

Commit

Permalink
Support for ES6 lexical declaration in switch statement.
Browse files Browse the repository at this point in the history
Refs #1065.
Closes #1070.
  • Loading branch information
ariya committed Feb 20, 2015
1 parent 167c689 commit 74bfd2c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
2 changes: 1 addition & 1 deletion esprima.js
Expand Up @@ -3471,7 +3471,7 @@
if (match('}') || matchKeyword('default') || matchKeyword('case')) {
break;
}
statement = parseStatement();
statement = parseSourceElement();
consequent.push(statement);
}

Expand Down
84 changes: 84 additions & 0 deletions test/test.js
Expand Up @@ -19070,6 +19070,90 @@ var testFixture = {

},

'[ES6] Lexical Declaration': {

'switch (answer) { case 42: let t = 42; break; }': {
type: 'SwitchStatement',
discriminant: {
type: 'Identifier',
name: 'answer',
range: [8, 14],
loc: {
start: { line: 1, column: 8 },
end: { line: 1, column: 14 }
}
},
cases: [{
type: 'SwitchCase',
test: {
type: 'Literal',
value: 42,
raw: '42',
range: [23, 25],
loc: {
start: { line: 1, column: 23 },
end: { line: 1, column: 25 }
}
},
consequent: [{
type: 'VariableDeclaration',
declarations: [{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: 't',
range: [31, 32],
loc: {
start: { line: 1, column: 31 },
end: { line: 1, column: 32 }
}
},
init: {
type: 'Literal',
value: 42,
raw: '42',
range: [35, 37],
loc: {
start: { line: 1, column: 35 },
end: { line: 1, column: 37 }
}
},
range: [31, 37],
loc: {
start: { line: 1, column: 31 },
end: { line: 1, column: 37 }
}
}],
kind: 'let',
range: [27, 38],
loc: {
start: { line: 1, column: 27 },
end: { line: 1, column: 38 }
}
}, {
type: 'BreakStatement',
label: null,
range: [39, 45],
loc: {
start: { line: 1, column: 39 },
end: { line: 1, column: 45 }
}
}],
range: [18, 45],
loc: {
start: { line: 1, column: 18 },
end: { line: 1, column: 45 }
}
}],
range: [0, 47],
loc: {
start: { line: 1, column: 0 },
end: { line: 1, column: 47 }
}
}

},

'Empty Statement': {

';': {
Expand Down

0 comments on commit 74bfd2c

Please sign in to comment.