@tsrx/vue 0.4.10 → 0.4.12

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 +3 -3
  2. package/src/transform.js +60 -1
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Vue compiler built on @tsrx/core",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.4.10",
6
+ "version": "0.4.12",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -42,8 +42,8 @@
42
42
  "esrap": "^2.4.2",
43
43
  "is-reference": "^3.0.3",
44
44
  "zimmerframe": "^1.1.2",
45
- "@tsrx/core": "0.7.0",
46
- "@tsrx/vue-runtime": "0.2.5"
45
+ "@tsrx/core": "0.8.0",
46
+ "@tsrx/vue-runtime": "0.2.6"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "vue": ">=3.6.0-0",
package/src/transform.js CHANGED
@@ -137,6 +137,8 @@ const vue_platform = {
137
137
  // `innerHTML` there as an attribute. `v-html` sets the body as written
138
138
  // when the element is created, and the server renders it as written.
139
139
  scriptBody: 'v-html',
140
+ // vue-jsx-vapor decodes JSX text as HTML and keeps its lines.
141
+ textReading: { lines: 'keep', html: true },
140
142
  },
141
143
  validation: {
142
144
  requireUseServerForAwait: true,
@@ -349,7 +351,7 @@ function create_pending_body(fallback_expression, ctx) {
349
351
  [
350
352
  b.jsx_attribute(
351
353
  b.jsx_id('content'),
352
- to_jsx_expression_container(b.arrow([], fallback_expression)),
354
+ to_jsx_expression_container(b.arrow([], with_reactive_output(fallback_expression))),
353
355
  ),
354
356
  ],
355
357
  true,
@@ -359,6 +361,63 @@ function create_pending_body(fallback_expression, ctx) {
359
361
  );
360
362
  }
361
363
 
364
+ /**
365
+ * A `@pending` body whose output follows what it reads. `TsrxPendingBody`
366
+ * calls its content once, as a component's setup, so output that isn't an
367
+ * element or a fragment, such as the choice of a lone `@if`, a `@switch` or a
368
+ * loop through `map_iterable`, would keep what it rendered first. In a
369
+ * fragment, vue-jsx-vapor renders it reactively: a choice becomes a
370
+ * `createIf`, which switches when its condition does, and anything else is
371
+ * evaluated in an effect. The body's statements still run once.
372
+ *
373
+ * @param {AST.Expression} expression
374
+ * @returns {AST.Expression}
375
+ */
376
+ function with_reactive_output(expression) {
377
+ // The shared lowering's `(() => { …statements; return output; })()`.
378
+ if (
379
+ expression.type === 'CallExpression' &&
380
+ expression.arguments.length === 0 &&
381
+ expression.callee.type === 'ArrowFunctionExpression' &&
382
+ expression.callee.body.type === 'BlockStatement'
383
+ ) {
384
+ const callee = expression.callee;
385
+ const body = /** @type {AST.BlockStatement} */ (callee.body);
386
+ return {
387
+ ...expression,
388
+ callee: {
389
+ ...callee,
390
+ body: {
391
+ ...body,
392
+ body: body.body.map((statement) =>
393
+ statement.type === 'ReturnStatement' && statement.argument
394
+ ? { ...statement, argument: in_fragment_unless_node(statement.argument) }
395
+ : statement,
396
+ ),
397
+ },
398
+ },
399
+ };
400
+ }
401
+ return in_fragment_unless_node(expression);
402
+ }
403
+
404
+ /**
405
+ * @param {AST.Expression} expression
406
+ * @returns {AST.Expression}
407
+ */
408
+ function in_fragment_unless_node(expression) {
409
+ if (
410
+ expression.type === 'JSXElement' ||
411
+ expression.type === 'JSXFragment' ||
412
+ (expression.type === 'Literal' && expression.value === null)
413
+ ) {
414
+ return expression;
415
+ }
416
+ return /** @type {AST.Expression} */ (
417
+ /** @type {unknown} */ (b.jsx_fragment([to_jsx_expression_container(expression)]))
418
+ );
419
+ }
420
+
362
421
  /**
363
422
  * @param {AST.Pattern[]} patterns
364
423
  * @returns {Set<string>}