Commit 1b8eca030e

Isaac Freund <ifreund@ifreund.xyz>
2021-02-24 12:14:15
zig fmt: fix firstToken() for switch_case
1 parent db4c15b
Changed files (2)
lib/std/zig/ast.zig
@@ -580,7 +580,7 @@ pub const Tree = struct {
             .switch_case => {
                 const extra = tree.extraData(datas[n].lhs, Node.SubRange);
                 assert(extra.end - extra.start > 0);
-                n = extra.start;
+                n = tree.extra_data[extra.start];
             },
 
             .asm_output, .asm_input => {
lib/std/zig/parser_test.zig
@@ -4189,19 +4189,18 @@ test "zig fmt: respect extra newline between fn and pub usingnamespace" {
     );
 }
 
-// TODO
-//test "zig fmt: respect extra newline between switch items" {
-//    try testCanonical(
-//        \\const a = switch (b) {
-//        \\    .c => {},
-//        \\
-//        \\    .d,
-//        \\    .e,
-//        \\    => f,
-//        \\};
-//        \\
-//    );
-//}
+test "zig fmt: respect extra newline between switch items" {
+    try testCanonical(
+        \\const a = switch (b) {
+        \\    .c => {},
+        \\
+        \\    .d,
+        \\    .e,
+        \\    => f,
+        \\};
+        \\
+    );
+}
 
 test "zig fmt: error for invalid bit range" {
     try testError(