fix(fmt): fix nested switch indentation (#36)

This commit is contained in:
Mohabbat 2026-01-09 18:10:45 +06:00 committed by GitHub
parent 03c86fd5f5
commit d17dab9f6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 7 deletions

View File

@ -1626,7 +1626,13 @@ fn renderSwitchExpression(
ctx.indent_level -= 1;
try w.writeAll(std.mem.trim(u8, case.pattern, &std.ascii.whitespace));
try w.writeAll(" => ");
const is_nested_switch = NodeKind.fromNode(case.value) == .switch_expression;
// For nested switches, keep indent level elevated
if (is_nested_switch) ctx.indent_level += 1;
try renderCaseValue(self, case.value, w, ctx);
if (is_nested_switch) ctx.indent_level -= 1;
try w.writeAll(",");
}
@ -1975,7 +1981,13 @@ fn renderSwitchExpressionInner(
ctx.indent_level -= 1;
try w.writeAll(std.mem.trim(u8, case.pattern, &std.ascii.whitespace));
try w.writeAll(" => ");
const is_nested_switch = NodeKind.fromNode(case.value) == .switch_expression;
// For nested switches, keep indent level elevated
if (is_nested_switch) ctx.indent_level += 1;
try renderCaseValue(self, case.value, w, ctx);
if (is_nested_switch) ctx.indent_level -= 1;
try w.writeAll(",");
}

View File

@ -101,7 +101,7 @@ test "switch_for" {
try test_fmt("control_flow/switch_for");
}
test "switch_switch" {
if (true) return error.Todo;
// if (true) return error.Todo;
try test_fmt("control_flow/switch_switch");
}
test "switch_while" {

View File

@ -5,13 +5,13 @@ pub fn Page(allocator: zx.Allocator) zx.Component {
<main @allocator={allocator}>
{switch (user_type) {
.admin => switch (status) {
.active => (<p>Active Admin</p>),
.inactive => (<p>Inactive Admin</p>),
},
.active => (<p>Active Admin</p>),
.inactive => (<p>Inactive Admin</p>),
},
.member => switch (status) {
.active => (<p>Active Member</p>),
.inactive => (<p>Inactive Member</p>),
},
.active => (<p>Active Member</p>),
.inactive => (<p>Inactive Member</p>),
},
}}
</main>
);