@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,78 +1,78 @@
1
- import { describe, expect, spyOn, test } from "bun:test";
2
- import { transform } from "./helpers/transform.ts";
3
-
4
- describe("Dead code warnings", () => {
5
- test("warns on unused $state", () => {
6
- const warn = spyOn(console, "warn");
7
- transform(`
8
- let unused = $state(0);
9
- const el = <div />;
10
- `);
11
- expect(warn).toHaveBeenCalledWith(
12
- expect.stringContaining('unused reactive declaration: "unused"'),
13
- );
14
- warn.mockRestore();
15
- });
16
-
17
- test("warns on unused $derived", () => {
18
- const warn = spyOn(console, "warn");
19
- transform(`
20
- let count = $state(0);
21
- let doubled = $derived(count * 2);
22
- const el = <div>{count}</div>;
23
- `);
24
- expect(warn).toHaveBeenCalledWith(
25
- expect.stringContaining('unused reactive declaration: "doubled"'),
26
- );
27
- warn.mockRestore();
28
- });
29
-
30
- test("no warning when $state is used in JSX", () => {
31
- const warn = spyOn(console, "warn");
32
- transform(`
33
- let count = $state(0);
34
- const el = <div>{count}</div>;
35
- `);
36
- expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
37
- warn.mockRestore();
38
- });
39
-
40
- test("no warning when $state is used in effect", () => {
41
- const warn = spyOn(console, "warn");
42
- transform(`
43
- let count = $state(0);
44
- $effect(() => { console.log(count); });
45
- `);
46
- expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
47
- warn.mockRestore();
48
- });
49
-
50
- test("$store does not warn even if not used in same file", () => {
51
- const warn = spyOn(console, "warn");
52
- transform(`
53
- export let count = $store(0);
54
- export let user = $store({ name: "" });
55
- `);
56
- expect(warn).not.toHaveBeenCalledWith(
57
- expect.stringContaining("unused reactive declaration"),
58
- );
59
- warn.mockRestore();
60
- });
61
-
62
- test("$store compiles to createSignal like $state", () => {
63
- const code = transform(`
64
- export let count = $store(0);
65
- `);
66
- expect(code).toContain("createSignal(0)");
67
- expect(code).not.toContain("$store");
68
- });
69
-
70
- test("$store in JSX works like $state", () => {
71
- const code = transform(`
72
- export let count = $store(0);
73
- const el = <div>{count}</div>;
74
- `);
75
- expect(code).toContain("count()");
76
- expect(code).not.toContain("$store");
77
- });
78
- });
1
+ import { describe, expect, spyOn, test } from "bun:test";
2
+ import { transform } from "./helpers/transform.ts";
3
+
4
+ describe("Dead code warnings", () => {
5
+ test("warns on unused $state", () => {
6
+ const warn = spyOn(console, "warn");
7
+ transform(`
8
+ let unused = $state(0);
9
+ const el = <div />;
10
+ `);
11
+ expect(warn).toHaveBeenCalledWith(
12
+ expect.stringContaining('unused reactive declaration: "unused"'),
13
+ );
14
+ warn.mockRestore();
15
+ });
16
+
17
+ test("warns on unused $derived", () => {
18
+ const warn = spyOn(console, "warn");
19
+ transform(`
20
+ let count = $state(0);
21
+ let doubled = $derived(count * 2);
22
+ const el = <div>{count}</div>;
23
+ `);
24
+ expect(warn).toHaveBeenCalledWith(
25
+ expect.stringContaining('unused reactive declaration: "doubled"'),
26
+ );
27
+ warn.mockRestore();
28
+ });
29
+
30
+ test("no warning when $state is used in JSX", () => {
31
+ const warn = spyOn(console, "warn");
32
+ transform(`
33
+ let count = $state(0);
34
+ const el = <div>{count}</div>;
35
+ `);
36
+ expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
37
+ warn.mockRestore();
38
+ });
39
+
40
+ test("no warning when $state is used in effect", () => {
41
+ const warn = spyOn(console, "warn");
42
+ transform(`
43
+ let count = $state(0);
44
+ $effect(() => { console.log(count); });
45
+ `);
46
+ expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
47
+ warn.mockRestore();
48
+ });
49
+
50
+ test("$store does not warn even if not used in same file", () => {
51
+ const warn = spyOn(console, "warn");
52
+ transform(`
53
+ export let count = $store(0);
54
+ export let user = $store({ name: "" });
55
+ `);
56
+ expect(warn).not.toHaveBeenCalledWith(
57
+ expect.stringContaining("unused reactive declaration"),
58
+ );
59
+ warn.mockRestore();
60
+ });
61
+
62
+ test("$store compiles to createSignal like $state", () => {
63
+ const code = transform(`
64
+ export let count = $store(0);
65
+ `);
66
+ expect(code).toContain("createSignal(0)");
67
+ expect(code).not.toContain("$store");
68
+ });
69
+
70
+ test("$store in JSX works like $state", () => {
71
+ const code = transform(`
72
+ export let count = $store(0);
73
+ const el = <div>{count}</div>;
74
+ `);
75
+ expect(code).toContain("count()");
76
+ expect(code).not.toContain("$store");
77
+ });
78
+ });
package/tsconfig.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "compilerOptions": {
3
- // Environment setup & latest features
4
- "lib": ["ESNext"],
5
- "target": "ESNext",
6
- "module": "Preserve",
7
- "moduleDetection": "force",
8
- "jsx": "react-jsx",
9
- "allowJs": true,
10
- "types": ["bun"],
11
-
12
- // Bundler mode
13
- "moduleResolution": "bundler",
14
- "allowImportingTsExtensions": true,
15
- "verbatimModuleSyntax": true,
16
- "noEmit": true,
17
-
18
- // Best practices
19
- "strict": true,
20
- "skipLibCheck": true,
21
- "noFallthroughCasesInSwitch": true,
22
- "noUncheckedIndexedAccess": true,
23
- "noImplicitOverride": true,
24
-
25
- // Some stricter flags (disabled by default)
26
- "noUnusedLocals": false,
27
- "noUnusedParameters": false,
28
- "noPropertyAccessFromIndexSignature": false
29
- }
30
- }
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+ "types": ["bun"],
11
+
12
+ // Bundler mode
13
+ "moduleResolution": "bundler",
14
+ "allowImportingTsExtensions": true,
15
+ "verbatimModuleSyntax": true,
16
+ "noEmit": true,
17
+
18
+ // Best practices
19
+ "strict": true,
20
+ "skipLibCheck": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "noUncheckedIndexedAccess": true,
23
+ "noImplicitOverride": true,
24
+
25
+ // Some stricter flags (disabled by default)
26
+ "noUnusedLocals": false,
27
+ "noUnusedParameters": false,
28
+ "noPropertyAccessFromIndexSignature": false
29
+ }
30
+ }