@sigil-dev/compiler 0.7.4 → 0.7.6
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 +5 -1
- package/src/babel/handlers/dom/derived.ts +31 -1
- package/src/babel/handlers/dom/globals.ts +102 -0
- package/src/babel/handlers/ssr/state.ts +10 -10
- package/src/babel/index.ts +430 -257
- package/src/babel/jsx/children.ts +124 -124
- package/src/babel/jsx/element.ts +803 -582
- package/src/babel/jsx/ssr.ts +319 -310
- package/src/babel/jsx/utils.ts +95 -89
- package/src/babel/util/bind.ts +126 -135
- package/src/babel/util/css.ts +151 -151
- package/src/babel/util/helpers.ts +16 -2
- package/src/babel/util/magic.ts +5 -0
- package/src/bun-plugin.ts +86 -45
- package/src/vite/index.ts +7 -2
- package/test/jsx.test.ts +195 -195
- package/test/reactivity.test.ts +147 -1
|
@@ -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
|
+
}
|