Skip to content

Commit d328131

Browse files
committed
Merge pull request #63 from eslint/issue54
Fix: Allow let/const in switchcase (fixes #54)
2 parents bfe3db4 + 457de85 commit d328131

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

espree.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ function parseSwitchCase() {
39973997
if (match("}") || matchKeyword("default") || matchKeyword("case")) {
39983998
break;
39993999
}
4000-
statement = parseStatement();
4000+
statement = parseSourceElement();
40014001
consequent.push(statement);
40024002
}
40034003

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
module.exports = {
2+
"type": "Program",
3+
"body": [
4+
{
5+
type: 'SwitchStatement',
6+
discriminant: {
7+
type: 'Identifier',
8+
name: 'answer',
9+
range: [8, 14],
10+
loc: {
11+
start: { line: 1, column: 8 },
12+
end: { line: 1, column: 14 }
13+
}
14+
},
15+
cases: [{
16+
type: 'SwitchCase',
17+
test: {
18+
type: 'Literal',
19+
value: 42,
20+
raw: '42',
21+
range: [23, 25],
22+
loc: {
23+
start: { line: 1, column: 23 },
24+
end: { line: 1, column: 25 }
25+
}
26+
},
27+
consequent: [{
28+
type: 'VariableDeclaration',
29+
declarations: [{
30+
type: 'VariableDeclarator',
31+
id: {
32+
type: 'Identifier',
33+
name: 't',
34+
range: [31, 32],
35+
loc: {
36+
start: { line: 1, column: 31 },
37+
end: { line: 1, column: 32 }
38+
}
39+
},
40+
init: {
41+
type: 'Literal',
42+
value: 42,
43+
raw: '42',
44+
range: [35, 37],
45+
loc: {
46+
start: { line: 1, column: 35 },
47+
end: { line: 1, column: 37 }
48+
}
49+
},
50+
range: [31, 37],
51+
loc: {
52+
start: { line: 1, column: 31 },
53+
end: { line: 1, column: 37 }
54+
}
55+
}],
56+
kind: 'let',
57+
range: [27, 38],
58+
loc: {
59+
start: { line: 1, column: 27 },
60+
end: { line: 1, column: 38 }
61+
}
62+
}, {
63+
type: 'BreakStatement',
64+
label: null,
65+
range: [39, 45],
66+
loc: {
67+
start: { line: 1, column: 39 },
68+
end: { line: 1, column: 45 }
69+
}
70+
}],
71+
range: [18, 45],
72+
loc: {
73+
start: { line: 1, column: 18 },
74+
end: { line: 1, column: 45 }
75+
}
76+
}],
77+
range: [0, 47],
78+
loc: {
79+
start: { line: 1, column: 0 },
80+
end: { line: 1, column: 47 }
81+
}
82+
}
83+
],
84+
"range": [
85+
0,
86+
47
87+
],
88+
"loc": {
89+
"start": {
90+
"line": 1,
91+
"column": 0
92+
},
93+
"end": {
94+
"line": 1,
95+
"column": 47
96+
}
97+
}
98+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
switch (answer) { case 42: let t = 42; break; }

0 commit comments

Comments
 (0)