File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -1519,8 +1519,15 @@ NonnullRefPtr<SwitchStatement> Parser::parse_switch_statement()
1519
1519
1520
1520
NonnullRefPtrVector<SwitchCase> cases;
1521
1521
1522
- while (match (TokenType::Case) || match (TokenType::Default))
1522
+ auto has_default = false ;
1523
+ while (match (TokenType::Case) || match (TokenType::Default)) {
1524
+ if (match (TokenType::Default)) {
1525
+ if (has_default)
1526
+ syntax_error (" Multiple 'default' clauses in switch statement" );
1527
+ has_default = true ;
1528
+ }
1523
1529
cases.append (parse_switch_case ());
1530
+ }
1524
1531
1525
1532
consume (TokenType::CurlyClose);
1526
1533
Original file line number Diff line number Diff line change @@ -68,3 +68,11 @@ describe("basic switch tests", () => {
68
68
expect ( i ) . toBe ( 5 ) ;
69
69
} ) ;
70
70
} ) ;
71
+
72
+ describe ( "errors" , ( ) => {
73
+ test ( "syntax errors" , ( ) => {
74
+ expect ( "switch () {}" ) . not . toEval ( ) ;
75
+ expect ( "switch (foo) { bar }" ) . not . toEval ( ) ;
76
+ expect ( "switch (foo) { default: default: }" ) . not . toEval ( ) ;
77
+ } ) ;
78
+ } ) ;
You can’t perform that action at this time.
0 commit comments