@sigil-dev/compiler 0.9.3 → 0.9.5

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.
Files changed (40) hide show
  1. package/index.ts +4 -4
  2. package/jsr.json +8 -8
  3. package/package.json +9 -8
  4. package/src/babel/handlers/dom/derived.ts +62 -62
  5. package/src/babel/handlers/dom/effect.ts +15 -15
  6. package/src/babel/handlers/dom/globals.ts +105 -105
  7. package/src/babel/handlers/dom/state.ts +107 -107
  8. package/src/babel/handlers/ssr/derived.ts +27 -27
  9. package/src/babel/handlers/ssr/state.ts +11 -11
  10. package/src/babel/index.ts +13 -0
  11. package/src/babel/jsx/anchor-mount.ts +385 -389
  12. package/src/babel/jsx/children.ts +124 -124
  13. package/src/babel/jsx/element.ts +848 -831
  14. package/src/babel/jsx/fragment.ts +282 -282
  15. package/src/babel/jsx/index.ts +2 -2
  16. package/src/babel/jsx/keyed-list.ts +309 -278
  17. package/src/babel/jsx/ssr.ts +351 -319
  18. package/src/babel/jsx/text-node.ts +192 -192
  19. package/src/babel/jsx/utils.ts +179 -179
  20. package/src/babel/util/bind.ts +139 -139
  21. package/src/babel/util/css.ts +151 -151
  22. package/src/babel/util/dead-code.ts +28 -28
  23. package/src/babel/util/helpers.ts +46 -46
  24. package/src/babel/util/magic.ts +11 -11
  25. package/src/bun-plugin.ts +92 -92
  26. package/src/vite/index.ts +58 -58
  27. package/test/async-components.test.ts +59 -59
  28. package/test/components.test.ts +129 -129
  29. package/test/containsSignal.test.ts +288 -288
  30. package/test/fragments.test.ts +90 -90
  31. package/test/helpers/transform.ts +45 -45
  32. package/test/hydration.test.ts +147 -147
  33. package/test/jsx.test.ts +227 -197
  34. package/test/keyed-lists.test.ts +126 -88
  35. package/test/reactivity.test.ts +225 -225
  36. package/test/scoped-css.test.ts +129 -129
  37. package/test/ssr.test.ts +130 -130
  38. package/test/style-object.test.ts +13 -0
  39. package/test/tree-shaking.test.ts +78 -78
  40. package/tsconfig.json +30 -30
