@tsrx/solid 0.0.28 → 0.1.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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/transform.js +36 -0
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Solid compiler built on @tsrx/core",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.0.28",
6
+ "version": "0.1.0",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -26,7 +26,7 @@
26
26
  "dependencies": {
27
27
  "esrap": "^2.1.0",
28
28
  "zimmerframe": "^1.1.2",
29
- "@tsrx/core": "0.0.28"
29
+ "@tsrx/core": "0.1.0"
30
30
  },
31
31
  "peerDependencies": {
32
32
  "solid-js": ">=1.8 || >=2.0.0-beta"
package/src/transform.js CHANGED
@@ -411,6 +411,8 @@ function to_jsx_child(node, transform_context) {
411
411
  // We're inside a JSX child position by construction; keep `{expr}`
412
412
  // containers wrapped. See helpers.js.
413
413
  return tsx_node_to_jsx_expression(node, true);
414
+ case 'Tsrx':
415
+ return tsrx_node_to_jsx_expression(node, transform_context, true);
414
416
  case 'TsxCompat':
415
417
  return tsx_compat_node_to_jsx_expression(node, transform_context, true);
416
418
  case 'Element':
@@ -436,6 +438,40 @@ function to_jsx_child(node, transform_context) {
436
438
  }
437
439
  }
438
440
 
441
+ /**
442
+ * Lower a `<tsrx>` node's native TSRX template body to a Solid JSX expression.
443
+ *
444
+ * @param {any} node
445
+ * @param {TransformContext} transform_context
446
+ * @param {boolean} [in_jsx_child]
447
+ * @returns {any}
448
+ */
449
+ function tsrx_node_to_jsx_expression(node, transform_context, in_jsx_child = false) {
450
+ const children = (node.children || []).filter(
451
+ (/** @type {any} */ child) =>
452
+ child &&
453
+ child.type !== 'EmptyStatement' &&
454
+ (child.type !== 'JSXText' || child.value.trim() !== ''),
455
+ );
456
+
457
+ let expression = body_to_jsx_child(children, transform_context);
458
+ if (is_branch_arrow(expression)) {
459
+ expression = b.call(expression);
460
+ }
461
+
462
+ if (
463
+ in_jsx_child &&
464
+ expression.type !== 'JSXElement' &&
465
+ expression.type !== 'JSXFragment' &&
466
+ expression.type !== 'JSXText' &&
467
+ expression.type !== 'JSXExpressionContainer'
468
+ ) {
469
+ return to_jsx_expression_container(expression, node);
470
+ }
471
+
472
+ return expression;
473
+ }
474
+
439
475
  /**
440
476
  * Convert a list of body nodes to a Solid JSX child.
441
477
  *