✓
Passing This code compiles and runs correctly.
Code
// NOTE: narrowed to Zig — print.ln of a bare variable WITH newline has no JS
// variant yet (print.ln is a Zig comptime transform; std/io:print has |js but no
// newline). print.ln cross-target JS for variable args is a tracked gap.
// JS continuation-branch dispatch: the JS emitter switches on the returned
// branch tag (as Zig does), firing only the matched branch — not all of them.
// n=4 → only the `even` branch fires; byte-identical on both targets. Minimal,
// no std/args dependency.
~import std/io
~event pick { n: i32 }
| even []const u8
| odd []const u8
~proc pick|zig {
if (@mod(n, 2) == 0) {
return .{ .even = "even" };
}
return .{ .odd = "odd" };
}
~proc pick|js {
if (n % 2 === 0) {
return { tag: "even", even: "even" };
}
return { tag: "odd", odd: "odd" };
}
~pick(n: 4)
| even e |> std/io:print.ln(e)
| odd o |> std/io:print.ln(o)
Actual
evenExpected output
✓ Zig✓ JavaScripteven
Emitted JavaScript source
const main_module = {
pick_event: {
handler(input) {
const n = input.n;
if (n % 2 === 0) {
return { tag: "even", even: "even" };
}
return { tag: "odd", odd: "odd" };
},
},
print_event: {
handler(input) {
const text = input.text;
process.stdout.write(text);
},
},
flow0() {
const result_0 = main_module.pick_event.handler({ n: 4 });
if (result_0.tag === "even") {
const e = result_0.even;
main_module.print_event.handler({ text: e });
}
if (result_0.tag === "odd") {
const o = result_0.odd;
main_module.print_event.handler({ text: o });
}
},
};
main_module.flow0();
Test Configuration
MUST_RUN