fix(compiler): preserve native boolean semantics in page branches
This commit is contained in:
1 parent
681679483a
commit
25a421c727
4 files changed
+38
-2
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { parse, generate } from "../src/index.ts";
|
||||
|
||||
test("native boolean attributes inside conditional and loop bodies use presence semantics", async () => {
|
||||
const source = `page Example {
|
||||
load server account { return {} }
|
||||
view {
|
||||
{#if account.visible}<input required disabled="{!account.edit}" />{/if}
|
||||
{#each account.rows as row}<input type="checkbox" checked="{row.checked}" disabled="false" />{/each}
|
||||
}
|
||||
}`;
|
||||
const code = new Bun.Transpiler({ loader: "ts" }).transformSync(generate(parse(source)));
|
||||
const mod = await import("data:text/javascript;base64," + Buffer.from(code).toString("base64"));
|
||||
const html = await mod.default({
|
||||
account: { visible: true, edit: true, rows: [{ checked: false }, { checked: true }] },
|
||||
});
|
||||
expect(html).not.toContain("disabled");
|
||||
expect(html).not.toContain('checked="false"');
|
||||
expect(html.match(/ checked/g)).toHaveLength(1);
|
||||
expect(html).toContain("required");
|
||||
const denied = await mod.default({ account: { visible: true, edit: false, rows: [] } });
|
||||
expect(denied).toContain(" disabled");
|
||||
});
|
||||
Reference in new issue
Block a user