@solidjs/babel-plugin 2.0.0-rc.2

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.
@@ -0,0 +1,10 @@
1
+ $ rollup -c --bundleConfigAsCjs
2
+ 
3
+ src/index.ts → index.js...
4
+ (!) Circular dependencies
5
+ src/shared/transform.ts -> src/dom/element.ts -> src/shared/transform.ts
6
+ src/shared/transform.ts -> src/ssr/element.ts -> src/shared/transform.ts
7
+ src/shared/transform.ts -> src/universal/element.ts -> src/shared/transform.ts
8
+ src/shared/transform.ts -> src/shared/component.ts -> src/shared/transform.ts
9
+ src/shared/transform.ts -> src/shared/fragment.ts -> src/shared/transform.ts
10
+ created index.js in 7.7s
@@ -0,0 +1,122 @@
1
+ $ pnpm run typecheck && pnpm run build && vitest run
2
+ $ tsc -p tsconfig.json --noEmit
3
+ $ rollup -c --bundleConfigAsCjs
4
+ 
5
+ src/index.ts → index.js...
6
+ (!) Circular dependencies
7
+ src/shared/transform.ts -> src/dom/element.ts -> src/shared/transform.ts
8
+ src/shared/transform.ts -> src/ssr/element.ts -> src/shared/transform.ts
9
+ src/shared/transform.ts -> src/universal/element.ts -> src/shared/transform.ts
10
+ src/shared/transform.ts -> src/shared/component.ts -> src/shared/transform.ts
11
+ src/shared/transform.ts -> src/shared/fragment.ts -> src/shared/transform.ts
12
+ created index.js in 1.6s
13
+
14
+ RUN v4.1.6 /Users/ryancarniato/Development/solid/packages/babel-plugin
15
+
16
+ stdout | test/dom.spec.js > Convert JSX fixtures > attributeExpressions
17
+
18
+ SyntaxError: "_hk" attribute found in template, which could potentially cause hydration miss-matches. Usually happens when copying and pasting Solid SSRed code into JSX. Please remove the attribute from the JSX.
19
+
20
+ /Users/ryancarniato/Development/solid/packages/babel-plugin/test/__dom_fixtures__/attributeExpressions/code.js
21
+
22
+ 388 | }
23
+ 389 |
24
+ > 390 | const template89 = <div _hk="should warn _hk is present on template" />;
25
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
26
+ 391 |
27
+ 392 | const template90 = <div style={{}} />;
28
+ 393 |
29
+
30
+ stdout | test/dynamic-dom.spec.js > Convert JSX fixtures > attributeExpressions
31
+
32
+ SyntaxError: "_hk" attribute found in template, which could potentially cause hydration miss-matches. Usually happens when copying and pasting Solid SSRed code into JSX. Please remove the attribute from the JSX.
33
+
34
+ /Users/ryancarniato/Development/solid/packages/babel-plugin/test/__dom_fixtures__/attributeExpressions/code.js
35
+
36
+ 388 | }
37
+ 389 |
38
+ > 390 | const template89 = <div _hk="should warn _hk is present on template" />;
39
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
+ 391 |
41
+ 392 | const template90 = <div style={{}} />;
42
+ 393 |
43
+
44
+ ✓ test/universal.spec.js (8 tests) 2008ms
45
+ ✓ attributeExpressions 850ms
46
+ ✓ components 324ms
47
+ ✓ conditionalExpressions 433ms
48
+ ✓ test/dynamic-universal.spec.js (8 tests) 1975ms
49
+ ✓ attributeExpressions 883ms
50
+ ✓ components 313ms
51
+ ✓ conditionalExpressions 369ms
52
+ ✓ test/ssr-hydratable.spec.js (13 tests) 2577ms
53
+ ✓ SVG 719ms
54
+ ✓ attributeExpressions 755ms
55
+ ✓ conditionalExpressions 434ms
56
+ ✓ test/dom.spec.js (16 tests) 2553ms
57
+ ✓ SVG 668ms
58
+ ✓ attributeExpressions 641ms
59
+ ✓ conditionalExpressions 314ms
60
+ ✓ test/dom-hydratable.spec.js (15 tests) 2646ms
61
+ ✓ SVG 755ms
62
+ ✓ attributeExpressions 697ms
63
+ ✓ components 380ms
64
+ ✓ conditionalExpressions 328ms
65
+ ✓ test/ssr.spec.js (13 tests) 2608ms
66
+ ✓ SVG 640ms
67
+ ✓ attributeExpressions 697ms
68
+ ✓ components 330ms
69
+ ✓ conditionalExpressions 387ms
70
+ ✓ test/dynamic.spec.js (12 tests) 2745ms
71
+ ✓ SVG 738ms
72
+ ✓ attributeExpressions 759ms
73
+ ✓ components 353ms
74
+ ✓ conditionalExpressions 369ms
75
+ ✓ test/dynamic-hydratable.spec.js (15 tests) 2765ms
76
+ ✓ SVG 777ms
77
+ ✓ attributeExpressions 825ms
78
+ ✓ test/dynamic-dom.spec.js (16 tests) 3030ms
79
+ ✓ SVG 691ms
80
+ ✓ attributeExpressions 985ms
81
+ ✓ components 328ms
82
+ stdout | test/dom-compatible.spec.js > Convert JSX fixtures > attributeExpressions
83
+
84
+ SyntaxError: "_hk" attribute found in template, which could potentially cause hydration miss-matches. Usually happens when copying and pasting Solid SSRed code into JSX. Please remove the attribute from the JSX.
85
+
86
+ /Users/ryancarniato/Development/solid/packages/babel-plugin/test/__dom_compatible_fixtures__/attributeExpressions/code.js
87
+
88
+ 382 | }
89
+ 383 |
90
+ > 384 | const template89 = <div _hk="should warn _hk is present on template" />;
91
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
92
+ 385 |
93
+ 386 | const template90 = <div style={{}} />;
94
+ 387 |
95
+
96
+ ✓ test/rowproof.spec.js (15 tests) 537ms
97
+ ✓ stamps a plain member-read row 323ms
98
+ ✓ test/numberedId.spec.js (1 test) 709ms
99
+ ✓ handles >= 490 merged dynamic attributes without emitting reserved-word bindings 707ms
100
+ ✓ test/dom-no-inline-styles.spec.js (1 test) 744ms
101
+ ✓ attributeExpressions 733ms
102
+ ✓ test/ssr-server-components.spec.js (1 test) 677ms
103
+ ✓ behaviorClaims 675ms
104
+ ✓ test/dom-wrapperless.spec.js (3 tests) 1208ms
105
+ ✓ components 931ms
106
+ ✓ test/dom-hydratable-dev.spec.js (2 tests) 830ms
107
+ ✓ simpleElements 760ms
108
+ ✓ test/dom-omit-attribute-spacing.spec.js (1 test) 649ms
109
+ ✓ SVG 647ms
110
+ ✓ test/dom-compatible.spec.js (3 tests) 1367ms
111
+ ✓ SVG 511ms
112
+ ✓ attributeExpressions 792ms
113
+ ✓ test/dynamic-wrapperless.spec.js (3 tests) 1046ms
114
+ ✓ components 894ms
115
+ ✓ test/defaults.spec.js (3 tests) 138ms
116
+ ✓ test/dom-require-import-source.spec.js (4 tests) 235ms
117
+
118
+ Test Files 20 passed (20)
119
+ Tests 153 passed (153)
120
+ Start at 15:50:06
121
+ Duration 5.68s (transform 464ms, setup 0ms, import 8.99s, tests 31.05s, environment 4ms)
122
+
@@ -0,0 +1 @@
1
+ $ tsc -p tsconfig.json --noEmit
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # @solidjs/babel-plugin
2
+
3
+ The Babel compiler implementation joined the SolidJS 2.0 monorepo at `2.0.0-rc.2` under the temporary `@solidjs/babel-plugin-jsx` name. It adopted this syntax-neutral package name before the integration merged. Earlier releases lived in [DOM Expressions](https://github.com/ryansolid/dom-expressions).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016-2025 Ryan Carniato
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,308 @@
1
+ # @solidjs/babel-plugin
2
+
3
+ Solid 2.0's Babel compiler integration. Configure this plugin once in a Babel pipeline; its current syntax frontend lowers JSX to template clones, inserts, and reactive wrappers against `@solidjs/web` (or a custom renderer).
4
+
5
+ The native Oxc compiler — [`@solidjs/compiler`](../compiler) — is the default in `vite-plugin-solid`. Use this plugin when you need a Babel pipeline (or as the JavaScript fallback).
6
+
7
+ > **Solid 2.0 (Release Candidate).** Pin exact versions.
8
+
9
+ ## Features
10
+
11
+ Lowercase tags are HTML elements; mixed-case tags are components. The plugin supports Custom Elements, camelCase event handlers, DOM-safe attributes (`class`, `for`), `ref`, and object `style` / `class` parsing.
12
+
13
+ Attribute expressions are attributes by default, except on custom elements (properties) and special fields like `class` and `style`. A heuristic wraps expressions that contain function calls or property access; simple literals and variables stay unwrapped.
14
+
15
+ ## Example
16
+
17
+ ```jsx
18
+ const view = ({ item }) => {
19
+ const itemId = item.id;
20
+ return (
21
+ <tr class={itemId === selected() ? "danger" : ""}>
22
+ <td class="col-md-1">{itemId}</td>
23
+ <td class="col-md-4">
24
+ <a onClick={e => select(item, e)}>{item.label}</a>
25
+ </td>
26
+ <td class="col-md-1">
27
+ <a onClick={e => del(item, e)}>
28
+ <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
29
+ </a>
30
+ </td>
31
+ <td class="col-md-6"></td>
32
+ </tr>
33
+ );
34
+ };
35
+ ```
36
+
37
+ Compiles to:
38
+
39
+ ```js
40
+ import { template as _$template } from "@solidjs/web";
41
+ import { delegateEvents as _$delegateEvents } from "@solidjs/web";
42
+ import { className as _$className } from "@solidjs/web";
43
+ import { effect as _$effect } from "@solidjs/web";
44
+ import { insert as _$insert } from "@solidjs/web";
45
+
46
+ const _tmpl$ = /*#__PURE__*/ _$template(
47
+ `<tr><td class="col-md-1"></td><td class="col-md-4"><a></a></td><td class="col-md-1"><a><span class="glyphicon glyphicon-remove" aria-hidden="true"></span></a></td><td class="col-md-6"></td></tr>`
48
+ );
49
+ const view = ({ item }) => {
50
+ const itemId = item.id;
51
+ return (() => {
52
+ const _el$ = _tmpl$(),
53
+ _el$2 = _el$.firstChild,
54
+ _el$3 = _el$2.nextSibling,
55
+ _el$4 = _el$3.firstChild,
56
+ _el$5 = _el$3.nextSibling,
57
+ _el$6 = _el$5.firstChild;
58
+ _$insert(_el$2, itemId);
59
+ _el$4.$$click = e => select(item, e);
60
+ _$insert(_el$4, () => item.label);
61
+ _el$6.$$click = e => del(item, e);
62
+ _$effect(
63
+ () => selected(),
64
+ _v$ => _$className(_el$, itemId === _v$ ? "danger" : "")
65
+ );
66
+ return _el$;
67
+ })();
68
+ };
69
+ _$delegateEvents(["click"]);
70
+ ```
71
+
72
+ `cloneNode` (via `template()`) improves repeat insert performance and precompilation reduces references to the minimal traversal path.
73
+
74
+ ## Configuration
75
+
76
+ Omitted options are the Solid 2.0 defaults that used to live in `babel-preset-solid`: `moduleName: "@solidjs/web"`, `generate: "dom"`, `wrapConditionals`, `contextToCustomElements`, and auto-import of `For` / `Show` / `Switch` / `Match` / `Loading` / `Reveal` / `Portal` / `Repeat` / `Dynamic` / `Errored`.
77
+
78
+ ```js
79
+ {
80
+ plugins: [
81
+ [
82
+ "@solidjs/babel-plugin",
83
+ {
84
+ moduleName: "@solidjs/web",
85
+ generate: "dom",
86
+ hydratable: true
87
+ }
88
+ ]
89
+ ]
90
+ }
91
+ ```
92
+
93
+ ## Plugin Options
94
+
95
+ ### moduleName
96
+
97
+ - Type: `string`
98
+ - Default: `"@solidjs/web"`
99
+
100
+ Runtime module the compiled output imports helpers from. Use the same module for SSR; switch `generate` instead.
101
+
102
+ ### generate
103
+
104
+ - Type: `'dom' | 'ssr' | 'universal' | 'dynamic'`
105
+ - Default: `'dom'`
106
+
107
+ `"dom"` is client DOM output. `"ssr"` emits server strings. `"universal"` targets a custom renderer. `"dynamic"` uses the universal renderer as fallback and can route configured native tags to the DOM renderer.
108
+
109
+ ### hydratable
110
+
111
+ - Type: `boolean`
112
+ - Default: `false`
113
+
114
+ Emit hydratable markers.
115
+
116
+ ### delegateEvents
117
+
118
+ - Type: `boolean`
119
+ - Default: `true`
120
+
121
+ Automatic event delegation on camelCase.
122
+
123
+ ### wrapConditionals
124
+
125
+ - Type: `boolean`
126
+ - Default: `true`
127
+
128
+ Smart conditional detection for simple boolean expressions and ternaries in JSX.
129
+
130
+ ### contextToCustomElements
131
+
132
+ - Type: `boolean`
133
+ - Default: `true`
134
+
135
+ Set current render context on Custom Elements and slots, so Solid's Context API works with Web Components.
136
+
137
+ ### builtIns
138
+
139
+ - Type: `string[]`
140
+ - Default: `["For", "Show", "Switch", "Match", "Loading", "Reveal", "Portal", "Repeat", "Dynamic", "Errored"]`
141
+
142
+ Component exports from `moduleName` that the plugin should auto-import when it sees them in JSX.
143
+
144
+ ### effectWrapper
145
+
146
+ - Type: `string | false`
147
+ - Default: `effect`
148
+
149
+ Reactive wrapper for lazy JSX expressions.
150
+
151
+ ### staticMarker
152
+
153
+ - Type: `string`
154
+ - Default: `@static`
155
+
156
+ When an expression starts with this comment, the compiler treats it as static and does not wrap it in an `effect`. Not a reactivity primitive — only use it when the expression is non-reactive for the lifetime of the element and the heuristic cannot infer that.
157
+
158
+ ### memoWrapper
159
+
160
+ - Type: `string | false`
161
+ - Default: `memo`
162
+
163
+ Memo function name for derived values used in many reactive computations.
164
+
165
+ ### validate
166
+
167
+ - Type: `boolean`
168
+ - Default: `true`
169
+
170
+ Checks for HTML that browsers would "correct" in ways that break DOM walks. Incomplete, but covers the dangerous cases.
171
+
172
+ ### omitNestedClosingTags
173
+
174
+ - Type: `boolean`
175
+ - Default: `false`
176
+
177
+ Removes unnecessary closing tags from template output. Tested against Chrome/Edge/Firefox/Safari; other HTML parsers may differ.
178
+
179
+ ### omitLastClosingTag
180
+
181
+ - Type: `boolean`
182
+ - Default: `true`
183
+
184
+ Omits the last closing tag when it has no closing parent. Same parser caveat as above.
185
+
186
+ ### omitQuotes
187
+
188
+ - Type: `boolean`
189
+ - Default: `true`
190
+
191
+ Drops quotes around HTML attributes when possible.
192
+
193
+ ### omitAttributeSpacing
194
+
195
+ - Type: `boolean`
196
+ - Default: `true`
197
+
198
+ When `true`, quoted attributes may omit the space before the next attribute. Set `false` for strictly spaced attributes.
199
+
200
+ ### requireImportSource
201
+
202
+ - Type: `string | false`
203
+ - Default: `false`
204
+
205
+ Restrict JSX transformation to files whose `@jsxImportSource` pragma matches.
206
+
207
+ ```js
208
+ {
209
+ plugins: [
210
+ [
211
+ "@solidjs/babel-plugin",
212
+ { requireImportSource: "@solidjs/web" }
213
+ ]
214
+ ]
215
+ }
216
+ ```
217
+
218
+ ```jsx
219
+ /** @jsxImportSource @solidjs/web */
220
+ const template = <div>Hello</div>;
221
+ ```
222
+
223
+ ### inlineStyles
224
+
225
+ - Type: `boolean`
226
+ - Default: `true`
227
+
228
+ Inline style attributes in templates when the value is a string or `Record<string, string>`. Disable for strong CSP configurations; styles are then set at runtime.
229
+
230
+ ### serverComponents
231
+
232
+ - Type: `boolean`
233
+ - Default: `false`
234
+
235
+ SSR-only: emit behavior-claim (`_bnd`) markers for `ref` / `on*` on intrinsic elements.
236
+
237
+ ## Special Binding
238
+
239
+ ### ref
240
+
241
+ Assigns the DOM element to a variable, or calls a function with the element.
242
+
243
+ ```jsx
244
+ const Child = props => <div ref={props.ref} />;
245
+
246
+ const Parent = () => {
247
+ let ref;
248
+ return <Child ref={ref} />;
249
+ };
250
+ ```
251
+
252
+ ### on(eventName)
253
+
254
+ CamelCase attributes such as `onClick` are event handlers. The compiler delegates events that bubble or compose, otherwise it uses Level 1 `on_____` properties.
255
+
256
+ Pass an array to bind a value: the second item is the first argument to the handler, the event is second.
257
+
258
+ ```jsx
259
+ function handler(itemId, e) {
260
+ /*...*/
261
+ }
262
+
263
+ <ul>
264
+ {list().map(item => (
265
+ <li onClick={[handler, item.id]} />
266
+ ))}
267
+ </ul>;
268
+ ```
269
+
270
+ Delegation works with Web Components and Shadow DOM when events are composed (custom events and most UA UI events). Custom delegated events should follow native all-lowercase naming. Use a ref that calls `addEventListener` when you need listener options or custom casing.
271
+
272
+ Event delegates are owned by render roots and are removed when those roots dispose.
273
+
274
+ ### ... (spreads)
275
+
276
+ ```jsx
277
+ <div {...props} />
278
+ ```
279
+
280
+ Given independent binding updates, spread order is not currently guaranteed.
281
+
282
+ ## Components
283
+
284
+ Capitalized tags are components. Dynamic props become getters rather than wrapped computations. Property access is tracking, so do not destructure outside computations unless the value should be static.
285
+
286
+ ```jsx
287
+ const MyComp = props => {
288
+ const staticProp = props.other;
289
+ return (
290
+ <>
291
+ <div>{props.param}</div>
292
+ <div>{staticProp}</div>
293
+ </>
294
+ );
295
+ };
296
+
297
+ <MyComp param={dynamic()} other={static} />;
298
+ ```
299
+
300
+ `props.children` may be a node, a function, a string, or an array of those. Non-expression children evaluate lazily on access.
301
+
302
+ ## Fragments
303
+
304
+ `<></>` compiles to arrays.
305
+
306
+ ## Acknowledgements
307
+
308
+ The concept of compiling JSX to DOM operations (rather than HTML strings) was inspired by [Surplus](https://github.com/adamhaile/surplus).