@solidjs/babel-plugin 2.0.0-rc.7 → 2.0.0-rc.8

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.
@@ -7,4 +7,4 @@ src/shared/transform.ts -> src/ssr/element.ts -> src/shared/transform.ts
7
7
  src/shared/transform.ts -> src/universal/element.ts -> src/shared/transform.ts
8
8
  src/shared/transform.ts -> src/shared/component.ts -> src/shared/transform.ts
9
9
  src/shared/transform.ts -> src/shared/fragment.ts -> src/shared/transform.ts
10
- created index.js in 2s
10
+ created index.js in 2.7s
package/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # @solidjs/babel-plugin
2
2
 
3
+ ## 2.0.0-rc.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 01ac18c: Compiler `componentNames` option: component owner labels that survive minification. With the flag on, DOM output carries the tag as written in source as a third `createComponent` argument — `<Home />` compiles to `createComponent(Home, props, "Home")`, `<Ui.Button />` to `"Ui.Button"`, `<this.Row />` to `"this.Row"` — and the dev and observe runtimes label the component's owner with it (`<Home>` in diagnostic `ownerPath`s, attribution chains, and the devtools `_component.name`), falling back to `Comp.name` as before. Until now an observe-tier production bundle reported hot scopes and holds under whatever the minifier left of the function name (`<Xt> › <Kn>`), and a `lazy()` or HMR wrapper hid the tag name even in dev. Off by default and byte-identical output when off; SSR (which inlines the call) and universal output never emit it; the production `createComponent` ignores the argument. Both compilers implement it in parity (shared fixtures, cross-mode ratchet). `@solidjs/vite-plugin` enables it for the dev and `observe` postures.
8
+ - 7d985b6: Fix SSR XSS: strings yielded by flow-control memos rendered unescaped
9
+
10
+ `<Show when={s}>{s}</Show>`, `<For>{v => v}</For>`, `<Dynamic component={() => s} />`,
11
+ `<Switch>/<Match>`, boundary fallbacks and any component that returns a string through a
12
+ memo rendered that string raw on the server. The server flow controls return memos for
13
+ hydration-id alignment; `escape()` passed functions through by identity, and the resolver
14
+ appended whatever they later produced without escaping.
15
+
16
+ One rule now: `escape(x)` at a hole covers everything reachable from `x` — strings, array
17
+ items, and what a function yields when the resolver calls it (a deferred-escape wrapper).
18
+ Finished `{ t }` nodes pass through. `Loading` escapes its content the way it already
19
+ escaped its fallback. The compilers stop wrapping fragment / mixed component children in
20
+ `_$escape` (they are values; escaping them too double-escaped through
21
+ `<Comp>{props.children}</Comp>`), and a single-expression fragment at a hole keeps the
22
+ hole's wrap. Live-hole tags ride the wrapper and `$slot` survives the array copy, so
23
+ frames behave as before.
24
+
25
+ - ab4c40c: Object-valued `style` / `class` bindings are read in the TRACKED half of their effect. `style()` and `className()` enumerate their object in the effect's untracked commit phase, so a proxy value — a store sub-object (`style={state.style}`, `class={row.classes}`), merged props, anything arriving through a spread — was identity-reactive only: in-place key mutations never re-applied, and every leaf read tripped `STRICT_READ_UNTRACKED` in dev. Both compilers now wrap the compute value of a non-inline `style={expr}` / `class={expr}` in a new compiler primitive, `readShallow()`, and `spread()` applies it to those two keys as it copies. `readShallow` is an identity passthrough for strings, plain objects and proxy-free arrays (a fresh literal is already the compute's own — the common case pays a `typeof`); a proxy is copied with one `ownKeys` trap (its own trap keeps the key set tracked) plus one tracked read per key; arrays are re-mapped only when an element is a proxy. Inline literals are untouched — they already compile per property. Provably-string expressions (string/template literals, concatenation) and literal objects/arrays skip the wrap at compile time. New Tier-1 bench `style-class-object`: plain-object rows at parity; store-backed rows go from identity-only (and, in dev, ~97 ms per 500 elements of diagnostics) to per-key reactive at ~3.5 ms. Octane svg-dashboard (prod build, store-backed style/attrs through spread): mount at parity, style_spread_pulse −6%, select_toggle −7%.
26
+
27
+ `spread()` shares the same enumeration: its compute half copied the source with `for…in` + `hasOwn`, which on a proxy source (`merge()`/`omit()`, `{...props}` in a component, store records — nearly every spread) is an `ownKeys` trap plus two `getOwnPropertyDescriptor` traps per key, each allocating a descriptor and a getter closure. It now takes the key set from one `Reflect.ownKeys` trap (the trap keeps the key set tracked) and reads each string key once; plain sources use `Object.keys`, the exact own-enumerable set the old loop yielded. New Tier-1 bench `spread-enumerate` (500 elements, 8 keys): `merge(static, reactive)` 376 → 537 ops/s (+43%), store record 253 → 415 ops/s (+64%), plain object at parity.
28
+
3
29
  ## 2.0.0-rc.7
