mirror of
https://github.com/ziex-dev/ziex.git
synced 2026-07-22 11:39:34 -06:00
fix(fmt): fix nested switch indentation (#36)
This commit is contained in:
parent
03c86fd5f5
commit
d17dab9f6c
@ -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(",");
|
||||
}
|
||||
|
||||
|
||||
@ -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" {
|
||||
|
||||
@ -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>
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user