| ... | ... | @@ -3730,6 +3730,16 @@ pub const Parser = struct { |
| 3730 | 3730 | try stack.append(RenderState { .Expression = suffix_op.lhs }); |
| 3731 | 3731 | continue; |
| 3732 | 3732 | } |
| 3733 | if (exprs.len == 1) { |
| 3734 | const expr = exprs.at(0); |
| 3735 | |
| 3736 | try stack.append(RenderState { .Text = "}" }); |
| 3737 | try stack.append(RenderState { .Expression = expr }); |
| 3738 | try stack.append(RenderState { .Text = " {" }); |
| 3739 | try stack.append(RenderState { .Expression = suffix_op.lhs }); |
| 3740 | continue; |
| 3741 | } |
| 3742 | |
| 3733 | 3743 | try stack.append(RenderState { .Text = "}"}); |
| 3734 | 3744 | try stack.append(RenderState.PrintIndent); |
| 3735 | 3745 | try stack.append(RenderState { .Indent = indent }); |
| ... | ... | @@ -4513,6 +4523,13 @@ fn testCanonical(source: []const u8) !void { |
| 4513 | 4523 | } |
| 4514 | 4524 | } |
| 4515 | 4525 | |
| 4526 | test "zig fmt: array literal with 1 item on 1 line" { |
| 4527 | try testCanonical( |
| 4528 | \\var s = []const u64 {0} ** 25; |
| 4529 | \\ |
| 4530 | ); |
| 4531 | } |
| 4532 | |
| 4516 | 4533 | test "zig fmt: preserve same-line comment after a statement" { |
| 4517 | 4534 | try testCanonical( |
| 4518 | 4535 | \\test "" { |