@sigil-dev/compiler 0.9.10 → 0.9.12
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/package.json +3 -1
- package/src/babel/handlers/dom/state.ts +4 -5
- package/src/babel/index.ts +75 -26
- package/src/babel/jsx/children.ts +10 -2
- package/src/babel/jsx/element.ts +205 -110
- package/src/babel/jsx/fragment.ts +15 -3
- package/src/babel/jsx/keyed-list.ts +10 -2
- package/src/babel/jsx/ssr.ts +136 -253
- package/src/babel/jsx/utils.ts +47 -1
- package/src/babel/util/bind.ts +4 -0
- package/src/babel/util/css.ts +170 -113
- package/src/babel/util/props.ts +256 -0
- package/src/bun-plugin.ts +28 -17
- package/src/vite/index.ts +4 -1
- package/test/bun-plugin.test.ts +45 -0
- package/test/hydration.test.ts +3 -2
- package/test/jsx.test.ts +26 -4
- package/test/render-parity.test.ts +639 -0
- package/test/scoped-css.test.ts +39 -2
- package/test/ssr.test.ts +1 -1
- package/test/style-object.test.ts +29 -6
package/test/scoped-css.test.ts
CHANGED
|
@@ -28,6 +28,42 @@ describe("Scoped CSS", () => {
|
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
describe("scopeCSS", () => {
|
|
31
|
+
test("several rules keep their own selectors (no text carried over)", () => {
|
|
32
|
+
const css = `.book {\n\tdisplay: flex;\n}\n.read .title {\n\ttext-decoration: line-through;\n}\n.author { color: #666; }`;
|
|
33
|
+
expect(scopeCSS(css, "h1")).toBe(
|
|
34
|
+
`.book.h1 {\n\tdisplay: flex;\n}\n.read .title.h1 {\n\ttext-decoration: line-through;\n}\n.author.h1 { color: #666; }`,
|
|
35
|
+
);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("pseudo-classes, combinators and :is() lists", () => {
|
|
39
|
+
expect(scopeCSS(".b:hover, .c > .d { x: 1 }", "h1")).toBe(
|
|
40
|
+
".b.h1:hover, .c > .d.h1 { x: 1 }",
|
|
41
|
+
);
|
|
42
|
+
expect(scopeCSS(":is(.a, .b) .c { x: 1 }", "h1")).toBe(
|
|
43
|
+
":is(.a, .b) .c.h1 { x: 1 }",
|
|
44
|
+
);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("@media is scoped inside; @keyframes and @import pass through", () => {
|
|
48
|
+
expect(
|
|
49
|
+
scopeCSS(
|
|
50
|
+
"@media (max-width: 600px) { .a { x: 1 } } @keyframes spin { from { a: 1 } } @import url(x.css);",
|
|
51
|
+
"h1",
|
|
52
|
+
),
|
|
53
|
+
).toBe(
|
|
54
|
+
"@media (max-width: 600px) { .a.h1 { x: 1 } } @keyframes spin { from { a: 1 } } @import url(x.css);",
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test(":global() anywhere in a selector", () => {
|
|
59
|
+
expect(scopeCSS(":global(.map) .pin { a: 1 }", "h1")).toBe(
|
|
60
|
+
".map .pin.h1 { a: 1 }",
|
|
61
|
+
);
|
|
62
|
+
expect(scopeCSS(".x :global(.y) { a: 1 }", "h1")).toBe(
|
|
63
|
+
".x.h1 .y { a: 1 }",
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
|
|
31
67
|
test("appends hash to simple selector", () => {
|
|
32
68
|
const result = scopeCSS(".card { color: red; }", "abc12345");
|
|
33
69
|
expect(result).toContain(".card.abc12345");
|
|
@@ -73,7 +109,8 @@ describe("Scoped CSS", () => {
|
|
|
73
109
|
'.card::before { content: ".card"; }',
|
|
74
110
|
"abc12345",
|
|
75
111
|
);
|
|
76
|
-
|
|
112
|
+
// the class goes before the pseudo-element; after it is invalid CSS
|
|
113
|
+
expect(result).toContain(".card.abc12345::before");
|
|
77
114
|
expect(result).toContain('".card"'); // String literal preserved
|
|
78
115
|
});
|
|
79
116
|
});
|
|
@@ -104,7 +141,7 @@ describe("Scoped CSS", () => {
|
|
|
104
141
|
test("classList.add after createElement and attributes", () => {
|
|
105
142
|
const result = transform(`<div class="foo" />`, "abc12345");
|
|
106
143
|
// setProp(el, "className", "foo") should come before classList.add
|
|
107
|
-
const classNameIdx = result.indexOf(
|
|
144
|
+
const classNameIdx = result.indexOf("setProp(");
|
|
108
145
|
const classListIdx = result.indexOf('classList.add("abc12345")');
|
|
109
146
|
expect(classNameIdx).toBeGreaterThan(0);
|
|
110
147
|
expect(classListIdx).toBeGreaterThan(classNameIdx);
|
package/test/ssr.test.ts
CHANGED
|
@@ -43,7 +43,7 @@ describe("SSR", () => {
|
|
|
43
43
|
test("static element with class", () => {
|
|
44
44
|
const result = transformSSR(`const el = <div class="app" />;`);
|
|
45
45
|
expect(result).toContain('class="app"');
|
|
46
|
-
expect(result).not.toContain(
|
|
46
|
+
expect(result).not.toContain('className="');
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
test("void element self closes", () => {
|
|
@@ -1,13 +1,36 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
import { transformSSR } from "./helpers/transform.ts";
|
|
3
3
|
|
|
4
|
+
function render(src: string): string {
|
|
5
|
+
const body = transformSSR(src).replace(/^export\s+/gm, "");
|
|
6
|
+
return String(new Function(`${body};\nreturn Card();`)());
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
describe("SSR style objects", () => {
|
|
5
|
-
test("style={{...}} serializes to CSS
|
|
6
|
-
|
|
7
|
-
|
|
10
|
+
test("style={{...}} serializes to CSS text, numbers in px", () => {
|
|
11
|
+
expect(
|
|
12
|
+
render(
|
|
13
|
+
`export function Card() { return <div style={{ display: "grid", marginTop: 12 }}>x</div>; }`,
|
|
14
|
+
),
|
|
15
|
+
).toBe(`<div style="display:grid;margin-top:12px">x</div>`);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("unitless properties, custom properties and empty values", () => {
|
|
19
|
+
expect(
|
|
20
|
+
render(
|
|
21
|
+
`const s = { opacity: 0.5, zIndex: 3, "--gap": 4, color: null, lineHeight: 1.2, padding: 0 };
|
|
22
|
+
export function Card() { return <div style={s} />; }`,
|
|
23
|
+
),
|
|
24
|
+
).toBe(
|
|
25
|
+
`<div style="opacity:0.5;z-index:3;--gap:4;line-height:1.2;padding:0"></div>`,
|
|
8
26
|
);
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test("values are attribute-escaped", () => {
|
|
30
|
+
expect(
|
|
31
|
+
render(
|
|
32
|
+
`const bg = 'url("a.png")'; export function Card() { return <div style={{ background: bg }} />; }`,
|
|
33
|
+
),
|
|
34
|
+
).toBe(`<div style="background:url("a.png")"></div>`);
|
|
12
35
|
});
|
|
13
36
|
});
|