@sigil-dev/compiler 0.7.6 → 0.8.0

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.
@@ -1,79 +1,78 @@
1
- import { describe, expect, spyOn, test } from "bun:test";
2
- import { transform } from "./helpers/transform.ts";
3
-
4
-
5
- describe("Dead code warnings", () => {
6
- test("warns on unused $state", () => {
7
- const warn = spyOn(console, "warn");
8
- transform(`
9
- let unused = $state(0);
10
- const el = <div />;
11
- `);
12
- expect(warn).toHaveBeenCalledWith(
13
- expect.stringContaining('unused reactive declaration: "unused"'),
14
- );
15
- warn.mockRestore();
16
- });
17
-
18
- test("warns on unused $derived", () => {
19
- const warn = spyOn(console, "warn");
20
- transform(`
21
- let count = $state(0);
22
- let doubled = $derived(count * 2);
23
- const el = <div>{count}</div>;
24
- `);
25
- expect(warn).toHaveBeenCalledWith(
26
- expect.stringContaining('unused reactive declaration: "doubled"'),
27
- );
28
- warn.mockRestore();
29
- });
30
-
31
- test("no warning when $state is used in JSX", () => {
32
- const warn = spyOn(console, "warn");
33
- transform(`
34
- let count = $state(0);
35
- const el = <div>{count}</div>;
36
- `);
37
- expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
38
- warn.mockRestore();
39
- });
40
-
41
- test("no warning when $state is used in effect", () => {
42
- const warn = spyOn(console, "warn");
43
- transform(`
44
- let count = $state(0);
45
- $effect(() => { console.log(count); });
46
- `);
47
- expect(warn).not.toHaveBeenCalledWith(expect.stringContaining('"count"'));
48
- warn.mockRestore();
49
- });
50
-
51
- test("$store does not warn even if not used in same file", () => {
52
- const warn = spyOn(console, "warn");
53
- transform(`
54
- export let count = $store(0);
55
- export let user = $store({ name: "" });
56
- `);
57
- expect(warn).not.toHaveBeenCalledWith(
58
- expect.stringContaining("unused reactive declaration")
59
- );
60
- warn.mockRestore();
61
- });
62
-
63
- test("$store compiles to createSignal like $state", () => {
64
- const code = transform(`
65
- export let count = $store(0);
66
- `);
67
- expect(code).toContain("createSignal(0)");
68
- expect(code).not.toContain("$store");
69
- });
70
-
71
- test("$store in JSX works like $state", () => {
72
- const code = transform(`
73
- export let count = $store(0);
74
- const el = <div>{count}</div>;
75
- `);
76
- expect(code).toContain("count()");
77
- expect(code).not.toContain("$store");
78
- });
79
- });
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
+ });