@tsrx/vue 0.1.46 → 0.1.47
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 +257 -211
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.1.
|
|
6
|
+
"version": "0.1.47",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"esrap": "^2.3.0",
|
|
39
39
|
"is-reference": "^3.0.3",
|
|
40
40
|
"zimmerframe": "^1.1.2",
|
|
41
|
-
"@tsrx/core": "0.1.
|
|
41
|
+
"@tsrx/core": "0.1.47"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"vue": ">=3.5",
|
package/src/transform.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
/** @import
|
|
1
|
+
/** @import * as AST from 'estree' */
|
|
2
|
+
/** @import * as ESTreeJSX from 'estree-jsx' */
|
|
3
|
+
/** @import { JsxHelperComponent, JsxPlatform, JsxTransformContext as TransformContext } from '@tsrx/core/types' */
|
|
2
4
|
|
|
3
5
|
import { walk } from 'zimmerframe';
|
|
4
6
|
import is_reference from 'is-reference';
|
|
5
7
|
import {
|
|
6
8
|
builders as b,
|
|
7
9
|
addJsxSetupDeclaration,
|
|
8
|
-
|
|
10
|
+
clone_ast_node,
|
|
9
11
|
clone_identifier,
|
|
10
12
|
contains_component_jsx,
|
|
11
13
|
createHookSafeHelper,
|
|
12
14
|
create_generated_identifier,
|
|
13
15
|
createJsxTransform,
|
|
14
16
|
error,
|
|
17
|
+
has_location,
|
|
15
18
|
is_component_like_element,
|
|
16
19
|
MERGE_REFS_INTERNAL_NAME,
|
|
17
20
|
NORMALIZE_SPREAD_PROPS_FOR_REF_ATTR_INTERNAL_NAME,
|
|
18
21
|
NORMALIZE_SPREAD_PROPS_INTERNAL_NAME,
|
|
19
22
|
setLocation,
|
|
20
|
-
toJsxAttribute,
|
|
21
23
|
} from '@tsrx/core';
|
|
22
24
|
|
|
23
25
|
/**
|
|
@@ -78,11 +80,10 @@ const vue_platform = {
|
|
|
78
80
|
return preprocess_ref_attributes(attrs, ctx);
|
|
79
81
|
},
|
|
80
82
|
transformElementAttributes(attrs, ctx, element) {
|
|
81
|
-
const result = attrs.map((attr) => toJsxAttribute(attr, ctx));
|
|
82
83
|
if (!ctx.typeOnly || is_component_like_element(element)) {
|
|
83
|
-
return
|
|
84
|
+
return attrs;
|
|
84
85
|
}
|
|
85
|
-
return
|
|
86
|
+
return attrs.map(mark_type_only_host_ref_attribute);
|
|
86
87
|
},
|
|
87
88
|
renderForOf: (node, loop_params, body_statements, ctx) =>
|
|
88
89
|
render_for_of_as_vapor_for(node, loop_params, body_statements, ctx),
|
|
@@ -102,7 +103,7 @@ const vue_platform = {
|
|
|
102
103
|
if (!node.pending) {
|
|
103
104
|
return null;
|
|
104
105
|
}
|
|
105
|
-
const fallback_content =
|
|
106
|
+
const fallback_content = try_content.metadata?.vapor_pending_fallback;
|
|
106
107
|
if (!fallback_content) {
|
|
107
108
|
return create_vapor_error_boundary(try_content, fallback_fn);
|
|
108
109
|
}
|
|
@@ -154,9 +155,9 @@ const vue_platform = {
|
|
|
154
155
|
export const transform = createJsxTransform(vue_platform);
|
|
155
156
|
|
|
156
157
|
/**
|
|
157
|
-
* @param {
|
|
158
|
-
* @param {
|
|
159
|
-
* @returns {
|
|
158
|
+
* @param {ESTreeJSX.JSXRenderNode} try_content
|
|
159
|
+
* @param {ESTreeJSX.JSXRenderNode} fallback_content
|
|
160
|
+
* @returns {ESTreeJSX.JSXElement}
|
|
160
161
|
*/
|
|
161
162
|
function create_vapor_pending_boundary(try_content, fallback_content) {
|
|
162
163
|
return create_vapor_pending_boundary_from_default_slot(
|
|
@@ -166,9 +167,9 @@ function create_vapor_pending_boundary(try_content, fallback_content) {
|
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
/**
|
|
169
|
-
* @param {
|
|
170
|
-
* @param {
|
|
171
|
-
* @returns {
|
|
170
|
+
* @param {AST.ArrowFunctionExpression} default_slot
|
|
171
|
+
* @param {ESTreeJSX.JSXRenderNode} fallback_content
|
|
172
|
+
* @returns {ESTreeJSX.JSXElement}
|
|
172
173
|
*/
|
|
173
174
|
function create_vapor_pending_boundary_from_default_slot(default_slot, fallback_content) {
|
|
174
175
|
const fallback_expression = jsx_child_to_expression(fallback_content);
|
|
@@ -189,16 +190,16 @@ function create_vapor_pending_boundary_from_default_slot(default_slot, fallback_
|
|
|
189
190
|
null,
|
|
190
191
|
[],
|
|
191
192
|
);
|
|
192
|
-
|
|
193
|
+
boundary.metadata.vapor_pending_fallback = fallback_content;
|
|
193
194
|
return boundary;
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
/**
|
|
197
|
-
* @param {
|
|
198
|
-
* @param {
|
|
199
|
-
* @param {
|
|
200
|
-
* @param {
|
|
201
|
-
* @returns {
|
|
198
|
+
* @param {AST.Statement[]} catch_body_nodes
|
|
199
|
+
* @param {AST.Pattern[]} catch_params
|
|
200
|
+
* @param {TransformContext} ctx
|
|
201
|
+
* @param {AST.TryStatement} node
|
|
202
|
+
* @returns {JsxHelperComponent}
|
|
202
203
|
*/
|
|
203
204
|
function create_module_scoped_error_fallback_component(catch_body_nodes, catch_params, ctx, node) {
|
|
204
205
|
const saved_module_scoped = ctx.module_scoped_hook_components;
|
|
@@ -217,12 +218,12 @@ function create_module_scoped_error_fallback_component(catch_body_nodes, catch_p
|
|
|
217
218
|
* Suspense can still observe async children while `catch` handles immediate
|
|
218
219
|
* render failures.
|
|
219
220
|
*
|
|
220
|
-
* @param {
|
|
221
|
-
* @param {
|
|
222
|
-
* @param {
|
|
223
|
-
* @param {
|
|
224
|
-
* @param {
|
|
225
|
-
* @returns {
|
|
221
|
+
* @param {ESTreeJSX.JSXRenderNode} content
|
|
222
|
+
* @param {AST.ArrowFunctionExpression} fallback_fn
|
|
223
|
+
* @param {JsxHelperComponent | null} fallback_component
|
|
224
|
+
* @param {AST.BlockStatement} source_block
|
|
225
|
+
* @param {AST.TryStatement} source_try
|
|
226
|
+
* @returns {AST.ArrowFunctionExpression}
|
|
226
227
|
*/
|
|
227
228
|
function create_sync_error_boundary_slot(
|
|
228
229
|
content,
|
|
@@ -239,7 +240,11 @@ function create_sync_error_boundary_slot(
|
|
|
239
240
|
b.arrow([], b.block([])),
|
|
240
241
|
])
|
|
241
242
|
: b.call(b.parenthesized(fallback_fn), clone_identifier(error_id), b.arrow([], b.block([])));
|
|
242
|
-
const try_block = setLocation(
|
|
243
|
+
const try_block = setLocation(
|
|
244
|
+
b.block([b.return(content_expression)]),
|
|
245
|
+
has_location(source_block) ? source_block : undefined,
|
|
246
|
+
true,
|
|
247
|
+
);
|
|
243
248
|
const try_statement = setLocation(
|
|
244
249
|
b.try(
|
|
245
250
|
try_block,
|
|
@@ -247,32 +252,33 @@ function create_sync_error_boundary_slot(
|
|
|
247
252
|
null,
|
|
248
253
|
null,
|
|
249
254
|
),
|
|
250
|
-
source_try,
|
|
255
|
+
has_location(source_try) ? source_try : undefined,
|
|
251
256
|
true,
|
|
252
257
|
);
|
|
253
258
|
return b.arrow([], b.block([try_statement]));
|
|
254
259
|
}
|
|
255
260
|
|
|
256
261
|
/**
|
|
257
|
-
* @param {
|
|
258
|
-
* @param {
|
|
259
|
-
* @returns {
|
|
262
|
+
* @param {JsxHelperComponent} fallback_component
|
|
263
|
+
* @param {AST.ArrowFunctionExpression} fallback_fn
|
|
264
|
+
* @returns {AST.ArrowFunctionExpression}
|
|
260
265
|
*/
|
|
261
266
|
function create_fallback_component_renderer(fallback_component, fallback_fn) {
|
|
262
267
|
return b.arrow(
|
|
263
|
-
fallback_fn.params.map((
|
|
268
|
+
fallback_fn.params.map((param) => clone_ast_node(param, false)),
|
|
264
269
|
b.block([b.return(create_fallback_component_element(fallback_component, fallback_fn))]),
|
|
265
270
|
);
|
|
266
271
|
}
|
|
267
272
|
|
|
268
273
|
/**
|
|
269
|
-
* @param {
|
|
270
|
-
* @param {
|
|
271
|
-
* @param {
|
|
272
|
-
* @returns {
|
|
274
|
+
* @param {JsxHelperComponent} fallback_component
|
|
275
|
+
* @param {AST.ArrowFunctionExpression} fallback_fn
|
|
276
|
+
* @param {AST.Expression[]} [replacement_args]
|
|
277
|
+
* @returns {ESTreeJSX.JSXElement}
|
|
273
278
|
*/
|
|
274
279
|
function create_fallback_component_element(fallback_component, fallback_fn, replacement_args = []) {
|
|
275
|
-
const element =
|
|
280
|
+
const element = clone_ast_node(fallback_component.component_element, false);
|
|
281
|
+
/** @type {Map<string, AST.Expression>} */
|
|
276
282
|
const replacements = new Map();
|
|
277
283
|
for (let i = 0; i < fallback_fn.params.length && i < replacement_args.length; i += 1) {
|
|
278
284
|
const param = fallback_fn.params[i];
|
|
@@ -282,16 +288,20 @@ function create_fallback_component_element(fallback_component, fallback_fn, repl
|
|
|
282
288
|
}
|
|
283
289
|
|
|
284
290
|
for (const attr of element.openingElement?.attributes ?? []) {
|
|
285
|
-
|
|
291
|
+
if (attr.type !== 'JSXAttribute' || attr.name.type !== 'JSXIdentifier') continue;
|
|
292
|
+
const attr_name = attr.name.name;
|
|
286
293
|
if (!attr_name || !replacements.has(attr_name)) continue;
|
|
287
|
-
attr.value = to_jsx_expression_container(
|
|
294
|
+
attr.value = to_jsx_expression_container(
|
|
295
|
+
/** @type {AST.Expression} */ (replacements.get(attr_name)),
|
|
296
|
+
attr.value ?? attr,
|
|
297
|
+
);
|
|
288
298
|
}
|
|
289
299
|
|
|
290
300
|
return element;
|
|
291
301
|
}
|
|
292
302
|
|
|
293
303
|
/**
|
|
294
|
-
* @param {
|
|
304
|
+
* @param {AST.Pattern[]} patterns
|
|
295
305
|
* @returns {Set<string>}
|
|
296
306
|
*/
|
|
297
307
|
function get_pattern_names(patterns) {
|
|
@@ -303,17 +313,19 @@ function get_pattern_names(patterns) {
|
|
|
303
313
|
}
|
|
304
314
|
|
|
305
315
|
/**
|
|
306
|
-
* @param {
|
|
307
|
-
* @returns {
|
|
316
|
+
* @param {ESTreeJSX.JSXRenderNode} child
|
|
317
|
+
* @returns {AST.Expression}
|
|
308
318
|
*/
|
|
309
319
|
function jsx_child_to_expression(child) {
|
|
310
|
-
return child
|
|
320
|
+
return child.type === 'JSXExpressionContainer'
|
|
321
|
+
? /** @type {AST.Expression} */ (child.expression)
|
|
322
|
+
: /** @type {AST.Expression} */ (child);
|
|
311
323
|
}
|
|
312
324
|
|
|
313
325
|
/**
|
|
314
|
-
* @param {
|
|
315
|
-
* @param {
|
|
316
|
-
* @returns {
|
|
326
|
+
* @param {ESTreeJSX.JSXRenderNode} content
|
|
327
|
+
* @param {AST.ArrowFunctionExpression} fallback_fn
|
|
328
|
+
* @returns {ESTreeJSX.JSXElement}
|
|
317
329
|
*/
|
|
318
330
|
function create_vapor_error_boundary(content, fallback_fn) {
|
|
319
331
|
return b.jsx_element_fresh(
|
|
@@ -339,8 +351,8 @@ function create_vapor_error_boundary(content, fallback_fn) {
|
|
|
339
351
|
* expression unchanged but stop TypeScript verification from reporting that
|
|
340
352
|
* Vue-specific assignability diagnostic on the generated `ref` prop token.
|
|
341
353
|
*
|
|
342
|
-
* @param {
|
|
343
|
-
* @returns {
|
|
354
|
+
* @param {ESTreeJSX.JSXAttributeNode} attr
|
|
355
|
+
* @returns {ESTreeJSX.JSXAttributeNode}
|
|
344
356
|
*/
|
|
345
357
|
function mark_type_only_host_ref_attribute(attr) {
|
|
346
358
|
if (
|
|
@@ -352,16 +364,16 @@ function mark_type_only_host_ref_attribute(attr) {
|
|
|
352
364
|
return attr;
|
|
353
365
|
}
|
|
354
366
|
|
|
355
|
-
const name = b.jsx_id(attr.name.name, attr.name);
|
|
367
|
+
const name = b.jsx_id(attr.name.name, has_location(attr.name) ? attr.name : undefined);
|
|
356
368
|
name.metadata = { ...(attr.name.metadata || {}), disable_verification: true };
|
|
357
|
-
return b.jsx_attribute(name, attr.value, attr.shorthand, attr);
|
|
369
|
+
return b.jsx_attribute(name, attr.value, attr.shorthand, has_location(attr) ? attr : undefined);
|
|
358
370
|
}
|
|
359
371
|
|
|
360
372
|
/**
|
|
361
|
-
* @param {
|
|
362
|
-
* @param {
|
|
363
|
-
* @param {
|
|
364
|
-
* @returns {
|
|
373
|
+
* @param {AST.FunctionDeclaration} helper_fn
|
|
374
|
+
* @param {AST.Identifier} helper_id
|
|
375
|
+
* @param {AST.NodeWithLocation | undefined} source_node
|
|
376
|
+
* @returns {AST.VariableDeclaration}
|
|
365
377
|
*/
|
|
366
378
|
function wrap_helper_component(helper_fn, helper_id, source_node) {
|
|
367
379
|
return setLocation(
|
|
@@ -376,33 +388,39 @@ function wrap_helper_component(helper_fn, helper_id, source_node) {
|
|
|
376
388
|
}
|
|
377
389
|
|
|
378
390
|
/**
|
|
379
|
-
* @param {
|
|
380
|
-
* @param {
|
|
391
|
+
* @param {AST.Program} program
|
|
392
|
+
* @param {TransformContext} ctx
|
|
381
393
|
* @returns {void}
|
|
382
394
|
*/
|
|
383
395
|
function wrap_native_function_components(program, ctx) {
|
|
384
396
|
const wrapped = walk(program, ctx, {
|
|
385
397
|
FunctionDeclaration(node, { next, path, state }) {
|
|
386
398
|
const inner = next() ?? node;
|
|
387
|
-
return
|
|
399
|
+
return (
|
|
400
|
+
wrap_native_function_component(/** @type {AST.Function} */ (inner), state, path) ?? inner
|
|
401
|
+
);
|
|
388
402
|
},
|
|
389
403
|
FunctionExpression(node, { next, path, state }) {
|
|
390
404
|
const inner = next() ?? node;
|
|
391
|
-
return
|
|
405
|
+
return (
|
|
406
|
+
wrap_native_function_component(/** @type {AST.Function} */ (inner), state, path) ?? inner
|
|
407
|
+
);
|
|
392
408
|
},
|
|
393
409
|
ArrowFunctionExpression(node, { next, path, state }) {
|
|
394
410
|
const inner = next() ?? node;
|
|
395
|
-
return
|
|
411
|
+
return (
|
|
412
|
+
wrap_native_function_component(/** @type {AST.Function} */ (inner), state, path) ?? inner
|
|
413
|
+
);
|
|
396
414
|
},
|
|
397
415
|
});
|
|
398
|
-
program.body = wrapped.body;
|
|
416
|
+
program.body = /** @type {AST.Program} */ (wrapped).body;
|
|
399
417
|
}
|
|
400
418
|
|
|
401
419
|
/**
|
|
402
|
-
* @param {
|
|
403
|
-
* @param {
|
|
404
|
-
* @param {
|
|
405
|
-
* @returns {
|
|
420
|
+
* @param {AST.Function} fn
|
|
421
|
+
* @param {TransformContext} ctx
|
|
422
|
+
* @param {AST.Node[]} path
|
|
423
|
+
* @returns {AST.Expression | AST.VariableDeclaration | null}
|
|
406
424
|
*/
|
|
407
425
|
function wrap_native_function_component(fn, ctx, path) {
|
|
408
426
|
if (!fn.metadata?.native_tsrx_function) {
|
|
@@ -423,7 +441,7 @@ function wrap_native_function_component(fn, ctx, path) {
|
|
|
423
441
|
fn.metadata?.generated_helpers || [],
|
|
424
442
|
fn.metadata?.generated_statics || [],
|
|
425
443
|
),
|
|
426
|
-
fn,
|
|
444
|
+
has_location(fn) ? fn : undefined,
|
|
427
445
|
true,
|
|
428
446
|
);
|
|
429
447
|
|
|
@@ -441,18 +459,18 @@ function wrap_native_function_component(fn, ctx, path) {
|
|
|
441
459
|
|
|
442
460
|
return setLocation(
|
|
443
461
|
b.declaration('const', [b.declarator(create_generated_identifier(fn.id.name), call)]),
|
|
444
|
-
fn,
|
|
462
|
+
has_location(fn) ? fn : undefined,
|
|
445
463
|
true,
|
|
446
464
|
);
|
|
447
465
|
}
|
|
448
466
|
|
|
449
467
|
/**
|
|
450
|
-
* @param {
|
|
451
|
-
* @param {
|
|
468
|
+
* @param {AST.Function} fn
|
|
469
|
+
* @param {AST.Node | undefined} parent
|
|
452
470
|
* @returns {string | null}
|
|
453
471
|
*/
|
|
454
472
|
function get_function_component_name(fn, parent) {
|
|
455
|
-
if (fn.id?.type === 'Identifier') {
|
|
473
|
+
if (fn.type !== 'ArrowFunctionExpression' && fn.id?.type === 'Identifier') {
|
|
456
474
|
return fn.id.name;
|
|
457
475
|
}
|
|
458
476
|
|
|
@@ -472,7 +490,7 @@ function get_function_component_name(fn, parent) {
|
|
|
472
490
|
}
|
|
473
491
|
|
|
474
492
|
/**
|
|
475
|
-
* @param {
|
|
493
|
+
* @param {AST.Node | undefined} node
|
|
476
494
|
* @returns {string | null}
|
|
477
495
|
*/
|
|
478
496
|
function get_static_name(node) {
|
|
@@ -489,14 +507,14 @@ function get_static_name(node) {
|
|
|
489
507
|
}
|
|
490
508
|
|
|
491
509
|
/**
|
|
492
|
-
* @param {
|
|
493
|
-
* @param {
|
|
494
|
-
* @param {
|
|
495
|
-
* @returns {
|
|
510
|
+
* @param {AST.FunctionExpression | AST.ArrowFunctionExpression} fn_expression
|
|
511
|
+
* @param {AST.Statement[]} generated_helpers
|
|
512
|
+
* @param {AST.Statement[]} generated_statics
|
|
513
|
+
* @returns {AST.CallExpression}
|
|
496
514
|
*/
|
|
497
515
|
function create_define_vapor_component_call(fn_expression, generated_helpers, generated_statics) {
|
|
498
516
|
const call = b.call('defineVaporComponent', fn_expression);
|
|
499
|
-
Object.assign(
|
|
517
|
+
Object.assign(call.metadata, {
|
|
500
518
|
generated_helpers,
|
|
501
519
|
generated_statics,
|
|
502
520
|
});
|
|
@@ -504,11 +522,11 @@ function create_define_vapor_component_call(fn_expression, generated_helpers, ge
|
|
|
504
522
|
}
|
|
505
523
|
|
|
506
524
|
/**
|
|
507
|
-
* @param {
|
|
508
|
-
* @param {
|
|
509
|
-
* @param {
|
|
510
|
-
* @param {
|
|
511
|
-
* @returns {
|
|
525
|
+
* @param {AST.ForOfStatement} node
|
|
526
|
+
* @param {AST.Pattern[]} loop_params
|
|
527
|
+
* @param {AST.Statement[]} body_statements
|
|
528
|
+
* @param {TransformContext} transform_context
|
|
529
|
+
* @returns {ESTreeJSX.JSXExpressionContainer | null}
|
|
512
530
|
*/
|
|
513
531
|
function render_for_of_as_vapor_for(node, loop_params, body_statements, transform_context) {
|
|
514
532
|
if (node.empty) {
|
|
@@ -530,9 +548,8 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
|
|
|
530
548
|
}
|
|
531
549
|
|
|
532
550
|
const key_expression = node.key
|
|
533
|
-
?
|
|
534
|
-
: (find_jsx_key_expression(rendered) ??
|
|
535
|
-
(node.index ? clone_expression_node(node.index) : null));
|
|
551
|
+
? clone_ast_node(node.key)
|
|
552
|
+
: (find_jsx_key_expression(rendered) ?? (node.index ? clone_ast_node(node.index) : null));
|
|
536
553
|
|
|
537
554
|
const slot = key_expression
|
|
538
555
|
? create_keyed_vapor_for_slot(loop_params, rendered)
|
|
@@ -548,7 +565,7 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
|
|
|
548
565
|
}
|
|
549
566
|
|
|
550
567
|
const attributes = [
|
|
551
|
-
b.jsx_attribute(b.jsx_id('in'), to_jsx_expression_container(
|
|
568
|
+
b.jsx_attribute(b.jsx_id('in'), to_jsx_expression_container(clone_ast_node(node.right))),
|
|
552
569
|
];
|
|
553
570
|
|
|
554
571
|
if (key_expression) {
|
|
@@ -570,15 +587,15 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
|
|
|
570
587
|
}
|
|
571
588
|
|
|
572
589
|
/**
|
|
573
|
-
* @param {
|
|
574
|
-
* @param {
|
|
575
|
-
* @param {
|
|
576
|
-
* @returns {
|
|
590
|
+
* @param {AST.ForOfStatement} node
|
|
591
|
+
* @param {AST.Pattern[]} loop_params
|
|
592
|
+
* @param {AST.Expression} rendered
|
|
593
|
+
* @returns {ESTreeJSX.JSXExpressionContainer}
|
|
577
594
|
*/
|
|
578
595
|
function render_for_of_as_flat_map(node, loop_params, rendered) {
|
|
579
596
|
return to_jsx_expression_container(
|
|
580
597
|
b.call(
|
|
581
|
-
b.member(
|
|
598
|
+
b.member(clone_ast_node(node.right), 'flatMap'),
|
|
582
599
|
b.arrow(loop_params, b.block([b.return(to_array_render_expression(rendered))])),
|
|
583
600
|
),
|
|
584
601
|
);
|
|
@@ -588,7 +605,7 @@ function render_for_of_as_flat_map(node, loop_params, rendered) {
|
|
|
588
605
|
* Loop bodies that can return `null` need the shared callback lowering so
|
|
589
606
|
* `continue` truly skips the iteration.
|
|
590
607
|
*
|
|
591
|
-
* @param {
|
|
608
|
+
* @param {AST.Node} node
|
|
592
609
|
* @returns {boolean}
|
|
593
610
|
*/
|
|
594
611
|
function expression_can_skip_rendering(node) {
|
|
@@ -615,8 +632,8 @@ function expression_can_skip_rendering(node) {
|
|
|
615
632
|
}
|
|
616
633
|
|
|
617
634
|
/**
|
|
618
|
-
* @param {
|
|
619
|
-
* @returns {
|
|
635
|
+
* @param {AST.Expression} node
|
|
636
|
+
* @returns {AST.Expression}
|
|
620
637
|
*/
|
|
621
638
|
function to_array_render_expression(node) {
|
|
622
639
|
if (node?.type === 'Literal' && node.value === null) {
|
|
@@ -639,8 +656,8 @@ function to_array_render_expression(node) {
|
|
|
639
656
|
}
|
|
640
657
|
|
|
641
658
|
/**
|
|
642
|
-
* @param {
|
|
643
|
-
* @returns {
|
|
659
|
+
* @param {AST.Expression} node
|
|
660
|
+
* @returns {AST.Expression | null}
|
|
644
661
|
*/
|
|
645
662
|
function find_jsx_key_expression(node) {
|
|
646
663
|
if (node?.type !== 'JSXElement') {
|
|
@@ -653,9 +670,13 @@ function find_jsx_key_expression(node) {
|
|
|
653
670
|
attr.name?.type === 'JSXIdentifier' &&
|
|
654
671
|
attr.name.name === 'key'
|
|
655
672
|
) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
673
|
+
if (
|
|
674
|
+
attr.value?.type === 'JSXExpressionContainer' &&
|
|
675
|
+
attr.value.expression.type !== 'JSXEmptyExpression'
|
|
676
|
+
) {
|
|
677
|
+
return clone_ast_node(attr.value.expression);
|
|
678
|
+
}
|
|
679
|
+
return attr.value?.type === 'Literal' ? clone_ast_node(attr.value) : null;
|
|
659
680
|
}
|
|
660
681
|
}
|
|
661
682
|
|
|
@@ -663,13 +684,13 @@ function find_jsx_key_expression(node) {
|
|
|
663
684
|
}
|
|
664
685
|
|
|
665
686
|
/**
|
|
666
|
-
* @param {
|
|
687
|
+
* @param {AST.Node} node
|
|
667
688
|
* @returns {void}
|
|
668
689
|
*/
|
|
669
690
|
function strip_top_level_jsx_keys(node) {
|
|
670
691
|
if (node?.type === 'JSXElement') {
|
|
671
692
|
node.openingElement.attributes = (node.openingElement.attributes || []).filter(
|
|
672
|
-
(
|
|
693
|
+
(attr) =>
|
|
673
694
|
!(
|
|
674
695
|
attr.type === 'JSXAttribute' &&
|
|
675
696
|
attr.name?.type === 'JSXIdentifier' &&
|
|
@@ -687,14 +708,14 @@ function strip_top_level_jsx_keys(node) {
|
|
|
687
708
|
}
|
|
688
709
|
|
|
689
710
|
/**
|
|
690
|
-
* @param {
|
|
691
|
-
* @param {
|
|
711
|
+
* @param {AST.Pattern[]} loop_params
|
|
712
|
+
* @param {AST.Expression} body
|
|
692
713
|
* @param {boolean} expression
|
|
693
|
-
* @returns {
|
|
714
|
+
* @returns {AST.ArrowFunctionExpression}
|
|
694
715
|
*/
|
|
695
716
|
function create_loop_callback(loop_params, body, expression) {
|
|
696
717
|
const callback = b.arrow(
|
|
697
|
-
loop_params.map((param) =>
|
|
718
|
+
loop_params.map((param) => clone_ast_node(param)),
|
|
698
719
|
body,
|
|
699
720
|
);
|
|
700
721
|
callback.expression = expression;
|
|
@@ -702,9 +723,9 @@ function create_loop_callback(loop_params, body, expression) {
|
|
|
702
723
|
}
|
|
703
724
|
|
|
704
725
|
/**
|
|
705
|
-
* @param {
|
|
706
|
-
* @param {
|
|
707
|
-
* @returns {{ params:
|
|
726
|
+
* @param {AST.Pattern[]} loop_params
|
|
727
|
+
* @param {AST.Expression} rendered
|
|
728
|
+
* @returns {{ params: AST.Pattern[], body: AST.Expression, expression: boolean } | null}
|
|
708
729
|
*/
|
|
709
730
|
function create_keyed_vapor_for_slot(loop_params, rendered) {
|
|
710
731
|
if (loop_params[0]?.type === 'Identifier') {
|
|
@@ -741,10 +762,10 @@ function create_keyed_vapor_for_slot(loop_params, rendered) {
|
|
|
741
762
|
* receive shallow refs so row instances can update in place. Match that runtime
|
|
742
763
|
* shape by reading loop params through `.value` inside the slot body.
|
|
743
764
|
*
|
|
744
|
-
* @param {
|
|
745
|
-
* @param {
|
|
746
|
-
* @param {Map<string,
|
|
747
|
-
* @returns {
|
|
765
|
+
* @param {AST.Expression} node
|
|
766
|
+
* @param {AST.Pattern[]} loop_params
|
|
767
|
+
* @param {Map<string, AST.Expression>} [replacements]
|
|
768
|
+
* @returns {AST.Expression}
|
|
748
769
|
*/
|
|
749
770
|
function rewrite_vapor_for_keyed_slot_refs(node, loop_params, replacements = new Map()) {
|
|
750
771
|
const loop_param_names = new Set();
|
|
@@ -756,38 +777,40 @@ function rewrite_vapor_for_keyed_slot_refs(node, loop_params, replacements = new
|
|
|
756
777
|
return node;
|
|
757
778
|
}
|
|
758
779
|
|
|
759
|
-
return
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
780
|
+
return /** @type {AST.Expression} */ (
|
|
781
|
+
walk(
|
|
782
|
+
node,
|
|
783
|
+
{ loop_param_names, shadowed_names: new Set() },
|
|
784
|
+
{
|
|
785
|
+
Identifier(identifier, { path, state, next }) {
|
|
786
|
+
const parent = path.at(-1);
|
|
787
|
+
if (
|
|
788
|
+
(state.loop_param_names.has(identifier.name) || replacements.has(identifier.name)) &&
|
|
789
|
+
!state.shadowed_names.has(identifier.name) &&
|
|
790
|
+
parent &&
|
|
791
|
+
is_runtime_reference(identifier, parent)
|
|
792
|
+
) {
|
|
793
|
+
const replacement = replacements.get(identifier.name);
|
|
794
|
+
if (replacement) {
|
|
795
|
+
return clone_ast_node(replacement);
|
|
796
|
+
}
|
|
797
|
+
return create_value_member_expression(identifier);
|
|
774
798
|
}
|
|
775
|
-
return create_value_member_expression(identifier);
|
|
776
|
-
}
|
|
777
799
|
|
|
778
|
-
|
|
800
|
+
return next();
|
|
801
|
+
},
|
|
802
|
+
FunctionDeclaration: rewrite_function_shadowed_refs,
|
|
803
|
+
FunctionExpression: rewrite_function_shadowed_refs,
|
|
804
|
+
ArrowFunctionExpression: rewrite_function_shadowed_refs,
|
|
805
|
+
BlockStatement: rewrite_block_shadowed_refs,
|
|
779
806
|
},
|
|
780
|
-
|
|
781
|
-
FunctionExpression: rewrite_function_shadowed_refs,
|
|
782
|
-
ArrowFunctionExpression: rewrite_function_shadowed_refs,
|
|
783
|
-
BlockStatement: rewrite_block_shadowed_refs,
|
|
784
|
-
},
|
|
807
|
+
)
|
|
785
808
|
);
|
|
786
809
|
}
|
|
787
810
|
|
|
788
811
|
/**
|
|
789
|
-
* @param {
|
|
790
|
-
* @param {
|
|
812
|
+
* @param {AST.Identifier} identifier
|
|
813
|
+
* @param {AST.Node} parent
|
|
791
814
|
* @returns {boolean}
|
|
792
815
|
*/
|
|
793
816
|
function is_runtime_reference(identifier, parent) {
|
|
@@ -795,25 +818,28 @@ function is_runtime_reference(identifier, parent) {
|
|
|
795
818
|
return parent.expression === identifier;
|
|
796
819
|
}
|
|
797
820
|
if (parent.type === 'JSXAttribute') {
|
|
798
|
-
return
|
|
821
|
+
return (
|
|
822
|
+
parent.value?.type === 'JSXExpressionContainer' && parent.value.expression === identifier
|
|
823
|
+
);
|
|
799
824
|
}
|
|
800
825
|
return is_reference(identifier, parent);
|
|
801
826
|
}
|
|
802
827
|
|
|
803
828
|
/**
|
|
804
|
-
* @param {
|
|
805
|
-
* @param {
|
|
806
|
-
* @returns {Map<string,
|
|
829
|
+
* @param {AST.Pattern} pattern
|
|
830
|
+
* @param {AST.Expression} source
|
|
831
|
+
* @returns {Map<string, AST.Expression> | null}
|
|
807
832
|
*/
|
|
808
833
|
function create_pattern_replacements(pattern, source) {
|
|
834
|
+
/** @type {Map<string, AST.Expression>} */
|
|
809
835
|
const replacements = new Map();
|
|
810
836
|
return collect_pattern_replacements(pattern, source, replacements) ? replacements : null;
|
|
811
837
|
}
|
|
812
838
|
|
|
813
839
|
/**
|
|
814
|
-
* @param {
|
|
815
|
-
* @param {
|
|
816
|
-
* @param {Map<string,
|
|
840
|
+
* @param {AST.Pattern | null} pattern
|
|
841
|
+
* @param {AST.Expression} source
|
|
842
|
+
* @param {Map<string, AST.Expression>} replacements
|
|
817
843
|
* @returns {boolean}
|
|
818
844
|
*/
|
|
819
845
|
function collect_pattern_replacements(pattern, source, replacements) {
|
|
@@ -861,13 +887,13 @@ function collect_pattern_replacements(pattern, source, replacements) {
|
|
|
861
887
|
}
|
|
862
888
|
|
|
863
889
|
/**
|
|
864
|
-
* @param {
|
|
865
|
-
* @param {
|
|
866
|
-
* @returns {
|
|
890
|
+
* @param {AST.Function} node
|
|
891
|
+
* @param {import('zimmerframe').Context<AST.Node, { loop_param_names: Set<string>, shadowed_names: Set<string> }>} context
|
|
892
|
+
* @returns {AST.Node | void}
|
|
867
893
|
*/
|
|
868
894
|
function rewrite_function_shadowed_refs(node, { state, next }) {
|
|
869
895
|
const shadowed_names = new Set(state.shadowed_names);
|
|
870
|
-
if (node.id) {
|
|
896
|
+
if (node.type !== 'ArrowFunctionExpression' && node.id) {
|
|
871
897
|
collect_pattern_names(node.id, shadowed_names);
|
|
872
898
|
}
|
|
873
899
|
for (const param of node.params || []) {
|
|
@@ -878,9 +904,9 @@ function rewrite_function_shadowed_refs(node, { state, next }) {
|
|
|
878
904
|
}
|
|
879
905
|
|
|
880
906
|
/**
|
|
881
|
-
* @param {
|
|
882
|
-
* @param {
|
|
883
|
-
* @returns {
|
|
907
|
+
* @param {AST.BlockStatement} node
|
|
908
|
+
* @param {import('zimmerframe').Context<AST.Node, { loop_param_names: Set<string>, shadowed_names: Set<string> }>} context
|
|
909
|
+
* @returns {AST.Node | void}
|
|
884
910
|
*/
|
|
885
911
|
function rewrite_block_shadowed_refs(node, { state, next }) {
|
|
886
912
|
const shadowed_names = new Set(state.shadowed_names);
|
|
@@ -889,7 +915,7 @@ function rewrite_block_shadowed_refs(node, { state, next }) {
|
|
|
889
915
|
}
|
|
890
916
|
|
|
891
917
|
/**
|
|
892
|
-
* @param {
|
|
918
|
+
* @param {AST.Statement[]} statements
|
|
893
919
|
* @param {Set<string>} names
|
|
894
920
|
* @returns {void}
|
|
895
921
|
*/
|
|
@@ -912,7 +938,7 @@ function collect_block_lexical_names(statements, names) {
|
|
|
912
938
|
}
|
|
913
939
|
|
|
914
940
|
/**
|
|
915
|
-
* @param {
|
|
941
|
+
* @param {AST.Node | AST.Node[]} node
|
|
916
942
|
* @param {Set<string>} names
|
|
917
943
|
* @returns {void}
|
|
918
944
|
*/
|
|
@@ -942,16 +968,26 @@ function collect_function_var_names(node, names) {
|
|
|
942
968
|
}
|
|
943
969
|
}
|
|
944
970
|
|
|
945
|
-
|
|
971
|
+
const traversable = /** @type {AST.TraversableAstNode} */ (node);
|
|
972
|
+
for (const key of Object.keys(traversable)) {
|
|
946
973
|
if (key === 'loc' || key === 'start' || key === 'end' || key === 'metadata') {
|
|
947
974
|
continue;
|
|
948
975
|
}
|
|
949
|
-
|
|
976
|
+
const value = traversable[key];
|
|
977
|
+
if (Array.isArray(value)) {
|
|
978
|
+
for (const child of value) {
|
|
979
|
+
if (child && typeof child === 'object' && 'type' in child) {
|
|
980
|
+
collect_function_var_names(/** @type {AST.Node} */ (child), names);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
} else if (value && typeof value === 'object' && 'type' in value) {
|
|
984
|
+
collect_function_var_names(/** @type {AST.Node} */ (value), names);
|
|
985
|
+
}
|
|
950
986
|
}
|
|
951
987
|
}
|
|
952
988
|
|
|
953
989
|
/**
|
|
954
|
-
* @param {
|
|
990
|
+
* @param {AST.Node | null} node
|
|
955
991
|
* @param {Set<string>} names
|
|
956
992
|
* @returns {void}
|
|
957
993
|
*/
|
|
@@ -985,66 +1021,69 @@ function collect_pattern_names(node, names) {
|
|
|
985
1021
|
}
|
|
986
1022
|
|
|
987
1023
|
/**
|
|
988
|
-
* @param {
|
|
989
|
-
* @param {
|
|
990
|
-
* @returns {
|
|
1024
|
+
* @param {AST.Expression} object
|
|
1025
|
+
* @param {AST.Expression | AST.PrivateIdentifier} key
|
|
1026
|
+
* @returns {AST.MemberExpression}
|
|
991
1027
|
*/
|
|
992
1028
|
function create_property_member_expression(object, key) {
|
|
993
1029
|
if (key?.type === 'Identifier') {
|
|
994
|
-
return create_member_expression(
|
|
995
|
-
clone_expression_node(object),
|
|
996
|
-
clone_identifier(key),
|
|
997
|
-
false,
|
|
998
|
-
key,
|
|
999
|
-
);
|
|
1030
|
+
return create_member_expression(clone_ast_node(object), clone_identifier(key), false, key);
|
|
1000
1031
|
}
|
|
1001
1032
|
|
|
1002
|
-
return create_member_expression(
|
|
1003
|
-
clone_expression_node(object),
|
|
1004
|
-
clone_expression_node(key),
|
|
1005
|
-
true,
|
|
1006
|
-
key,
|
|
1007
|
-
);
|
|
1033
|
+
return create_member_expression(clone_ast_node(object), clone_ast_node(key), true, key);
|
|
1008
1034
|
}
|
|
1009
1035
|
|
|
1010
1036
|
/**
|
|
1011
|
-
* @param {
|
|
1037
|
+
* @param {AST.Expression} object
|
|
1012
1038
|
* @param {number} index
|
|
1013
|
-
* @returns {
|
|
1039
|
+
* @returns {AST.MemberExpression}
|
|
1014
1040
|
*/
|
|
1015
1041
|
function create_index_member_expression(object, index) {
|
|
1016
|
-
return create_member_expression(
|
|
1042
|
+
return create_member_expression(clone_ast_node(object), b.literal(index), true, object);
|
|
1017
1043
|
}
|
|
1018
1044
|
|
|
1019
1045
|
/**
|
|
1020
|
-
* @param {
|
|
1021
|
-
* @returns {
|
|
1046
|
+
* @param {AST.Identifier} identifier
|
|
1047
|
+
* @returns {AST.MemberExpression}
|
|
1022
1048
|
*/
|
|
1023
1049
|
function create_value_member_expression(identifier) {
|
|
1024
1050
|
return create_member_expression(clone_identifier(identifier), 'value', false, identifier);
|
|
1025
1051
|
}
|
|
1026
1052
|
|
|
1027
1053
|
/**
|
|
1028
|
-
* @param {
|
|
1029
|
-
* @param {
|
|
1054
|
+
* @param {AST.Expression} object
|
|
1055
|
+
* @param {string | AST.Expression | AST.PrivateIdentifier} property
|
|
1030
1056
|
* @param {boolean} computed
|
|
1031
|
-
* @param {
|
|
1032
|
-
* @returns {
|
|
1057
|
+
* @param {AST.Node} source_node
|
|
1058
|
+
* @returns {AST.MemberExpression}
|
|
1033
1059
|
*/
|
|
1034
1060
|
function create_member_expression(object, property, computed, source_node) {
|
|
1035
|
-
return b.member(
|
|
1061
|
+
return b.member(
|
|
1062
|
+
object,
|
|
1063
|
+
property,
|
|
1064
|
+
computed,
|
|
1065
|
+
false,
|
|
1066
|
+
has_location(source_node) ? source_node : undefined,
|
|
1067
|
+
);
|
|
1036
1068
|
}
|
|
1037
1069
|
|
|
1038
1070
|
/**
|
|
1039
|
-
* @param {
|
|
1040
|
-
* @returns {
|
|
1071
|
+
* @param {AST.Function} fn
|
|
1072
|
+
* @returns {AST.FunctionExpression | AST.ArrowFunctionExpression}
|
|
1041
1073
|
*/
|
|
1042
1074
|
function function_declaration_to_expression(fn) {
|
|
1043
1075
|
if (fn.type === 'ArrowFunctionExpression') {
|
|
1044
1076
|
return fn;
|
|
1045
1077
|
}
|
|
1046
1078
|
|
|
1047
|
-
const expression = b.function(
|
|
1079
|
+
const expression = b.function(
|
|
1080
|
+
fn.id ?? null,
|
|
1081
|
+
fn.params,
|
|
1082
|
+
fn.body,
|
|
1083
|
+
fn.async,
|
|
1084
|
+
fn.typeParameters,
|
|
1085
|
+
has_location(fn) ? fn : undefined,
|
|
1086
|
+
);
|
|
1048
1087
|
expression.generator = fn.generator;
|
|
1049
1088
|
expression.metadata = { ...(fn.metadata || {}), path: fn.metadata?.path || [] };
|
|
1050
1089
|
return expression;
|
|
@@ -1063,7 +1102,7 @@ const VUE_SETUP_CALLS = new Set([
|
|
|
1063
1102
|
]);
|
|
1064
1103
|
|
|
1065
1104
|
/**
|
|
1066
|
-
* @param {
|
|
1105
|
+
* @param {AST.CallExpression} call_expression
|
|
1067
1106
|
* @returns {boolean}
|
|
1068
1107
|
*/
|
|
1069
1108
|
function is_vue_setup_call(call_expression) {
|
|
@@ -1092,9 +1131,9 @@ function is_vue_setup_call(call_expression) {
|
|
|
1092
1131
|
* virtual TSX skips that spread so Volar can offer completions on the real
|
|
1093
1132
|
* component prop name.
|
|
1094
1133
|
*
|
|
1095
|
-
* @param {
|
|
1096
|
-
* @param {
|
|
1097
|
-
* @returns {
|
|
1134
|
+
* @param {ESTreeJSX.JSXAttributeNode[]} attrs
|
|
1135
|
+
* @param {TransformContext} transform_context
|
|
1136
|
+
* @returns {ESTreeJSX.JSXAttributeNode[]}
|
|
1098
1137
|
*/
|
|
1099
1138
|
function preprocess_ref_attributes(attrs, transform_context) {
|
|
1100
1139
|
const result = [];
|
|
@@ -1109,7 +1148,7 @@ function preprocess_ref_attributes(attrs, transform_context) {
|
|
|
1109
1148
|
}
|
|
1110
1149
|
|
|
1111
1150
|
/**
|
|
1112
|
-
* @param {
|
|
1151
|
+
* @param {ESTreeJSX.JSXAttributeNode} attr
|
|
1113
1152
|
* @returns {boolean}
|
|
1114
1153
|
*/
|
|
1115
1154
|
function is_vue_named_ref_attribute(attr) {
|
|
@@ -1118,7 +1157,7 @@ function is_vue_named_ref_attribute(attr) {
|
|
|
1118
1157
|
return !!(
|
|
1119
1158
|
attr_name &&
|
|
1120
1159
|
attr_name !== 'ref' &&
|
|
1121
|
-
|
|
1160
|
+
attr.type === 'JSXAttribute' &&
|
|
1122
1161
|
value &&
|
|
1123
1162
|
is_vue_ref_prop_name(attr_name)
|
|
1124
1163
|
);
|
|
@@ -1133,52 +1172,56 @@ function is_vue_ref_prop_name(name) {
|
|
|
1133
1172
|
}
|
|
1134
1173
|
|
|
1135
1174
|
/**
|
|
1136
|
-
* @param {
|
|
1137
|
-
* @returns {
|
|
1175
|
+
* @param {ESTreeJSX.JSXAttributeNode} attr
|
|
1176
|
+
* @returns {ESTreeJSX.JSXAttributeNode}
|
|
1138
1177
|
*/
|
|
1139
1178
|
function create_vue_named_ref_spread(attr) {
|
|
1179
|
+
if (attr.type === 'JSXSpreadAttribute') return attr;
|
|
1140
1180
|
const attr_name = get_vue_attribute_name(attr);
|
|
1141
1181
|
const value = get_vue_attribute_expression(attr);
|
|
1142
1182
|
if (attr_name === null) return attr;
|
|
1143
1183
|
const prop = b.prop('init', b.key(attr_name), value ?? b.literal(true), false, false);
|
|
1144
|
-
|
|
1184
|
+
const source = has_location(attr) ? attr : undefined;
|
|
1185
|
+
return b.jsx_spread_attribute(b.object([prop], source), source);
|
|
1145
1186
|
}
|
|
1146
1187
|
|
|
1147
1188
|
/**
|
|
1148
|
-
* @param {
|
|
1189
|
+
* @param {ESTreeJSX.JSXAttributeNode} attr
|
|
1149
1190
|
* @returns {string | null}
|
|
1150
1191
|
*/
|
|
1151
1192
|
function get_vue_attribute_name(attr) {
|
|
1152
|
-
if (attr
|
|
1153
|
-
return typeof attr.name === 'string' ? attr.name : (attr.name?.name ?? null);
|
|
1154
|
-
}
|
|
1155
|
-
if (attr?.type === 'JSXAttribute') {
|
|
1193
|
+
if (attr.type === 'JSXAttribute') {
|
|
1156
1194
|
return attr.name?.type === 'JSXIdentifier' ? attr.name.name : null;
|
|
1157
1195
|
}
|
|
1158
1196
|
return null;
|
|
1159
1197
|
}
|
|
1160
1198
|
|
|
1161
1199
|
/**
|
|
1162
|
-
* @param {
|
|
1163
|
-
* @returns {
|
|
1200
|
+
* @param {ESTreeJSX.JSXAttributeNode} attr
|
|
1201
|
+
* @returns {AST.Expression | ESTreeJSX.JSXEmptyExpression | null}
|
|
1164
1202
|
*/
|
|
1165
1203
|
function get_vue_attribute_expression(attr) {
|
|
1166
|
-
|
|
1204
|
+
if (attr.type === 'JSXSpreadAttribute') return attr.argument;
|
|
1205
|
+
const value = attr.value;
|
|
1167
1206
|
return value?.type === 'JSXExpressionContainer' ? value.expression : value;
|
|
1168
1207
|
}
|
|
1169
1208
|
|
|
1170
1209
|
/**
|
|
1171
|
-
* @param {
|
|
1172
|
-
* @param {
|
|
1173
|
-
* @param {
|
|
1174
|
-
* @param {
|
|
1175
|
-
* @returns {{ children:
|
|
1210
|
+
* @param {AST.TSRXJSXElement} node
|
|
1211
|
+
* @param {AST.Node[]} walked_children
|
|
1212
|
+
* @param {AST.Node[]} raw_children
|
|
1213
|
+
* @param {ESTreeJSX.JSXAttributeNode[]} attributes
|
|
1214
|
+
* @returns {{ children: ESTreeJSX.JSXElement['children']; selfClosing?: boolean } | null}
|
|
1176
1215
|
*/
|
|
1177
1216
|
function rewrite_host_text_children(node, walked_children, raw_children, attributes) {
|
|
1178
1217
|
const source_children = raw_children || walked_children;
|
|
1179
1218
|
const is_composite = is_component_like_element(node);
|
|
1180
1219
|
|
|
1181
|
-
if (
|
|
1220
|
+
if (
|
|
1221
|
+
!is_composite &&
|
|
1222
|
+
source_children.length === 1 &&
|
|
1223
|
+
/** @type {{ type: string }} */ (source_children[0]).type === 'Text'
|
|
1224
|
+
) {
|
|
1182
1225
|
return null;
|
|
1183
1226
|
}
|
|
1184
1227
|
|
|
@@ -1186,17 +1229,20 @@ function rewrite_host_text_children(node, walked_children, raw_children, attribu
|
|
|
1186
1229
|
}
|
|
1187
1230
|
|
|
1188
1231
|
/**
|
|
1189
|
-
* @param {
|
|
1190
|
-
* @param {
|
|
1191
|
-
* @returns {
|
|
1232
|
+
* @param {AST.Expression | ESTreeJSX.JSXEmptyExpression} expression
|
|
1233
|
+
* @param {AST.Node} [source_node]
|
|
1234
|
+
* @returns {ESTreeJSX.JSXExpressionContainer}
|
|
1192
1235
|
*/
|
|
1193
1236
|
function to_jsx_expression_container(expression, source_node = expression) {
|
|
1194
|
-
return b.jsx_expression_container(
|
|
1237
|
+
return b.jsx_expression_container(
|
|
1238
|
+
expression,
|
|
1239
|
+
has_location(source_node) ? source_node : undefined,
|
|
1240
|
+
);
|
|
1195
1241
|
}
|
|
1196
1242
|
|
|
1197
1243
|
/**
|
|
1198
1244
|
* @param {import('estree').Program} program
|
|
1199
|
-
* @param {
|
|
1245
|
+
* @param {TransformContext} transform_context
|
|
1200
1246
|
* @returns {void}
|
|
1201
1247
|
*/
|
|
1202
1248
|
function inject_vue_imports(program, transform_context) {
|
|
@@ -1253,7 +1299,7 @@ function ensure_named_import(program, source, name, local = name) {
|
|
|
1253
1299
|
}
|
|
1254
1300
|
|
|
1255
1301
|
const has_specifier = statement.specifiers.some(
|
|
1256
|
-
(
|
|
1302
|
+
(specifier) =>
|
|
1257
1303
|
specifier.type === 'ImportSpecifier' &&
|
|
1258
1304
|
specifier.imported?.type === 'Identifier' &&
|
|
1259
1305
|
specifier.imported.name === name &&
|
|
@@ -1273,7 +1319,7 @@ function ensure_named_import(program, source, name, local = name) {
|
|
|
1273
1319
|
/**
|
|
1274
1320
|
* @param {string} name
|
|
1275
1321
|
* @param {string} [local]
|
|
1276
|
-
* @returns {
|
|
1322
|
+
* @returns {AST.ImportSpecifier}
|
|
1277
1323
|
*/
|
|
1278
1324
|
function create_import_specifier(name, local = name) {
|
|
1279
1325
|
return b.import_specifier(name, local, 'value');
|