@sigil-dev/compiler 0.9.21 → 0.9.22

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,143 +1,143 @@
1
- import { types as t } from "@babel/core";
2
-
3
- const BIND_EVENT: Record<string, string> = {
4
- value: "input",
5
- checked: "change",
6
- innerHTML: "input",
7
- textContent: "input",
8
- group: "change",
9
- // element state that isn't form input changes on its own event
10
- scrollTop: "scroll",
11
- scrollLeft: "scroll",
12
- open: "toggle",
13
- };
14
-
15
- export function buildBind(
16
- varName: string,
17
- bindProp: string,
18
- attr: t.JSXAttribute,
19
- statements: t.Statement[],
20
- ): void {
21
- const signal = (attr.value as t.JSXExpressionContainer)
22
- .expression as t.CallExpression; // already text()
23
-
24
- const signalId = signal.callee as t.Identifier; // text — for .set()
25
-
26
- const event = BIND_EVENT[bindProp] ?? "input";
27
-
28
- // createEffect(() => _el.prop = text())
29
- statements.push(
30
- t.expressionStatement(
31
- t.callExpression(t.identifier("createEffect"), [
32
- t.arrowFunctionExpression(
33
- [],
34
- t.blockStatement([
35
- t.expressionStatement(
36
- t.assignmentExpression(
37
- "=",
38
- t.memberExpression(
39
- t.identifier(varName),
40
- t.identifier(bindProp),
41
- ),
42
- signal,
43
- ),
44
- ),
45
- ]),
46
- ),
47
- ]),
48
- ),
49
- );
50
-
51
- // addEventListener(event, e => text.set(e.target.prop))
52
- statements.push(
53
- t.expressionStatement(
54
- t.callExpression(
55
- t.memberExpression(
56
- t.identifier(varName),
57
- t.identifier("addEventListener"),
58
- ),
59
- [
60
- t.stringLiteral(event),
61
- t.arrowFunctionExpression(
62
- [t.identifier("e")],
63
- t.callExpression(
64
- t.memberExpression(signalId, t.identifier("set")),
65
- [
66
- t.memberExpression(
67
- t.memberExpression(t.identifier("e"), t.identifier("target")),
68
- t.identifier(bindProp),
69
- ),
70
- ],
71
- ),
72
- ),
73
- ],
74
- ),
75
- ),
76
- );
77
- }
78
-
79
- export function buildProxyBind(
80
- varName: string,
81
- bindProp: string,
82
- _attr: t.JSXAttribute,
83
- statements: t.Statement[],
84
- signal: t.MemberExpression, // already form().name
85
- ): void {
86
- const event = BIND_EVENT[bindProp] ?? "input";
87
-
88
- // createEffect(() => el.prop = form().name)
89
- statements.push(
90
- t.expressionStatement(
91
- t.callExpression(t.identifier("createEffect"), [
92
- t.arrowFunctionExpression(
93
- [],
94
- t.blockStatement([
95
- t.expressionStatement(
96
- t.assignmentExpression(
97
- "=",
98
- t.memberExpression(
99
- t.identifier(varName),
100
- t.identifier(bindProp),
101
- ),
102
- signal,
103
- ),
104
- ),
105
- ]),
106
- ),
107
- ]),
108
- ),
109
- );
110
-
111
- // addEventListener(event, e => { form().name = e.target.prop })
112
- statements.push(
113
- t.expressionStatement(
114
- t.callExpression(
115
- t.memberExpression(
116
- t.identifier(varName),
117
- t.identifier("addEventListener"),
118
- ),
119
- [
120
- t.stringLiteral(event),
121
- t.arrowFunctionExpression(
122
- [t.identifier("e")],
123
- t.blockStatement([
124
- t.expressionStatement(
125
- t.assignmentExpression(
126
- "=",
127
- signal as unknown as t.LVal, // form().name — valid LVal
128
- t.memberExpression(
129
- t.memberExpression(
130
- t.identifier("e"),
131
- t.identifier("target"),
132
- ),
133
- t.identifier(bindProp),
134
- ),
135
- ),
136
- ),
137
- ]),
138
- ),
139
- ],
140
- ),
141
- ),
142
- );
143
- }
1
+ import { types as t } from "@babel/core";
2
+
3
+ const BIND_EVENT: Record<string, string> = {
4
+ value: "input",
5
+ checked: "change",
6
+ innerHTML: "input",
7
+ textContent: "input",
8
+ group: "change",
9
+ // element state that isn't form input changes on its own event
10
+ scrollTop: "scroll",
11
+ scrollLeft: "scroll",
12
+ open: "toggle",
13
+ };
14
+
15
+ export function buildBind(
16
+ varName: string,
17
+ bindProp: string,
18
+ attr: t.JSXAttribute,
19
+ statements: t.Statement[],
20
+ ): void {
21
+ const signal = (attr.value as t.JSXExpressionContainer)
22
+ .expression as t.CallExpression; // already text()
23
+
24
+ const signalId = signal.callee as t.Identifier; // text — for .set()
25
+
26
+ const event = BIND_EVENT[bindProp] ?? "input";
27
+
28
+ // createEffect(() => _el.prop = text())
29
+ statements.push(
30
+ t.expressionStatement(
31
+ t.callExpression(t.identifier("createEffect"), [
32
+ t.arrowFunctionExpression(
33
+ [],
34
+ t.blockStatement([
35
+ t.expressionStatement(
36
+ t.assignmentExpression(
37
+ "=",
38
+ t.memberExpression(
39
+ t.identifier(varName),
40
+ t.identifier(bindProp),
41
+ ),
42
+ signal,
43
+ ),
44
+ ),
45
+ ]),
46
+ ),
47
+ ]),
48
+ ),
49
+ );
50
+
51
+ // addEventListener(event, e => text.set(e.target.prop))
52
+ statements.push(
53
+ t.expressionStatement(
54
+ t.callExpression(
55
+ t.memberExpression(
56
+ t.identifier(varName),
57
+ t.identifier("addEventListener"),
58
+ ),
59
+ [
60
+ t.stringLiteral(event),
61
+ t.arrowFunctionExpression(
62
+ [t.identifier("e")],
63
+ t.callExpression(
64
+ t.memberExpression(signalId, t.identifier("set")),
65
+ [
66
+ t.memberExpression(
67
+ t.memberExpression(t.identifier("e"), t.identifier("target")),
68
+ t.identifier(bindProp),
69
+ ),
70
+ ],
71
+ ),
72
+ ),
73
+ ],
74
+ ),
75
+ ),
76
+ );
77
+ }
78
+
79
+ export function buildProxyBind(
80
+ varName: string,
81
+ bindProp: string,
82
+ _attr: t.JSXAttribute,
83
+ statements: t.Statement[],
84
+ signal: t.MemberExpression, // already form().name
85
+ ): void {
86
+ const event = BIND_EVENT[bindProp] ?? "input";
87
+
88
+ // createEffect(() => el.prop = form().name)
89
+ statements.push(
90
+ t.expressionStatement(
91
+ t.callExpression(t.identifier("createEffect"), [
92
+ t.arrowFunctionExpression(
93
+ [],
94
+ t.blockStatement([
95
+ t.expressionStatement(
96
+ t.assignmentExpression(
97
+ "=",
98
+ t.memberExpression(
99
+ t.identifier(varName),
100
+ t.identifier(bindProp),
101
+ ),
102
+ signal,
103
+ ),
104
+ ),
105
+ ]),
106
+ ),
107
+ ]),
108
+ ),
109
+ );
110
+
111
+ // addEventListener(event, e => { form().name = e.target.prop })
112
+ statements.push(
113
+ t.expressionStatement(
114
+ t.callExpression(
115
+ t.memberExpression(
116
+ t.identifier(varName),
117
+ t.identifier("addEventListener"),
118
+ ),
119
+ [
120
+ t.stringLiteral(event),
121
+ t.arrowFunctionExpression(
122
+ [t.identifier("e")],
123
+ t.blockStatement([
124
+ t.expressionStatement(
125
+ t.assignmentExpression(
126
+ "=",
127
+ signal as unknown as t.LVal, // form().name — valid LVal
128
+ t.memberExpression(
129
+ t.memberExpression(
130
+ t.identifier("e"),
131
+ t.identifier("target"),
132
+ ),
133
+ t.identifier(bindProp),
134
+ ),
135
+ ),
136
+ ),
137
+ ]),
138
+ ),
139
+ ],
140
+ ),
141
+ ),
142
+ );
143
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Per-file flags the JSX codegen needs but is not handed as arguments. Set once
3
+ * by the plugin when it enters a file.
4
+ */
5
+ export const compileState = { dev: false };