@@ -1,124 +1,124 @@
1
- import { types as t } from "@babel/core";
2
- import { processElement } from "./element";
3
- import { processFragment } from "./fragment";
4
-
5
- /**
6
- * Collect children from a JSX element into a children expression.
7
- * Returns null if no meaningful children exist.
8
- */
9
- export function collectChildren(
10
- node: t.JSXElement,
11
- _statements: t.Statement[],
12
- genId: () => string,
13
- signals: Set<string>,
14
- hash?: string,
15
- hydrate?: boolean,
16
- nodesVar?: string,
17
- ): t.Expression | null {
18
- const childrenElements: t.Expression[] = [];
19
- let hasOnlyText = true;
20
-
21
- for (const child of node.children) {
22
- if (t.isJSXText(child)) {
23
- const text = child.value.trim();
24
- if (!text) continue;
25
- childrenElements.push(t.stringLiteral(text));
26
- } else if (t.isJSXElement(child) || t.isJSXFragment(child)) {
27
- hasOnlyText = false;
28
- const childStatements: t.Statement[] = [];
29
- let childVar: string;
30
- if (t.isJSXElement(child)) {
31
- childVar = processElement(
32
- child,
33
- childStatements,
34
- genId,
35
- signals,
36
- hash,
37
- hydrate,
38
- nodesVar,
39
- );
40
- } else {
41
- childVar = processFragment(
42
- child,
43
- childStatements,
44
- genId,
45
- signals,
46
- hash,
47
- hydrate,
48
- nodesVar,
49
- );
50
- }
51
- // Build an IIFE from the child statements
52
- childrenElements.push(
53
- t.callExpression(
54
- t.arrowFunctionExpression(
55
- [],
56
- t.blockStatement([
57
- ...childStatements,
58
- t.returnStatement(t.identifier(childVar)),
59
- ]),
60
- ),
61
- [],
62
- ),
63
- );
64
- } else if (t.isJSXExpressionContainer(child)) {
65
- const expr = child.expression as t.Expression;
66
- if (t.isJSXElement(expr) || t.isJSXFragment(expr)) {
67
- hasOnlyText = false;
68
- const childStatements: t.Statement[] = [];
69
- let childVar: string;
70
- if (t.isJSXElement(expr)) {
71
- childVar = processElement(
72
- expr,
73
- childStatements,
74
- genId,
75
- signals,
76
- hash,
77
- hydrate,
78
- nodesVar,
79
- );
80
- } else {
81
- childVar = processFragment(
82
- expr,
83
- childStatements,
84
- genId,
85
- signals,
86
- hash,
87
- hydrate,
88
- nodesVar,
89
- );
90
- }
91
- childrenElements.push(
92
- t.callExpression(
93
- t.arrowFunctionExpression(
94
- [],
95
- t.blockStatement([
96
- ...childStatements,
97
- t.returnStatement(t.identifier(childVar)),
98
- ]),
99
- ),
100
- [],
101
- ),
102
- );
103
- } else {
104
- hasOnlyText = false;
105
- // For dynamic expressions, just pass the expression directly
106
- childrenElements.push(expr);
107
- }
108
- }
109
- }
110
-
111
- if (childrenElements.length === 0) return null;
112
- // Build the inner value: string for single text, array otherwise
113
- let inner: t.Expression;
114
- if (
115
- childrenElements.length === 1 &&
116
- hasOnlyText &&
117
- t.isStringLiteral(childrenElements[0])
118
- ) {
119
- inner = childrenElements[0];
120
- } else {
121
- inner = t.arrayExpression(childrenElements);
122
- }
123
- return inner;
124
- }
1
+ import { types as t } from "@babel/core";
2
+ import { processElement } from "./element";
3
+ import { processFragment } from "./fragment";
4
+
5
+ /**
6
+ * Collect children from a JSX element into a children expression.
7
+ * Returns null if no meaningful children exist.
8
+ */
9
+ export function collectChildren(
10
+ node: t.JSXElement,
11
+ _statements: t.Statement[],
12
+ genId: () => string,
13
+ signals: Set<string>,
14
+ hash?: string,
15
+ hydrate?: boolean,
16
+ nodesVar?: string,
17
+ ): t.Expression | null {
18
+ const childrenElements: t.Expression[] = [];
19
+ let hasOnlyText = true;
20
+
21
+ for (const child of node.children) {
22
+ if (t.isJSXText(child)) {
23
+ const text = child.value.trim();
24
+ if (!text) continue;
25
+ childrenElements.push(t.stringLiteral(text));
26
+ } else if (t.isJSXElement(child) || t.isJSXFragment(child)) {
27
+ hasOnlyText = false;
28
+ const childStatements: t.Statement[] = [];
29
+ let childVar: string;
30
+ if (t.isJSXElement(child)) {
31
+ childVar = processElement(
32
+ child,
33
+ childStatements,
34
+ genId,
35
+ signals,
36
+ hash,
37
+ hydrate,
38
+ nodesVar,
39
+ );
40
+ } else {
41
+ childVar = processFragment(
42
+ child,
43
+ childStatements,
44
+ genId,
45
+ signals,
46
+ hash,
47
+ hydrate,
48
+ nodesVar,
49
+ );
50
+ }
51
+ // Build an IIFE from the child statements
52
+ childrenElements.push(
53
+ t.callExpression(
54
+ t.arrowFunctionExpression(
55
+ [],
56
+ t.blockStatement([
57
+ ...childStatements,
58
+ t.returnStatement(t.identifier(childVar)),
59
+ ]),
60
+ ),
61
+ [],
62
+ ),
63
+ );
64
+ } else if (t.isJSXExpressionContainer(child)) {
65
+ const expr = child.expression as t.Expression;
66
+ if (t.isJSXElement(expr) || t.isJSXFragment(expr)) {
67
+ hasOnlyText = false;
68
+ const childStatements: t.Statement[] = [];
69
+ let childVar: string;
70
+ if (t.isJSXElement(expr)) {
71
+ childVar = processElement(
72
+ expr,
73
+ childStatements,
74
+ genId,
75
+ signals,
76
+ hash,
77
+ hydrate,
78
+ nodesVar,
79
+ );
80
+ } else {
81
+ childVar = processFragment(
82
+ expr,
83
+ childStatements,
84
+ genId,
85
+ signals,
86
+ hash,
87
+ hydrate,
88
+ nodesVar,
89
+ );
90
+ }
91
+ childrenElements.push(
92
+ t.callExpression(
93
+ t.arrowFunctionExpression(
94
+ [],
95
+ t.blockStatement([
96
+ ...childStatements,
97
+ t.returnStatement(t.identifier(childVar)),
98
+ ]),
99
+ ),
100
+ [],
101
+ ),
102
+ );
103
+ } else {
104
+ hasOnlyText = false;
105
+ // For dynamic expressions, just pass the expression directly
106
+ childrenElements.push(expr);
107
+ }
108
+ }
109
+ }
110
+
111
+ if (childrenElements.length === 0) return null;
112
+ // Build the inner value: string for single text, array otherwise
113
+ let inner: t.Expression;
114
+ if (
115
+ childrenElements.length === 1 &&
116
+ hasOnlyText &&
117
+ t.isStringLiteral(childrenElements[0])
118
+ ) {
119
+ inner = childrenElements[0];
120
+ } else {
121
+ inner = t.arrayExpression(childrenElements);
122
+ }
123
+ return inner;
124
+ }