@sigil-dev/compiler 0.9.4 → 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.
- package/index.ts +4 -4
- package/jsr.json +8 -8
- package/package.json +2 -1
- package/src/babel/handlers/dom/derived.ts +62 -62
- package/src/babel/handlers/dom/effect.ts +15 -15
- package/src/babel/handlers/dom/globals.ts +105 -105
- package/src/babel/handlers/dom/state.ts +107 -107
- package/src/babel/handlers/ssr/derived.ts +27 -27
- package/src/babel/handlers/ssr/state.ts +11 -11
- package/src/babel/index.ts +8 -0
- package/src/babel/jsx/anchor-mount.ts +385 -385
- package/src/babel/jsx/children.ts +124 -124
- package/src/babel/jsx/element.ts +848 -850
- package/src/babel/jsx/fragment.ts +282 -282
- package/src/babel/jsx/index.ts +2 -2
- package/src/babel/jsx/keyed-list.ts +309 -309
- package/src/babel/jsx/ssr.ts +351 -324
- package/src/babel/jsx/text-node.ts +192 -192
- package/src/babel/jsx/utils.ts +179 -179
- package/src/babel/util/bind.ts +139 -139
- package/src/babel/util/css.ts +151 -151
- package/src/babel/util/dead-code.ts +28 -28
- package/src/babel/util/helpers.ts +46 -46
- package/src/babel/util/magic.ts +11 -11
- package/src/bun-plugin.ts +92 -92
- package/src/vite/index.ts +58 -58
- package/test/async-components.test.ts +59 -59
- package/test/components.test.ts +129 -129
- package/test/containsSignal.test.ts +288 -288
- package/test/fragments.test.ts +90 -90
- package/test/helpers/transform.ts +45 -45
- package/test/hydration.test.ts +147 -147
- package/test/jsx.test.ts +227 -225
- package/test/keyed-lists.test.ts +126 -126
- package/test/reactivity.test.ts +225 -225
- package/test/scoped-css.test.ts +129 -129
- package/test/ssr.test.ts +130 -130
- package/test/style-object.test.ts +13 -0
- package/test/tree-shaking.test.ts +78 -78
- package/tsconfig.json +30 -30
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { type NodePath, types as t } from "@babel/core";
|
|
2
|
-
|
|
3
|
-
export function handleDerivedSSR(
|
|
4
|
-
declaration: NodePath<t.VariableDeclaration>,
|
|
5
|
-
declarator: NodePath<t.VariableDeclarator>,
|
|
6
|
-
init: NodePath<t.CallExpression>,
|
|
7
|
-
_signals?: Set<string>, // SSR has no reactivity, intentionally unused
|
|
8
|
-
): void {
|
|
9
|
-
const { id } = declarator.node;
|
|
10
|
-
if (!t.isIdentifier(id))
|
|
11
|
-
throw new Error("Destructured $derived not supported");
|
|
12
|
-
|
|
13
|
-
// Replace $derived(expr) with () => expr (lazy evaluation)
|
|
14
|
-
init.replaceWith(
|
|
15
|
-
t.arrowFunctionExpression([], init.node.arguments[0] as t.Expression),
|
|
16
|
-
);
|
|
17
|
-
declaration.node.kind = "const";
|
|
18
|
-
|
|
19
|
-
// Replace all references to this variable with () calls
|
|
20
|
-
const binding = declaration.scope.getBinding(id.name);
|
|
21
|
-
if (!binding) return;
|
|
22
|
-
for (const ref of [...binding.referencePaths]) {
|
|
23
|
-
if (!ref.isIdentifier()) continue;
|
|
24
|
-
if (ref.parentPath?.isUpdateExpression()) continue;
|
|
25
|
-
ref.replaceWith(t.callExpression(ref.node, []));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
import { type NodePath, types as t } from "@babel/core";
|
|
2
|
+
|
|
3
|
+
export function handleDerivedSSR(
|
|
4
|
+
declaration: NodePath<t.VariableDeclaration>,
|
|
5
|
+
declarator: NodePath<t.VariableDeclarator>,
|
|
6
|
+
init: NodePath<t.CallExpression>,
|
|
7
|
+
_signals?: Set<string>, // SSR has no reactivity, intentionally unused
|
|
8
|
+
): void {
|
|
9
|
+
const { id } = declarator.node;
|
|
10
|
+
if (!t.isIdentifier(id))
|
|
11
|
+
throw new Error("Destructured $derived not supported");
|
|
12
|
+
|
|
13
|
+
// Replace $derived(expr) with () => expr (lazy evaluation)
|
|
14
|
+
init.replaceWith(
|
|
15
|
+
t.arrowFunctionExpression([], init.node.arguments[0] as t.Expression),
|
|
16
|
+
);
|
|
17
|
+
declaration.node.kind = "const";
|
|
18
|
+
|
|
19
|
+
// Replace all references to this variable with () calls
|
|
20
|
+
const binding = declaration.scope.getBinding(id.name);
|
|
21
|
+
if (!binding) return;
|
|
22
|
+
for (const ref of [...binding.referencePaths]) {
|
|
23
|
+
if (!ref.isIdentifier()) continue;
|
|
24
|
+
if (ref.parentPath?.isUpdateExpression()) continue;
|
|
25
|
+
ref.replaceWith(t.callExpression(ref.node, []));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { NodePath, types as t } from "@babel/core";
|
|
2
|
-
|
|
3
|
-
export function handleStateSSR(
|
|
4
|
-
declaration: NodePath<t.VariableDeclaration>,
|
|
5
|
-
_declarator: NodePath<t.VariableDeclarator>,
|
|
6
|
-
init: NodePath<t.CallExpression>,
|
|
7
|
-
_signals?: Set<string>, // SSR has no reactivity. Left in for future reference
|
|
8
|
-
): void {
|
|
9
|
-
init.replaceWith(init.node.arguments[0] as t.Expression);
|
|
10
|
-
declaration.node.kind = "let";
|
|
11
|
-
}
|
|
1
|
+
import type { NodePath, types as t } from "@babel/core";
|
|
2
|
+
|
|
3
|
+
export function handleStateSSR(
|
|
4
|
+
declaration: NodePath<t.VariableDeclaration>,
|
|
5
|
+
_declarator: NodePath<t.VariableDeclarator>,
|
|
6
|
+
init: NodePath<t.CallExpression>,
|
|
7
|
+
_signals?: Set<string>, // SSR has no reactivity. Left in for future reference
|
|
8
|
+
): void {
|
|
9
|
+
init.replaceWith(init.node.arguments[0] as t.Expression);
|
|
10
|
+
declaration.node.kind = "let";
|
|
11
|
+
}
|
package/src/babel/index.ts
CHANGED
|
@@ -25,6 +25,14 @@ const SSR_HELPERS = template.statements.ast(`
|
|
|
25
25
|
if (v?.[__SAFE]) return v.v;
|
|
26
26
|
if (Array.isArray(v)) return v.map(x => x?.[__SAFE] ? x.v : __e(x)).join('');
|
|
27
27
|
if (v === false || v === null || v === undefined) return '';
|
|
28
|
+
if (typeof v === 'object' && v.constructor === Object) {
|
|
29
|
+
const UNITLESS = new Set(['animationIterationCount','borderImageOutset','borderImageSlice','borderImageWidth','boxFlex','boxFlexGroup','boxSnapAfterPatch','boxSupress','columnCount','columnFlex','columnFlexGrow','columns','flexGrow','flexPositive','flexShrink','flexNegative','fontWeight','gridArea','gridRow','gridRowEnd','gridRowSpan','gridRowStart','gridColumn','gridColumnEnd','gridColumnSpan','gridColumnStart','lineClamp','lineHeight','opacity','order','orphans','tabSize','widows','zIndex','zoom','fillOpacity','floodOpacity','stopOpacity','strokeDasharray','strokeDashoffset','strokeMiterlimit','strokeOpacity','strokeWidth']);
|
|
30
|
+
return Object.entries(v).map(([k, val]) => {
|
|
31
|
+
const prop = k.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
32
|
+
if (typeof val === 'number' && !UNITLESS.has(k)) return prop + ':' + val + 'px';
|
|
33
|
+
return prop + ':' + val;
|
|
34
|
+
}).join(';');
|
|
35
|
+
}
|
|
28
36
|
return String(v).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
|
|
29
37
|
};
|
|
30
38
|
`);
|