File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
src/com/google/javascript/jscomp
test/com/google/javascript/jscomp Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -1483,7 +1483,7 @@ private void validateSwitch(Node n) {
1483
1483
validateExpression (n .getFirstChild ());
1484
1484
int defaults = 0 ;
1485
1485
for (Node c = n .getSecondChild (); c != null ; c = c .getNext ()) {
1486
- validateSwitchMember (n . getLastChild () );
1486
+ validateSwitchMember (c );
1487
1487
if (c .isDefaultCase ()) {
1488
1488
defaults ++;
1489
1489
}
Original file line number Diff line number Diff line change @@ -1265,6 +1265,35 @@ public void testUnresolvedTypesAreBanned() {
1265
1265
expectValid (expr , Check .STATEMENT );
1266
1266
}
1267
1267
1268
+ @ Test
1269
+ public void testSwitchStatement () {
1270
+ // Since we're building the AST by hand, there won't be any types on it.
1271
+ enableTypeInfoValidation = false ;
1272
+
1273
+ String switchStatement =
1274
+ lines (
1275
+ "function foo(x) {" ,
1276
+ " switch(x) {" ,
1277
+ " case 1: " ,
1278
+ " var y = 5;" ,
1279
+ " case 2: " ,
1280
+ " var y = 5;" ,
1281
+ " }" ,
1282
+ "}" );
1283
+
1284
+ valid (switchStatement );
1285
+
1286
+ Node rootScriptNode = parseValidScript (switchStatement );
1287
+ Node blockNode = IR .block ();
1288
+
1289
+ Node firstCaseNode =
1290
+ stream (NodeUtil .preOrderIterable (rootScriptNode )).filter (Node ::isCase ).findFirst ().get ();
1291
+
1292
+ firstCaseNode .addChildToFront (blockNode );
1293
+ // A CASE node is only allowed to have 2 children, 1 expression and 1 block.
1294
+ expectInvalid (rootScriptNode , Check .SCRIPT );
1295
+ }
1296
+
1268
1297
private void valid (String code ) {
1269
1298
testSame (code );
1270
1299
assertThat (lastCheckWasValid ).isTrue ();
You can’t perform that action at this time.
0 commit comments