@tsrx/solid 0.1.6 → 0.1.7
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 +20 -21
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.7",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"esrap": "^2.2.7",
|
|
28
28
|
"zimmerframe": "^1.1.2",
|
|
29
|
-
"@tsrx/core": "0.1.
|
|
29
|
+
"@tsrx/core": "0.1.7"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
32
|
"solid-js": ">=1.8 || >=2.0.0-beta"
|
package/src/transform.js
CHANGED
|
@@ -11,9 +11,7 @@ import {
|
|
|
11
11
|
setLocation,
|
|
12
12
|
addJsxSetupDeclaration as add_jsx_setup_declaration,
|
|
13
13
|
applyLazyTransforms as apply_lazy_transforms,
|
|
14
|
-
collectLazyBindingsFromComponent as collect_lazy_bindings_from_component,
|
|
15
14
|
extractJsxSetupDeclarations as extract_jsx_setup_declarations,
|
|
16
|
-
replaceLazyParams as replace_lazy_params,
|
|
17
15
|
rewriteLoopContinuesToBareReturns as rewrite_loop_continues_to_bare_returns,
|
|
18
16
|
isRefPropExpression as is_ref_prop_expression,
|
|
19
17
|
isInterleavedBody as is_interleaved_body_core,
|
|
@@ -237,12 +235,6 @@ function component_to_function_declaration(component, transform_context, walk_he
|
|
|
237
235
|
}
|
|
238
236
|
transform_context.available_bindings = body_bindings;
|
|
239
237
|
|
|
240
|
-
// In type-only mode the lazy rewrite is skipped so destructuring patterns
|
|
241
|
-
// survive into the virtual TSX and TypeScript can flow real types.
|
|
242
|
-
const lazy_bindings = transform_context.typeOnly
|
|
243
|
-
? new Map()
|
|
244
|
-
: collect_lazy_bindings_from_component(params, body, transform_context);
|
|
245
|
-
|
|
246
238
|
// Detect top-level early-return patterns such as `if (cond) { return; }`
|
|
247
239
|
// and `if (cond) { <p />; return; }`.
|
|
248
240
|
// Solid components run their body once at setup, so an early `return` would
|
|
@@ -368,30 +360,37 @@ function component_to_function_declaration(component, transform_context, walk_he
|
|
|
368
360
|
statements.push(b.return(build_return_expression(render_nodes) || b.literal(null)));
|
|
369
361
|
}
|
|
370
362
|
|
|
371
|
-
const final_params = lazy_bindings.size > 0 ? replace_lazy_params(params) : params;
|
|
372
|
-
|
|
373
363
|
const body_block = b.block(statements);
|
|
374
|
-
const final_body =
|
|
375
|
-
lazy_bindings.size > 0 ? apply_lazy_transforms(body_block, lazy_bindings) : body_block;
|
|
376
364
|
|
|
377
365
|
/** @type {AST.FunctionDeclaration | AST.FunctionExpression | AST.ArrowFunctionExpression} */
|
|
378
366
|
let fn;
|
|
379
367
|
|
|
380
368
|
if (component.id) {
|
|
381
|
-
fn = b.function_declaration(
|
|
382
|
-
component.id,
|
|
383
|
-
final_params,
|
|
384
|
-
final_body,
|
|
385
|
-
false,
|
|
386
|
-
component.typeParameters,
|
|
387
|
-
);
|
|
369
|
+
fn = b.function_declaration(component.id, params, body_block, false, component.typeParameters);
|
|
388
370
|
} else if (component.metadata?.arrow) {
|
|
389
|
-
fn = b.arrow(
|
|
371
|
+
fn = b.arrow(params, body_block, false, component.typeParameters);
|
|
390
372
|
} else {
|
|
391
|
-
fn = b.function(null,
|
|
373
|
+
fn = b.function(null, params, body_block, false, component.typeParameters);
|
|
392
374
|
}
|
|
393
375
|
fn.metadata.is_component = true;
|
|
394
376
|
|
|
377
|
+
// `preallocate_lazy_ids` stamped `has_lazy_descendants` on the source
|
|
378
|
+
// `Component` node; the freshly-built `fn` shares the same params/body
|
|
379
|
+
// subtree, so propagate the flag so the function-handler's early-return
|
|
380
|
+
// path can fire for non-lazy components.
|
|
381
|
+
if (/** @type {any} */ (component).metadata?.has_lazy_descendants) {
|
|
382
|
+
/** @type {any} */ (fn.metadata).has_lazy_descendants = true;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Apply lazy `&{}` / `&[]` rewrites end-to-end via the function-handler in
|
|
386
|
+
// `apply_lazy_transforms`. Constant-time fast-path for functions whose
|
|
387
|
+
// subtrees contain no lazy patterns (flagged ahead of time by
|
|
388
|
+
// `preallocate_lazy_ids`). In type-only mode the rewrite is skipped so
|
|
389
|
+
// destructuring patterns survive into the virtual TSX.
|
|
390
|
+
if (!transform_context.typeOnly) {
|
|
391
|
+
fn = /** @type {typeof fn} */ (apply_lazy_transforms(fn, new Map()));
|
|
392
|
+
}
|
|
393
|
+
|
|
395
394
|
if (fn.type === 'FunctionDeclaration' && fn.id) {
|
|
396
395
|
fn.id.metadata = /** @type {AST.Identifier['metadata']} */ ({
|
|
397
396
|
...fn.id.metadata,
|