@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.
Files changed (40) hide show
  1. package/index.ts +4 -4
  2. package/jsr.json +8 -8
  3. package/package.json +2 -1
  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 +8 -0
  11. package/src/babel/jsx/anchor-mount.ts +385 -385
  12. package/src/babel/jsx/children.ts +124 -124
  13. package/src/babel/jsx/element.ts +848 -850
  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 -309
  17. package/src/babel/jsx/ssr.ts +351 -324
  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 -225
  34. package/test/keyed-lists.test.ts +126 -126
  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,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
+ }
@@ -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,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;');
29
37
  };
30
38
  `);