4
30
 
5
31
  ### Patch Changes
package/README.md CHANGED
@@ -120,6 +120,20 @@ Source syntax frontend. `"auto"` routes `.tsrx` files through the TSRX frontend
120
120
 
121
121
  Emit hydratable markers.
122
122
 
123
+ ### dev
124
+
125
+ - Type: `boolean`
126
+ - Default: `false`
127
+
128
+ Development output. With `hydratable`, emits the hydration walk validation helpers.
129
+
130
+ ### componentNames
131
+
132
+ - Type: `boolean`
133
+ - Default: `false`
134
+
135
+ DOM output only. Emit the tag as written in source as a third `createComponent` argument — `<Home />` compiles to `createComponent(Home, props, "Home")`, `<Ui.Button />` to `"Ui.Button"` — so the dev and observe runtimes label each component's owner (`<Home>` in diagnostic `ownerPath`s and attribution chains) even after a minifier renames the function or a `lazy()`/HMR wrapper hides it. The production runtime ignores the argument; SSR and universal output are unaffected. `@solidjs/vite-plugin` turns this on for its dev and `observe` postures.
136
+
123
137
  ### delegateEvents
124
138
 
125
139
  - Type: `boolean`
package/index.js CHANGED
@@ -2952,6 +2952,32 @@ function registerTemplate(path, results) {
2952
2952
  results.decl = t__namespace.variableDeclaration("var", results.declarations);
2953
2953
  }
2954
2954
 
