@sigil-dev/compiler 0.9.2 → 0.9.4

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 +8 -8
  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 +599 -589
  12. package/src/babel/jsx/anchor-mount.ts +385 -389
  13. package/src/babel/jsx/children.ts +124 -124
  14. package/src/babel/jsx/element.ts +850 -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 +309 -278
  18. package/src/babel/jsx/ssr.ts +324 -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 +225 -197
  35. package/test/keyed-lists.test.ts +126 -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,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
+ }