| ... | ... | @@ -1505,11 +1505,11 @@ pub const Parser = struct { |
| 1505 | 1505 | if (try self.expectCommaOrEnd(Token.Id.RBrace)) |end| { |
| 1506 | 1506 | container_decl.rbrace_token = end; |
| 1507 | 1507 | continue; |
| 1508 | | } else { |
| 1509 | | try self.lookForSameLineComment(arena, container_decl.fields_and_decls.toSlice()[container_decl.fields_and_decls.len - 1]); |
| 1510 | | try stack.append(State { .ContainerDecl = container_decl }); |
| 1511 | | continue; |
| 1512 | 1508 | } |
| 1509 | |
| 1510 | try self.lookForSameLineComment(arena, container_decl.fields_and_decls.toSlice()[container_decl.fields_and_decls.len - 1]); |
| 1511 | try stack.append(State { .ContainerDecl = container_decl }); |
| 1512 | continue; |
| 1513 | 1513 | }, |
| 1514 | 1514 | State.IdentifierListItemOrEnd => |list_state| { |
| 1515 | 1515 | if (self.eatToken(Token.Id.RBrace)) |rbrace| { |
| ... | ... | @@ -1536,30 +1536,36 @@ pub const Parser = struct { |
| 1536 | 1536 | continue; |
| 1537 | 1537 | } |
| 1538 | 1538 | |
| 1539 | | const node = try self.createNode(arena, ast.Node.SwitchCase, |
| 1540 | | ast.Node.SwitchCase { |
| 1541 | | .base = undefined, |
| 1542 | | .items = ArrayList(&ast.Node).init(arena), |
| 1543 | | .payload = null, |
| 1544 | | .expr = undefined, |
| 1545 | | } |
| 1546 | | ); |
| 1539 | const node = try arena.construct(ast.Node.SwitchCase { |
| 1540 | .base = ast.Node { |
| 1541 | .id = ast.Node.Id.SwitchCase, |
| 1542 | .before_comments = null, |
| 1543 | .same_line_comment = null, |
| 1544 | }, |
| 1545 | .items = ArrayList(&ast.Node).init(arena), |
| 1546 | .payload = null, |
| 1547 | .expr = undefined, |
| 1548 | }); |
| 1547 | 1549 | try list_state.list.append(node); |
| 1548 | | stack.append(State { .SwitchCaseCommaOrEnd = list_state }) catch unreachable; |
| 1550 | try stack.append(State { .SwitchCaseCommaOrEnd = list_state }); |
| 1549 | 1551 | try stack.append(State { .AssignmentExpressionBegin = OptionalCtx { .Required = &node.expr } }); |
| 1550 | 1552 | try stack.append(State { .PointerPayload = OptionalCtx { .Optional = &node.payload } }); |
| 1551 | 1553 | try stack.append(State { .SwitchCaseFirstItem = &node.items }); |
| 1552 | 1554 | continue; |
| 1553 | 1555 | }, |
| 1556 | |
| 1554 | 1557 | State.SwitchCaseCommaOrEnd => |list_state| { |
| 1555 | 1558 | if (try self.expectCommaOrEnd(Token.Id.RBrace)) |end| { |
| 1556 | 1559 | *list_state.ptr = end; |
| 1557 | 1560 | continue; |
| 1558 | | } else { |
| 1559 | | stack.append(State { .SwitchCaseOrEnd = list_state }) catch unreachable; |
| 1560 | | continue; |
| 1561 | 1561 | } |
| 1562 | |
| 1563 | const switch_case = list_state.list.toSlice()[list_state.list.len - 1]; |
| 1564 | try self.lookForSameLineComment(arena, &switch_case.base); |
| 1565 | try stack.append(State { .SwitchCaseOrEnd = list_state }); |
| 1566 | continue; |
| 1562 | 1567 | }, |
| 1568 | |
| 1563 | 1569 | State.SwitchCaseFirstItem => |case_items| { |
| 1564 | 1570 | const token = self.getNextToken(); |
| 1565 | 1571 | if (token.id == Token.Id.Keyword_else) { |
| ... | ... | @@ -4095,7 +4101,6 @@ pub const Parser = struct { |
| 4095 | 4101 | while (i != 0) { |
| 4096 | 4102 | i -= 1; |
| 4097 | 4103 | const node = cases[i]; |
| 4098 | | try stack.append(RenderState { .Text = ","}); |
| 4099 | 4104 | try stack.append(RenderState { .Expression = &node.base}); |
| 4100 | 4105 | try stack.append(RenderState.PrintIndent); |
| 4101 | 4106 | try stack.append(RenderState { |
| ... | ... | @@ -4118,6 +4123,8 @@ pub const Parser = struct { |
| 4118 | 4123 | ast.Node.Id.SwitchCase => { |
| 4119 | 4124 | const switch_case = @fieldParentPtr(ast.Node.SwitchCase, "base", base); |
| 4120 | 4125 | |
| 4126 | try stack.append(RenderState { .PrintSameLineComment = switch_case.base.same_line_comment }); |
| 4127 | try stack.append(RenderState { .Text = "," }); |
| 4121 | 4128 | try stack.append(RenderState { .Expression = switch_case.expr }); |
| 4122 | 4129 | if (switch_case.payload) |payload| { |
| 4123 | 4130 | try stack.append(RenderState { .Text = " " }); |