@sigil-dev/compiler 0.9.6 → 0.9.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +162 -162
- package/package.json +1 -1
- package/src/babel/index.ts +614 -608
- package/src/babel/jsx/anchor-mount.ts +408 -408
- package/src/babel/jsx/children.ts +108 -108
- package/src/babel/jsx/element.ts +863 -876
- package/src/babel/jsx/fragment.ts +259 -259
- package/src/babel/jsx/ssr.ts +45 -0
- package/test/hydration.test.ts +276 -276
- package/test/jsx.test.ts +10 -5
- package/test/scoped-css.test.ts +2 -2
- package/test/ssr-boolean-attrs.test.ts +56 -0
- package/test/style-object.test.ts +13 -13
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { transformSSR } from "./helpers/transform.ts";
|
|
6
|
+
|
|
7
|
+
// Render through the real SSR output: write the compiled module to disk and
|
|
8
|
+
// import it, so the assertions are on the HTML a browser would receive.
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), "sigil-ssr-bool-"));
|
|
10
|
+
let n = 0;
|
|
11
|
+
async function render(src: string, ...args: unknown[]): Promise<string> {
|
|
12
|
+
const file = join(dir, `m${n++}.js`);
|
|
13
|
+
writeFileSync(file, transformSSR(src));
|
|
14
|
+
const mod = await import(file);
|
|
15
|
+
return String(mod.default(...args));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("SSR boolean attributes", () => {
|
|
19
|
+
const box = `export default (on) => <input type="checkbox" checked={on} />;`;
|
|
20
|
+
|
|
21
|
+
test("true renders the bare attribute", async () => {
|
|
22
|
+
expect(await render(box, true)).toBe(`<input type="checkbox" checked>`);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("false, null and undefined omit it", async () => {
|
|
26
|
+
// checked="" would mean checked: every box ticked, every option selected
|
|
27
|
+
for (const v of [false, null, undefined]) {
|
|
28
|
+
expect(await render(box, v)).toBe(`<input type="checkbox">`);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("selected, disabled and friends follow the same rule", async () => {
|
|
33
|
+
const src = `export default (a, b) => <select disabled={a}><option selected={b}>x</option></select>;`;
|
|
34
|
+
expect(await render(src, false, true)).toBe(
|
|
35
|
+
`<select><option selected>x</option></select>`,
|
|
36
|
+
);
|
|
37
|
+
expect(await render(src, true, false)).toBe(
|
|
38
|
+
`<select disabled><option>x</option></select>`,
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("a string value is kept, escaped", async () => {
|
|
43
|
+
expect(
|
|
44
|
+
await render(`export default (v) => <div hidden={v} />;`, "until-found"),
|
|
45
|
+
).toBe(`<div hidden="until-found"></div>`);
|
|
46
|
+
expect(
|
|
47
|
+
await render(`export default (v) => <div hidden={v} />;`, `"><x`),
|
|
48
|
+
).toBe(`<div hidden=""><x"></div>`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test("literal attributes are untouched", async () => {
|
|
52
|
+
expect(
|
|
53
|
+
await render(`export default () => <input checked="checked" />;`),
|
|
54
|
+
).toBe(`<input checked="checked">`);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { transformSSR } from "./helpers/transform.ts";
|
|
3
|
-
|
|
4
|
-
describe("SSR style objects", () => {
|
|
5
|
-
test("style={{...}} serializes to CSS string, not [object Object]", () => {
|
|
6
|
-
const out = transformSSR(
|
|
7
|
-
`export function Card() { return <div style={{ display: "grid", marginTop: 12 }}>x</div>; }`,
|
|
8
|
-
);
|
|
9
|
-
// the __e helper must carry the object branch
|
|
10
|
-
expect(out).toContain("constructor === Object");
|
|
11
|
-
expect(out).toContain("UNITLESS");
|
|
12
|
-
});
|
|
13
|
-
});
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { transformSSR } from "./helpers/transform.ts";
|
|
3
|
+
|
|
4
|
+
describe("SSR style objects", () => {
|
|
5
|
+
test("style={{...}} serializes to CSS string, not [object Object]", () => {
|
|
6
|
+
const out = transformSSR(
|
|
7
|
+
`export function Card() { return <div style={{ display: "grid", marginTop: 12 }}>x</div>; }`,
|
|
8
|
+
);
|
|
9
|
+
// the __e helper must carry the object branch
|
|
10
|
+
expect(out).toContain("constructor === Object");
|
|
11
|
+
expect(out).toContain("UNITLESS");
|
|
12
|
+
});
|
|
13
|
+
});
|