@tsrx/solid 0.1.2 → 0.1.4
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.
- package/package.json +2 -2
- package/src/transform.js +24 -3
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.1.
|
|
6
|
+
"version": "0.1.4",
|
|
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.1.
|
|
29
|
+
"@tsrx/core": "0.1.4"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"solid-js": ">=1.8 || >=2.0.0-beta"
|
package/src/transform.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
captureJsxChild,
|
|
22
22
|
CREATE_REF_PROP_INTERNAL_NAME,
|
|
23
23
|
NORMALIZE_SPREAD_PROPS_INTERNAL_NAME,
|
|
24
|
+
returnValueBodyToExpression as return_value_body_to_expression,
|
|
24
25
|
tsxNodeToJsxExpression as tsx_node_to_jsx_expression,
|
|
25
26
|
// Shared AST builders (truly platform-agnostic utilities).
|
|
26
27
|
clone_expression_node,
|
|
@@ -454,6 +455,20 @@ function tsrx_node_to_jsx_expression(node, transform_context, in_jsx_child = fal
|
|
|
454
455
|
(child.type !== 'JSXText' || child.value.trim() !== ''),
|
|
455
456
|
);
|
|
456
457
|
|
|
458
|
+
const returned_expression = return_value_body_to_expression(children, node, transform_context);
|
|
459
|
+
if (returned_expression) {
|
|
460
|
+
if (
|
|
461
|
+
in_jsx_child &&
|
|
462
|
+
returned_expression.type !== 'JSXElement' &&
|
|
463
|
+
returned_expression.type !== 'JSXFragment' &&
|
|
464
|
+
returned_expression.type !== 'JSXText' &&
|
|
465
|
+
returned_expression.type !== 'JSXExpressionContainer'
|
|
466
|
+
) {
|
|
467
|
+
return to_jsx_expression_container(returned_expression, node);
|
|
468
|
+
}
|
|
469
|
+
return returned_expression;
|
|
470
|
+
}
|
|
471
|
+
|
|
457
472
|
let expression = body_to_jsx_child(children, transform_context);
|
|
458
473
|
if (is_branch_arrow(expression)) {
|
|
459
474
|
expression = b.call(expression);
|
|
@@ -509,7 +524,7 @@ function body_to_jsx_child(body_nodes, transform_context) {
|
|
|
509
524
|
const statements = [];
|
|
510
525
|
/** @type {any[]} */
|
|
511
526
|
const children = [];
|
|
512
|
-
let
|
|
527
|
+
let has_terminal_return = false;
|
|
513
528
|
let capture_index = 0;
|
|
514
529
|
for (const child of body_nodes) {
|
|
515
530
|
if (is_bare_return_statement(child)) {
|
|
@@ -522,7 +537,13 @@ function body_to_jsx_child(body_nodes, transform_context) {
|
|
|
522
537
|
loc: child.loc,
|
|
523
538
|
});
|
|
524
539
|
children.length = 0;
|
|
525
|
-
|
|
540
|
+
has_terminal_return = true;
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (child?.type === 'ReturnStatement' && child.argument != null) {
|
|
545
|
+
statements.push(child);
|
|
546
|
+
has_terminal_return = true;
|
|
526
547
|
continue;
|
|
527
548
|
}
|
|
528
549
|
|
|
@@ -557,7 +578,7 @@ function body_to_jsx_child(body_nodes, transform_context) {
|
|
|
557
578
|
// statements run when (and only when) the branch actually renders.
|
|
558
579
|
/** @type {any[]} */
|
|
559
580
|
const block_body = [...statements];
|
|
560
|
-
if (children.length > 0 || !
|
|
581
|
+
if (children.length > 0 || !has_terminal_return) {
|
|
561
582
|
block_body.push(
|
|
562
583
|
/** @type {any} */ ({
|
|
563
584
|
type: 'ReturnStatement',
|