@sigil-dev/compiler 0.9.1 → 0.9.3

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/README.md +162 -162
  2. package/index.ts +4 -4
  3. package/jsr.json +8 -8
  4. package/package.json +1 -1
  5. package/src/babel/handlers/dom/derived.ts +62 -62
  6. package/src/babel/handlers/dom/effect.ts +15 -15
  7. package/src/babel/handlers/dom/globals.ts +105 -105
  8. package/src/babel/handlers/dom/state.ts +107 -104
  9. package/src/babel/handlers/ssr/derived.ts +27 -27
  10. package/src/babel/handlers/ssr/state.ts +11 -11
  11. package/src/babel/index.ts +594 -589
  12. package/src/babel/jsx/anchor-mount.ts +389 -389
  13. package/src/babel/jsx/children.ts +124 -124
  14. package/src/babel/jsx/element.ts +831 -831
  15. package/src/babel/jsx/fragment.ts +282 -282
  16. package/src/babel/jsx/index.ts +2 -2
  17. package/src/babel/jsx/keyed-list.ts +278 -278
  18. package/src/babel/jsx/ssr.ts +319 -319
  19. package/src/babel/jsx/text-node.ts +192 -192
  20. package/src/babel/jsx/utils.ts +179 -179
  21. package/src/babel/util/bind.ts +139 -139
  22. package/src/babel/util/css.ts +151 -151
  23. package/src/babel/util/dead-code.ts +28 -28
  24. package/src/babel/util/helpers.ts +46 -46
  25. package/src/babel/util/magic.ts +11 -11
  26. package/src/bun-plugin.ts +92 -90
  27. package/src/vite/index.ts +58 -58
  28. package/test/async-components.test.ts +24 -24
  29. package/test/components.test.ts +129 -129
  30. package/test/containsSignal.test.ts +288 -288
  31. package/test/fragments.test.ts +90 -90
  32. package/test/helpers/transform.ts +45 -48
  33. package/test/hydration.test.ts +147 -147
  34. package/test/jsx.test.ts +197 -197
  35. package/test/keyed-lists.test.ts +88 -88
  36. package/test/reactivity.test.ts +225 -225
  37. package/test/scoped-css.test.ts +129 -129
  38. package/test/ssr.test.ts +130 -130
  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
+ }