@tsrx/solid 0.0.25 → 0.0.26
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 +50 -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.0.
|
|
6
|
+
"version": "0.0.26",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"esrap": "^2.1.0",
|
|
24
24
|
"zimmerframe": "^1.1.2",
|
|
25
|
-
"@tsrx/core": "0.0.
|
|
25
|
+
"@tsrx/core": "0.0.26"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"solid-js": ">=1.8 || >=2.0.0-beta"
|
package/src/transform.js
CHANGED
|
@@ -233,6 +233,10 @@ function component_to_function_declaration(component, transform_context) {
|
|
|
233
233
|
const collect = (nodes, outer, jsx_bucket) => {
|
|
234
234
|
for (const child of nodes) {
|
|
235
235
|
if (is_jsx_child(child)) {
|
|
236
|
+
if (get_returning_if_info(child) !== null) {
|
|
237
|
+
jsx_bucket.push(child);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
236
240
|
if (early_interleaved) {
|
|
237
241
|
const jsx = to_jsx_child(child, transform_context);
|
|
238
242
|
if (is_capturable_jsx_child(jsx)) {
|
|
@@ -260,11 +264,11 @@ function component_to_function_declaration(component, transform_context) {
|
|
|
260
264
|
transform_context.needs_show = true;
|
|
261
265
|
const branch_body = body_to_jsx_child(early_info.consequent_body, transform_context);
|
|
262
266
|
const fallback_body =
|
|
263
|
-
after_jsx.length > 0 ?
|
|
267
|
+
after_jsx.length > 0 ? body_to_early_return_jsx_child(after_jsx, transform_context) : null;
|
|
264
268
|
next_body.push(build_show_element(early_if.test, branch_body, fallback_body));
|
|
265
269
|
} else if (after_jsx.length > 0) {
|
|
266
270
|
transform_context.needs_show = true;
|
|
267
|
-
const show_body =
|
|
271
|
+
const show_body = body_to_early_return_jsx_child(after_jsx, transform_context);
|
|
268
272
|
next_body.push(build_show_element(negate_expression(early_if.test), show_body, null));
|
|
269
273
|
}
|
|
270
274
|
|
|
@@ -522,6 +526,45 @@ function body_to_jsx_child(body_nodes, transform_context) {
|
|
|
522
526
|
});
|
|
523
527
|
}
|
|
524
528
|
|
|
529
|
+
/**
|
|
530
|
+
* Lower render-continuation bodies that may contain additional early-return
|
|
531
|
+
* guards. Sequential guards need to nest the remaining continuation instead
|
|
532
|
+
* of rendering later children beside a `<Show>` for the guard itself.
|
|
533
|
+
*
|
|
534
|
+
* @param {any[]} body_nodes
|
|
535
|
+
* @param {TransformContext} transform_context
|
|
536
|
+
* @returns {any}
|
|
537
|
+
*/
|
|
538
|
+
function body_to_early_return_jsx_child(body_nodes, transform_context) {
|
|
539
|
+
const early_idx = body_nodes.findIndex((node) => get_returning_if_info(node) !== null);
|
|
540
|
+
if (early_idx === -1) {
|
|
541
|
+
return body_to_jsx_child(body_nodes, transform_context);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
const early_if = /** @type {any} */ (body_nodes[early_idx]);
|
|
545
|
+
const early_info = /** @type {{ consequent_body: any[], return_index: number }} */ (
|
|
546
|
+
get_returning_if_info(early_if)
|
|
547
|
+
);
|
|
548
|
+
const before = body_nodes.slice(0, early_idx);
|
|
549
|
+
const after = body_nodes.slice(early_idx + 1);
|
|
550
|
+
const branch_has_content_before_return = early_info.return_index > 0;
|
|
551
|
+
const children = [...before];
|
|
552
|
+
|
|
553
|
+
if (branch_has_content_before_return) {
|
|
554
|
+
transform_context.needs_show = true;
|
|
555
|
+
const branch_body = body_to_jsx_child(early_info.consequent_body, transform_context);
|
|
556
|
+
const fallback_body =
|
|
557
|
+
after.length > 0 ? body_to_early_return_jsx_child(after, transform_context) : null;
|
|
558
|
+
children.push(build_show_element(early_if.test, branch_body, fallback_body));
|
|
559
|
+
} else if (after.length > 0) {
|
|
560
|
+
transform_context.needs_show = true;
|
|
561
|
+
const show_body = body_to_early_return_jsx_child(after, transform_context);
|
|
562
|
+
children.push(build_show_element(negate_expression(early_if.test), show_body, null));
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return body_to_jsx_child(children, transform_context);
|
|
566
|
+
}
|
|
567
|
+
|
|
525
568
|
/**
|
|
526
569
|
* @param {any} node
|
|
527
570
|
* @returns {boolean}
|
|
@@ -825,11 +868,15 @@ function get_returning_if_info(node) {
|
|
|
825
868
|
* @returns {any}
|
|
826
869
|
*/
|
|
827
870
|
function negate_expression(expr) {
|
|
871
|
+
if (expr?.type === 'UnaryExpression' && expr.operator === '!') {
|
|
872
|
+
return clone_expression_node(expr.argument);
|
|
873
|
+
}
|
|
874
|
+
|
|
828
875
|
return {
|
|
829
876
|
type: 'UnaryExpression',
|
|
830
877
|
operator: '!',
|
|
831
878
|
prefix: true,
|
|
832
|
-
argument: expr,
|
|
879
|
+
argument: clone_expression_node(expr),
|
|
833
880
|
metadata: { path: [] },
|
|
834
881
|
};
|
|
835
882
|
}
|