@tsrx/vue 0.4.7 → 0.4.8
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 +3 -3
- package/src/transform.js +67 -4
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.
|
|
6
|
+
"version": "0.4.8",
|
|
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.6.
|
|
46
|
-
"@tsrx/vue-runtime": "0.2.
|
|
45
|
+
"@tsrx/core": "0.6.8",
|
|
46
|
+
"@tsrx/vue-runtime": "0.2.4"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"vue": ">=3.6.0-0",
|
package/src/transform.js
CHANGED
|
@@ -229,7 +229,10 @@ const vue_platform = {
|
|
|
229
229
|
);
|
|
230
230
|
},
|
|
231
231
|
injectImports(program, ctx) {
|
|
232
|
-
if (!ctx.typeOnly)
|
|
232
|
+
if (!ctx.typeOnly) {
|
|
233
|
+
render_element_ifs_as_directives(program);
|
|
234
|
+
place_boundaries_as_children(program);
|
|
235
|
+
}
|
|
233
236
|
wrap_native_function_components(program, ctx);
|
|
234
237
|
inject_vue_imports(program, ctx);
|
|
235
238
|
},
|
|
@@ -322,7 +325,7 @@ function create_module_scoped_error_fallback_component(catch_body_nodes, catch_p
|
|
|
322
325
|
* @returns {AST.ArrowFunctionExpression}
|
|
323
326
|
*/
|
|
324
327
|
function create_error_boundary_slot(content, fallback_fn, source_try) {
|
|
325
|
-
const boundary = create_vapor_error_boundary(content, clone_ast_node(fallback_fn, false));
|
|
328
|
+
const boundary = create_vapor_error_boundary(content, clone_ast_node(fallback_fn, false), true);
|
|
326
329
|
return b.arrow(
|
|
327
330
|
[],
|
|
328
331
|
setLocation(boundary, has_location(source_try) ? source_try : undefined, true),
|
|
@@ -383,7 +386,7 @@ function jsx_child_to_expression(child) {
|
|
|
383
386
|
* @param {AST.ArrowFunctionExpression} fallback_fn
|
|
384
387
|
* @returns {AST.TSRXJSXElement}
|
|
385
388
|
*/
|
|
386
|
-
function create_vapor_error_boundary(content, fallback_fn) {
|
|
389
|
+
function create_vapor_error_boundary(content, fallback_fn, shares_catch = false) {
|
|
387
390
|
return b.jsx_element_fresh(
|
|
388
391
|
b.jsx_opening_element(
|
|
389
392
|
b.jsx_id(ERROR_BOUNDARY_INTERNAL_NAME),
|
|
@@ -393,6 +396,9 @@ function create_vapor_error_boundary(content, fallback_fn) {
|
|
|
393
396
|
b.jsx_id('content'),
|
|
394
397
|
to_jsx_expression_container(b.arrow([], jsx_child_to_expression(content))),
|
|
395
398
|
),
|
|
399
|
+
// The boundary around it renders the same `@catch`: an error that
|
|
400
|
+
// `@catch` throws goes past both.
|
|
401
|
+
...(shares_catch ? [b.jsx_attribute(b.jsx_id('sharesCatch'))] : []),
|
|
396
402
|
],
|
|
397
403
|
true,
|
|
398
404
|
),
|
|
@@ -1795,7 +1801,8 @@ function get_function_component_name(fn, parent) {
|
|
|
1795
1801
|
}
|
|
1796
1802
|
|
|
1797
1803
|
if (parent?.type === 'Property' && parent.value === fn) {
|
|
1798
|
-
|
|
1804
|
+
// A getter or setter is no component, and a call can't take its place.
|
|
1805
|
+
return parent.kind === 'init' ? get_static_name(parent.key) : null;
|
|
1799
1806
|
}
|
|
1800
1807
|
|
|
1801
1808
|
if (parent?.type === 'AssignmentExpression' && parent.right === fn) {
|
|
@@ -2259,6 +2266,62 @@ function render_element_ifs_as_directives(program) {
|
|
|
2259
2266
|
program.body = walked.body;
|
|
2260
2267
|
}
|
|
2261
2268
|
|
|
2269
|
+
/**
|
|
2270
|
+
* Puts the boundary a `@try` renders among an element's or fragment's
|
|
2271
|
+
* children as a child element, where the shared lowering puts it in an
|
|
2272
|
+
* expression container (`{<__TsrxErrorBoundary … />}`). vue-jsx-vapor renders
|
|
2273
|
+
* an expression child through a text placeholder, which can't hydrate a
|
|
2274
|
+
* component: Vue stops with "No current hydration node was found", and the
|
|
2275
|
+
* body no longer updates. A child component hydrates.
|
|
2276
|
+
*
|
|
2277
|
+
* @param {AST.Program} program
|
|
2278
|
+
*/
|
|
2279
|
+
function place_boundaries_as_children(program) {
|
|
2280
|
+
/**
|
|
2281
|
+
* @param {ESTreeJSX.JSXElement['children']} children
|
|
2282
|
+
* @returns {ESTreeJSX.JSXElement['children'] | null}
|
|
2283
|
+
*/
|
|
2284
|
+
const place = (children) => {
|
|
2285
|
+
let changed = false;
|
|
2286
|
+
const placed = children.map((child) => {
|
|
2287
|
+
if (
|
|
2288
|
+
child.type === 'JSXExpressionContainer' &&
|
|
2289
|
+
child.expression.type === 'JSXElement' &&
|
|
2290
|
+
child.expression.openingElement.name.type === 'JSXIdentifier' &&
|
|
2291
|
+
child.expression.openingElement.name.name === ERROR_BOUNDARY_INTERNAL_NAME
|
|
2292
|
+
) {
|
|
2293
|
+
changed = true;
|
|
2294
|
+
return /** @type {ESTreeJSX.JSXElement} */ (child.expression);
|
|
2295
|
+
}
|
|
2296
|
+
return child;
|
|
2297
|
+
});
|
|
2298
|
+
return changed ? placed : null;
|
|
2299
|
+
};
|
|
2300
|
+
const walked = /** @type {AST.Program} */ (
|
|
2301
|
+
walk(/** @type {AST.Node} */ (program), null, {
|
|
2302
|
+
JSXElement(node, { next }) {
|
|
2303
|
+
const element = /** @type {ESTreeJSX.JSXElement} */ (
|
|
2304
|
+
/** @type {unknown} */ (next() ?? node)
|
|
2305
|
+
);
|
|
2306
|
+
const children = place(element.children);
|
|
2307
|
+
return children
|
|
2308
|
+
? /** @type {AST.Node} */ (/** @type {unknown} */ ({ ...element, children }))
|
|
2309
|
+
: undefined;
|
|
2310
|
+
},
|
|
2311
|
+
JSXFragment(node, { next }) {
|
|
2312
|
+
const fragment = /** @type {ESTreeJSX.JSXFragment} */ (
|
|
2313
|
+
/** @type {unknown} */ (next() ?? node)
|
|
2314
|
+
);
|
|
2315
|
+
const children = place(fragment.children);
|
|
2316
|
+
return children
|
|
2317
|
+
? /** @type {AST.Node} */ (/** @type {unknown} */ ({ ...fragment, children }))
|
|
2318
|
+
: undefined;
|
|
2319
|
+
},
|
|
2320
|
+
})
|
|
2321
|
+
);
|
|
2322
|
+
program.body = walked.body;
|
|
2323
|
+
}
|
|
2324
|
+
|
|
2262
2325
|
/**
|
|
2263
2326
|
* Whether the first element in `siblings`, the children after a choice, has
|
|
2264
2327
|
* a `v-else` or `v-else-if`. Anything before it, an expression such as
|