2955
+ /** A non-inline object-valued `style` / `class` binding is read in the TRACKED
2956
+ * half of its effect through `readShallow()`: `style()`/`className()` enumerate
2957
+ * their object in the untracked commit phase, so a proxy value (a store
2958
+ * sub-object, merged props) would be identity-reactive only. Skipped when the
2959
+ * expression is provably a string or a fresh literal (`readShallow` would pass
2960
+ * those through anyway; the call is what's saved). */
2961
+ function wrapReadShallow(path, key, value) {
2962
+ if (key !== "class" && key !== "style") return value;
2963
+ if (
2964
+ t__namespace.isStringLiteral(value) ||
2965
+ t__namespace.isTemplateLiteral(value) ||
2966
+ t__namespace.isBinaryExpression(value) ||
2967
+ t__namespace.isObjectExpression(value) ||
2968
+ // a class array of literals cannot hold a proxy either
2969
+ t__namespace.isArrayExpression(value) &&
2970
+ value.elements.every(
2971
+ (e) => t__namespace.isStringLiteral(e) || t__namespace.isTemplateLiteral(e) || t__namespace.isObjectExpression(e)
2972
+ ))
2973
+
2974
+ return value;
2975
+ return t__namespace.callExpression(
2976
+ registerImportMethod(path, "readShallow", getRendererConfig(path, "dom").moduleName),
2977
+ [value]
2978
+ );
2979
+ }
2980
+
2955
2981
  function wrapDynamics$1(path, dynamics) {
2956
2982
  if (!dynamics.length) return;
2957
2983
  const config = getConfig(path);
@@ -2975,7 +3001,7 @@ function wrapDynamics$1(path, dynamics) {
2975
3001
  const newValue = t__namespace.identifier("_v$");
2976
3002
  return t__namespace.expressionStatement(
2977
3003
  t__namespace.callExpression(effectWrapperId, [
2978
- wrapForEffect(dynamics[0].value),
3004
+ wrapForEffect(wrapReadShallow(path, dynamics[0].key, dynamics[0].value)),
2979
3005
  t__namespace.arrowFunctionExpression(
2980
3006
  prevValue ? [newValue, prevValue] : [newValue],
2981
3007
  t__namespace.blockStatement([
@@ -3010,7 +3036,7 @@ function wrapDynamics$1(path, dynamics) {
3010
3036
  }
3011
3037
 
3012
3038
  properties.push(propIdent);
3013
- values.push(t__namespace.objectProperty(propIdent, value));
3039
+ values.push(t__namespace.objectProperty(propIdent, wrapReadShallow(path, key, value)));
3014
3040
 
3015
3041
  if (key === "class" || key === "style" || isStatefulDOMProperty(tagName, key)) {
3016
3042
  statements.push(
@@ -3465,9 +3491,8 @@ escapeLiterals)
3465
3491
  expression.wontEscape = true;
3466
3492
  return expression;
3467
3493
  } else if (t.isJSXFragment(expression) && fragmentWillSelfEscape(expression)) {
3468
- // The fragment will later be transformed into a runtime value the
3469
- // `escape` helper passes through unchanged — either a memoized
3470
- // accessor function or an `_$ssr(...)` SSRNode object (see
3494
+ // The fragment will later be transformed into an `_$ssr(...)` SSRNode
3495
+ // object the `escape` helper passes through unchanged (see
3471
3496
  // `fragmentWillSelfEscape`). Wrapping it in another `_$escape(...)`
3472
3497
  // here would be a guaranteed no-op, so leave the fragment in place
3473
3498
  // and let the later traversal emit the inner form directly.
@@ -3495,23 +3520,16 @@ function escapeTemplateQuasis(expression, attr) {
3495
3520
  // Predicts whether a JSXFragment AST will compile to a single runtime
3496
3521
  // value for which the outer `_$escape(...)` wrap is a no-op. Must stay
3497
3522
  // conservative: any shape this returns `true` for must, when later
3498
- // transformed, produce a self-escaping (or escape-immune) runtime value.
3499
- // When in doubt, return false so the outer `_$escape` wrap is kept.
3523
+ // transformed, produce an escape-immune runtime value. When in doubt,
3524
+ // return false so the outer `_$escape` wrap is kept.
3525
+ //
3526
+ // The one recognized shape is `<><native /></>` — a single native
3527
+ // (non-component) JSXElement, whose `createTemplate` output is
3528
+ // `_$ssr(_tmpl$N, …)`: an SSRNode object `escape` passes through.
3500
3529
  //
3501
- // Recognized single-significant-child shapes:
3502
- // A. `<>{memberOrCall}</>` — a `JSXExpressionContainer` whose
3503
- // expression matches the top-level subset of
3504
- // `isDynamic({ checkMember: true })` (member access, call, tagged
3505
- // template, optional variants, `in` checks). `createTemplate`
3506
- // emits `_$memo(() => _$escape(expr))`; the memo returns a
3507
- // function accessor at runtime and `escape(fn)` is a pass-through.
3508
- // Nested-dynamic shapes (conditional/logical carrying dynamic
3509
- // sub-expressions) are excluded — confirming them needs the full
3510
- // `isDynamic` traversal and a missed optimization costs only one
3511
- // runtime no-op call.
3512
- // B. `<><native /></>` — a single native (non-component) JSXElement.
3513
- // `createTemplate` emits `_$ssr(_tmpl$N, …)`, which returns an
3514
- // SSRNode object; `escape(object)` is a pass-through.
3530
+ // A single expression child (`<>{x()}</>`) is NOT immune: it compiles to a
3531
+ // memo the runtime's `escape` defers into (a function's yield is content
3532
+ // like any other), so the hole must keep its wrap.
3515
3533
  function fragmentWillSelfEscape(fragment) {
3516
3534
  let only = null;
3517
3535
  for (const c of fragment.children) {
@@ -3521,25 +3539,10 @@ function fragmentWillSelfEscape(fragment) {
3521
3539
  }
3522
3540
  if (t__namespace.isJSXExpressionContainer(c) && t__namespace.isJSXEmptyExpression(c.expression))
3523
3541
  continue;
3524
- if (only !== null) return false;
3525
- if (t__namespace.isJSXElement(c) || t__namespace.isJSXExpressionContainer(c)) only = c;else
3526
- return false;
3527
- }
3528
- if (!only) return false;
3529
- if (t__namespace.isJSXExpressionContainer(only)) {
3530
- const expr = only.expression;
3531
- if (t__namespace.isJSXEmptyExpression(expr)) return false;
3532
- return (
3533
- t.isCallExpression(expr) ||
3534
- t.isOptionalCallExpression(expr) ||
3535
- t.isTaggedTemplateExpression(expr) ||
3536
- t.isMemberExpression(expr) ||
3537
- t.isOptionalMemberExpression(expr) ||
3538
- t__namespace.isBinaryExpression(expr) && expr.operator === "in");
3539
-
3542
+ if (only !== null || !t__namespace.isJSXElement(c)) return false;
3543
+ only = c;
3540
3544
  }
3541
- if (t__namespace.isJSXElement(only)) return !isComponent(getTagName(only));
3542
- return false;
3545
+ return only !== null && !isComponent(getTagName(only));
3543
3546
  }
3544
3547
 
3545
3548
  function normalizeAttributes(path) {
@@ -4139,31 +4142,6 @@ path,
4139
4142
  return { exprs, template: "", declarations: [], dynamics: [], spreadElement: true };
4140
4143
  }
4141
4144
 
4142
- // Wrap the *inner* value of a fragment-child accessor with `_$escape` so that
4143
- // hostile string values returned from reactive accessors cannot be
4144
- // concatenated raw into the SSR output. Element-child expressions already get
4145
- // this treatment via `escapeExpression` in `ssr/element.js`; fragment
4146
- // children reach SSR via a different code path and would otherwise skip the
4147
- // escape step.
4148
- //
4149
- // `expr` is the first entry of `result.exprs` produced by `transformNode`
4150
- // for a `JSXExpressionContainer`. It is either:
4151
- // - an arrow function `() => X` (default case)
4152
- // - a bare callee (`fnRef`, emitted when the expression is `fnRef()` with
4153
- // no args — see the JSXExpressionContainer branch in shared/transform.js)
4154
- // - the result of `transformCondition(..., inline=true)`, which also
4155
- // returns an arrow function
4156
- // For arrows with an expression body we rewrite in place; for anything else
4157
- // we conservatively wrap in a new arrow that calls and escapes.
4158
- function wrapFragmentChildWithEscape(path, expr) {
4159
- const escape = registerImportMethod(path, "escape", undefined);
4160
- if (t__namespace.isArrowFunctionExpression(expr) && !t__namespace.isBlockStatement(expr.body)) {
4161
- expr.body = t__namespace.callExpression(escape, [expr.body]);
4162
- return expr;
4163
- }
4164
- return t__namespace.arrowFunctionExpression([], t__namespace.callExpression(escape, [t__namespace.callExpression(expr, [])]));
4165
- }
4166
-
4167
4145
  function createTemplate$1(
4168
4146
  path,
4169
4147
  result,
@@ -4171,19 +4149,16 @@ wrap)
4171
4149
  {
4172
4150
  if (!result.template) {
4173
4151
  // `wrap` is true for fragment children and for mixed component children.
4174
- // A sole component child (`wrap === false`) is a value passed to the
4175
- // callee — do not `_$escape` it here; the callee's insert/SSR sites
4176
- // escape when interpolating into HTML. Escaping both layers double-escapes.
4152
+ // Both are VALUES — they flow to whatever hole eventually inserts them,
4153
+ // and that hole's `_$escape` covers everything reachable from the value:
4154
+ // strings, array items, and what a function (this memo) yields when the
4155
+ // resolver calls it. Escaping here as well double-escapes through
4156
+ // `<Comp>{props.children}</Comp>`. The memo exists for hydration-id
4157
+ // alignment with the client, not for escaping.
4177
4158
  if (wrap && result.dynamic && getConfig(path).memoWrapper) {
4178
- // wontEscape is set on JSXElement children whose compiled form is
4179
- // already a safe SSR node (e.g. `_$ssr(...)` call). Wrapping those in
4180
- // escape would be a no-op at runtime but obscures intent — skip it.
4181
- const inner = result.wontEscape ?
4182
- result.exprs[0] :
4183
- wrapFragmentChildWithEscape(path, result.exprs[0]);
4184
4159
  return t__namespace.callExpression(
4185
4160
  registerImportMethod(path, getConfig(path).memoWrapper, undefined),
4186
- [inner]
4161
+ [result.exprs[0]]
4187
4162
  );
4188
4163
  }
4189
4164
  return result.exprs[0];
@@ -4940,11 +4915,24 @@ node)
4940
4915
  return t__namespace.stringLiteral(`${node.namespace.name}:${node.name.name}`);
4941
4916
  }
4942
4917
 
4918
+ /**
4919
+ * The tag as written in source (`Home`, `Ui.Button`, `this.Row`) — the label
4920
+ * `componentNames` emits. Read before `convertComponentIdentifier` since that
4921
+ * retypes the JSX identifier nodes in place.
4922
+ */
4923
+ function jsxTagName(node) {
4924
+ if (t__namespace.isJSXIdentifier(node)) return thisTagIdentifiers.has(node) ? "this" : node.name;
4925
+ if (t__namespace.isJSXMemberExpression(node))
4926
+ return `${jsxTagName(node.object)}.${jsxTagName(node.property)}`;
4927
+ return `${node.namespace.name}:${node.name.name}`;
4928
+ }
4929
+
4943
4930
  function transformComponent(
4944
4931
  path)
4945
4932
  {
4946
4933
  let exprs = [],
4947
4934
  config = getConfig(path),
4935
+ tagName = jsxTagName(path.node.openingElement.name),
4948
4936
  tagId = convertComponentIdentifier(path.node.openingElement.name),
4949
4937
  props = [],
4950
4938
  runningObject = [],
@@ -5213,13 +5201,20 @@ path)
5213
5201
  props = [t__namespace.callExpression(registerImportMethod(path, "mergeProps"), props)];
5214
5202
  }
5215
5203
  const componentArgs = [tagId, props[0]];
5204
+ // `componentNames` carries the source tag name into the call so the
5205
+ // dev/observe runtimes can label the owner after minification renames the
5206
+ // function. DOM output only: SSR inlines the call below and the universal
5207
+ // renderer's `createComponent` is user code with a two-argument contract.
5208
+ if (config.componentNames && config.generate === "dom") {
5209
+ componentArgs.push(t__namespace.stringLiteral(tagName));
5210
+ }
5216
5211
  // SSR's `createComponent` is literally `Comp(props || {})`. Since the
5217
5212
  // compiler always emits a real `props[0]` object expression above (see the
5218
5213
  // `props.push(t.objectExpression(runningObject))` line), the `|| {}` fallback
5219
5214
  // never fires in compiled output. Inline to a direct `Comp(props)` call to
5220
5215
  // drop one function-call frame per component invocation. (DOM/dev modes
5221
5216
  // keep the wrapper since it does real work — `untrack`, dev metadata.)
5222
- if (getConfig(path).generate === "ssr") {
5217
+ if (config.generate === "ssr") {
5223
5218
  exprs.push(t__namespace.callExpression(tagId, [props[0]]));
5224
5219
  } else {
5225
5220
  exprs.push(t__namespace.callExpression(registerImportMethod(path, "createComponent"), componentArgs));
@@ -5411,6 +5406,13 @@ function getTargetFunctionParent(path, parent) {
5411
5406
  return current;
5412
5407
  }
5413
5408
 
5409
+ /**
5410
+ * JSX tag identifiers `transformThis` rewrote from `this` to the `_self$`
5411
+ * capture, so `componentNames` can label `<this.Row />` by its source text
5412
+ * rather than the generated uid.
5413
+ */
5414
+ const thisTagIdentifiers = new WeakSet();
5415
+
5414
5416
  function transformThis(path) {
5415
5417
  const parent = path.scope.getFunctionParent();
5416
5418
  let thisId, inserted;
@@ -5431,7 +5433,9 @@ function transformThis(path) {
5431
5433
  const current = getTargetFunctionParent(path, parent);
5432
5434
  if (current === parent) {
5433
5435
  thisId || (thisId = path.scope.generateUidIdentifier("self$"));
5434
- source.replaceWith(t__namespace.jsxIdentifier(thisId.name));
5436
+ const selfTag = t__namespace.jsxIdentifier(thisId.name);
5437
+ thisTagIdentifiers.add(selfTag);
5438
+ source.replaceWith(selfTag);
5435
5439
 
5436
5440
  if (path.node.closingElement) {
5437
5441
  path.node.closingElement.name = path.node.openingElement.name;
@@ -14264,6 +14268,7 @@ const config = {
14264
14268
  generate: "dom",
14265
14269
  hydratable: false,
14266
14270
  dev: false,
14271
+ componentNames: false,
14267
14272
  delegateEvents: true,
14268
14273
  delegatedEvents: [],
14269
14274
  builtIns: [
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@solidjs/babel-plugin",
3
3
  "description": "Babel compiler plugin for Solid templates",
4
- "version": "2.0.0-rc.7",
4
+ "version": "2.0.0-rc.8",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -24,8 +24,7 @@
24
24
  "@babel/plugin-syntax-jsx": "^7.18.6",
25
25
  "@babel/types": "^7.20.7",
26
26
  "html-entities": "2.3.3",
27
- "parse5": "^7.1.2",
28
- "validate-html-nesting": "^1.2.1"
27
+ "parse5": "^7.1.2"
29
28
  },
30
29
  "peerDependencies": {
31
30
  "@babel/core": "^7.20.12",