@tsrx/vue 0.4.4 → 0.4.6

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 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.4",
6
+ "version": "0.4.6",
7
7
  "type": "module",
8
8
  "publishConfig": {
9
9
  "access": "public"
@@ -39,11 +39,11 @@
39
39
  }
40
40
  },
41
41
  "dependencies": {
42
- "esrap": "^2.4.0",
42
+ "esrap": "^2.4.2",
43
43
  "is-reference": "^3.0.3",
44
44
  "zimmerframe": "^1.1.2",
45
- "@tsrx/core": "0.6.4",
46
- "@tsrx/vue-runtime": "0.2.2"
45
+ "@tsrx/core": "0.6.6",
46
+ "@tsrx/vue-runtime": "0.2.3"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "vue": ">=3.6.0-0",
@@ -19,27 +19,51 @@ const AST_METADATA_KEYS = new Set(['loc', 'start', 'end', 'metadata']);
19
19
  * @returns {AST.YieldExpression[]}
20
20
  */
21
21
  export function find_deferred_template_yields(program) {
22
- /** @type {AST.YieldExpression[]} */
22
+ return /** @type {AST.YieldExpression[]} */ (find_deferred(program, 'YieldExpression'));
23
+ }
24
+
25
+ /**
26
+ * The `await`s that vue-jsx-vapor moves out of their async function, for the
27
+ * same reason: an `await` anywhere in an element or fragment ends up in a
28
+ * function that isn't async. `packages/vite-plugin-vue/tests/template-yield-downstream.test.js`
29
+ * checks these too.
30
+ *
31
+ * @param {AST.Program} program
32
+ * @returns {AST.AwaitExpression[]}
33
+ */
34
+ export function find_deferred_template_awaits(program) {
35
+ return /** @type {AST.AwaitExpression[]} */ (find_deferred(program, 'AwaitExpression'));
36
+ }
37
+
38
+ /**
39
+ * @param {AST.Program} program
40
+ * @param {'YieldExpression' | 'AwaitExpression'} type
41
+ * @returns {AST.Node[]}
42
+ */
43
+ function find_deferred(program, type) {
44
+ /** @type {AST.Node[]} */
23
45
  const found = [];
24
46
 
25
47
  /**
26
48
  * @param {AST.Node} node
27
- * @param {boolean} in_generator whether the nearest function is a generator
49
+ * @param {boolean} in_owner whether the nearest function is a generator, for
50
+ * a `yield`, or async, for an `await`
28
51
  * @param {boolean} in_template whether the node is inside an element or fragment
29
52
  */
30
- const visit = (node, in_generator, in_template) => {
53
+ const visit = (node, in_owner, in_template) => {
31
54
  if (isFunctionNode(node)) {
32
- in_generator = !!node.generator;
55
+ in_owner = type === 'YieldExpression' ? !!node.generator : !!node.async;
33
56
  in_template = false;
34
- } else if (node.type === 'YieldExpression' && in_generator && in_template) {
57
+ } else if (node.type === type && in_owner && in_template) {
35
58
  found.push(node);
36
59
  } else if (node.type === 'JSXElement' || node.type === 'JSXFragment') {
37
60
  in_template = true;
38
61
  }
39
- for_each_child(node, (child) => visit(child, in_generator, in_template));
62
+ for_each_child(node, (child) => visit(child, in_owner, in_template));
40
63
  };
41
64
 
42
- visit(program, false, false);
65
+ // A module's top level can await, but not yield.
66
+ visit(program, type === 'AwaitExpression', false);
43
67
  return found;
44
68
  }
45
69
 
package/src/transform.js CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { walk } from 'zimmerframe';
6
6
  import is_reference from 'is-reference';
7
- import { find_deferred_template_yields } from './template-yield.js';
7
+ import { find_deferred_template_awaits, find_deferred_template_yields } from './template-yield.js';
8
8
  import {
9
9
  builders as b,
10
10
  addJsxSetupDeclaration,
@@ -16,12 +16,14 @@ import {
16
16
  destructure_for_of_item,
17
17
  ERROR_BOUNDARY_INTERNAL_NAME,
18
18
  error,
19
+ findFirstTopLevelAwait,
19
20
  FRAGMENT_INTERNAL_NAME,
20
21
  forOfPatternReadsIndex as for_of_pattern_reads_index,
21
22
  has_location,
22
23
  IDENTIFIER_OBFUSCATION_PREFIX,
23
24
  insertAfterDirectives,
24
25
  is_component_like_element,
26
+ isFunctionNode,
25
27
  JOIN_SCOPE_CLASS_INTERNAL_NAME,
26
28
  MAP_ITERABLE_ASYNC_INTERNAL_NAME,
27
29
  MAP_ITERABLE_INTERNAL_NAME,
@@ -30,6 +32,7 @@ import {
30
32
  NORMALIZE_SPREAD_PROPS_INTERNAL_NAME,
31
33
  setLocation,
32
34
  SUSPENSE_INTERNAL_NAME,
35
+ switchStatementToJsxChild,
33
36
  TSRX_ERRORS,
34
37
  } from '@tsrx/core';
35
38
 
@@ -53,6 +56,34 @@ const vapor_bindings_counts = new WeakMap();
53
56
  */
54
57
  const VAPOR_FOR_INTERNAL_NAME = '__VaporFor';
55
58
 
59
+ /**
60
+ * Local name for the runtime helper that hands `VaporFor` the source's items.
61
+ * It has the reserved prefix, so no authored name, such as an outer loop's item
62
+ * that a keyed row reads through `.value`, can take it.
63
+ */
64
+ const FOR_ITEMS_INTERNAL_NAME = IDENTIFIER_OBFUSCATION_PREFIX + 'for_items';
65
+ /** The `computed` that walks the source of a `VaporFor` loop with `@empty`. */
66
+ const VAPOR_ITEMS_NAME = IDENTIFIER_OBFUSCATION_PREFIX + 'vapor_items';
67
+ /** The `computed` that picks the case of a `@switch` row, numbered per row. */
68
+ const SWITCH_CASE_NAME = IDENTIFIER_OBFUSCATION_PREFIX + 'case';
69
+ /** What a `@switch` row's `computed` caught. */
70
+ const SWITCH_ERROR_NAME = IDENTIFIER_OBFUSCATION_PREFIX + 'error';
71
+ /** The value a `@switch` row's `computed` held before it runs again. */
72
+ const SWITCH_PREVIOUS_NAME = IDENTIFIER_OBFUSCATION_PREFIX + 'previous';
73
+ /**
74
+ * How many `@switch` rows each compile has lowered, so a nested one's
75
+ * `computed` can't capture an outer one's name.
76
+ * @type {WeakMap<TransformContext, number>}
77
+ */
78
+ const switch_counts = new WeakMap();
79
+ /**
80
+ * The metadata flag on a `@switch`'s shared lowering, which survives the
81
+ * clones a `VaporFor` row goes through.
82
+ */
83
+ const VAPOR_SWITCH_METADATA = 'vapor_switch';
84
+ /** The most cases a `@switch` row turns into a chain of `createIf`s. */
85
+ const MAX_SWITCH_ROW_CASES = 64;
86
+
56
87
  const DEFINE_VAPOR_COMPONENT = 'defineVaporComponent';
57
88
 
58
89
  /**
@@ -113,6 +144,7 @@ const vue_platform = {
113
144
  needs_define_vapor_component: false,
114
145
  needs_vapor_for: false,
115
146
  needs_use_slots: false,
147
+ needs_pending_body: false,
116
148
  }),
117
149
  wrapHelperComponent(helper_fn, helper_id, ctx, source_node) {
118
150
  ctx.needs_define_vapor_component = true;
@@ -133,8 +165,11 @@ const vue_platform = {
133
165
  }
134
166
  return attrs.map(mark_type_only_host_ref_attribute);
135
167
  },
136
- renderForOf: (node, loop_params, body_statements, ctx) =>
137
- render_for_of_as_vapor_for(node, loop_params, body_statements, ctx),
168
+ renderForOf: (node, loop_params, body_statements, ctx, get_empty_statements) =>
169
+ render_for_of_as_vapor_for(node, loop_params, body_statements, ctx, get_empty_statements),
170
+ controlFlow: {
171
+ switchStatement: render_switch_statement,
172
+ },
138
173
  createPendingBoundary(try_content, fallback_content, ctx) {
139
174
  return create_vapor_pending_boundary(try_content, fallback_content, ctx);
140
175
  },
@@ -179,6 +214,7 @@ const vue_platform = {
179
214
  return rewrite_host_text_children(node, walked_children, raw_children, attributes);
180
215
  },
181
216
  findDeferredTemplateYields: find_deferred_template_yields,
217
+ findDeferredTemplateAwaits: find_deferred_template_awaits,
182
218
  validateComponentAwait(await_expression, _component, ctx) {
183
219
  error(
184
220
  TSRX_ERRORS.TARGET_COMPONENT_AWAIT_UNSUPPORTED(ctx.platform.name),
@@ -197,6 +233,9 @@ const vue_platform = {
197
233
 
198
234
  export const transform = createJsxTransform(vue_platform);
199
235
 
236
+ /** Local name for the `TsrxPendingBody` that renders a `@pending` body. */
237
+ const PENDING_BODY_INTERNAL_NAME = '__TsrxPendingBody';
238
+
200
239
  /**
201
240
  * @param {ESTreeJSX.JSXRenderNode} try_content
202
241
  * @param {ESTreeJSX.JSXRenderNode} fallback_content
@@ -225,7 +264,15 @@ function create_vapor_pending_boundary_from_default_slot(default_slot, fallback_
225
264
  if (!ctx.typeOnly) slots_properties.unshift(b.init('_', b.literal(1)));
226
265
 
227
266
  if (fallback_expression.type !== 'Literal' || fallback_expression.value !== null) {
228
- slots_properties.push(b.init('fallback', b.arrow([], fallback_expression)));
267
+ slots_properties.push(
268
+ b.init(
269
+ 'fallback',
270
+ b.arrow(
271
+ [],
272
+ ctx.typeOnly ? fallback_expression : create_pending_body(fallback_expression, ctx),
273
+ ),
274
+ ),
275
+ );
229
276
  }
230
277
 
231
278
  const slots = b.object(slots_properties);
@@ -277,6 +324,33 @@ function create_error_boundary_slot(content, fallback_fn, source_try) {
277
324
  );
278
325
  }
279
326
 
327
+ /**
328
+ * Render a `@pending` body through `TsrxPendingBody`. `Suspense` then creates
329
+ * it only while it shows its fallback, and a throw in it reaches the nearest
330
+ * `@catch` instead of ending the mount.
331
+ *
332
+ * @param {AST.Expression} fallback_expression
333
+ * @param {TransformContext} ctx
334
+ * @returns {AST.TSRXJSXElement}
335
+ */
336
+ function create_pending_body(fallback_expression, ctx) {
337
+ ctx.needs_pending_body = true;
338
+ return b.jsx_element_fresh(
339
+ b.jsx_opening_element(
340
+ b.jsx_id(PENDING_BODY_INTERNAL_NAME),
341
+ [
342
+ b.jsx_attribute(
343
+ b.jsx_id('content'),
344
+ to_jsx_expression_container(b.arrow([], fallback_expression)),
345
+ ),
346
+ ],
347
+ true,
348
+ ),
349
+ null,
350
+ [],
351
+ );
352
+ }
353
+
280
354
  /**
281
355
  * @param {AST.Pattern[]} patterns
282
356
  * @returns {Set<string>}
@@ -1435,29 +1509,6 @@ function read_children_from_default_slot(fn, name, ctx) {
1435
1509
  return fn;
1436
1510
  }
1437
1511
 
1438
- /**
1439
- * @param {AST.Node} node
1440
- * @param {import('zimmerframe').Context<AST.Node, ChildrenReadState>} context
1441
- */
1442
- const shadow_head = (node, { state, next }) => {
1443
- /** @type {AST.Node[]} */
1444
- const bindings = [];
1445
- if (node.type === 'CatchClause' && node.param) bindings.push(node.param);
1446
- const head =
1447
- node.type === 'ForStatement'
1448
- ? node.init
1449
- : node.type === 'ForInStatement' || node.type === 'ForOfStatement'
1450
- ? node.left
1451
- : null;
1452
- if (head?.type === 'VariableDeclaration') {
1453
- for (const declarator of head.declarations) bindings.push(declarator.id);
1454
- }
1455
- if (bindings.length === 0) return next();
1456
- const shadowed_names = new Set(state.shadowed_names);
1457
- for (const binding of bindings) collect_pattern_names(binding, shadowed_names);
1458
- return next({ ...state, shadowed_names });
1459
- };
1460
-
1461
1512
  const body = /** @type {AST.BlockStatement | AST.Expression} */ (
1462
1513
  walk(/** @type {AST.Node} */ (fn.body), state, {
1463
1514
  ChainExpression(node, { path, state, next }) {
@@ -1507,10 +1558,14 @@ function read_children_from_default_slot(fn, name, ctx) {
1507
1558
  FunctionDeclaration: rewrite_function_shadowed_refs,
1508
1559
  FunctionExpression: rewrite_function_shadowed_refs,
1509
1560
  ArrowFunctionExpression: rewrite_function_shadowed_refs,
1510
- CatchClause: shadow_head,
1511
- ForStatement: shadow_head,
1512
- ForInStatement: shadow_head,
1513
- ForOfStatement: shadow_head,
1561
+ CatchClause: rewrite_head_shadowed_refs,
1562
+ ForStatement: rewrite_head_shadowed_refs,
1563
+ ForInStatement: rewrite_head_shadowed_refs,
1564
+ ForOfStatement: rewrite_head_shadowed_refs,
1565
+ SwitchStatement: rewrite_switch_shadowed_refs,
1566
+ ClassExpression: rewrite_class_shadowed_refs,
1567
+ StaticBlock: rewrite_static_block_shadowed_refs,
1568
+ TSEnumDeclaration: rewrite_enum_shadowed_refs,
1514
1569
  BlockStatement(node, context) {
1515
1570
  // The component body declares the destructured `children` binding;
1516
1571
  // it cannot redeclare the props parameter or its bindings.
@@ -1782,13 +1837,16 @@ function create_define_vapor_component_call(fn_expression, generated_helpers, ge
1782
1837
  * @param {AST.Pattern[]} loop_params
1783
1838
  * @param {AST.Statement[]} body_statements
1784
1839
  * @param {TransformContext} transform_context
1840
+ * @param {(() => AST.Statement[]) | null} get_empty_statements
1785
1841
  * @returns {ESTreeJSX.JSXExpressionContainer | null}
1786
1842
  */
1787
- function render_for_of_as_vapor_for(node, loop_params, body_statements, transform_context) {
1788
- if (node.empty) {
1789
- return null;
1790
- }
1791
-
1843
+ function render_for_of_as_vapor_for(
1844
+ node,
1845
+ loop_params,
1846
+ body_statements,
1847
+ transform_context,
1848
+ get_empty_statements,
1849
+ ) {
1792
1850
  if (body_statements.length !== 1) {
1793
1851
  return null;
1794
1852
  }
@@ -1798,38 +1856,71 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
1798
1856
  return null;
1799
1857
  }
1800
1858
 
1801
- // A default in the head's pattern that reads the index can't be read in
1802
- // the parameters, where the index comes second. The shared lowering
1803
- // destructures the item in the callback for a body that can skip a row.
1804
- const pattern_reads_index = for_of_pattern_reads_index(loop_params[0], node.index);
1805
- if (pattern_reads_index && expression_can_skip_rendering(statement.argument)) {
1806
- return null;
1807
- }
1808
-
1809
1859
  const rendered = statement.argument;
1810
- if (expression_can_skip_rendering(rendered)) {
1811
- return render_for_of_as_map_iterable(node, loop_params, rendered, transform_context);
1812
- }
1813
-
1814
1860
  const key_expression = node.key
1815
1861
  ? clone_ast_node(node.key)
1816
1862
  : (find_jsx_key_expression(rendered) ?? (node.index ? clone_ast_node(node.index) : null));
1863
+ const pattern_reads_index = for_of_pattern_reads_index(loop_params[0], node.index);
1864
+
1865
+ // A keyed loop renders through `VaporFor` even when its body can skip a row
1866
+ // or it has `@empty`, so its rows move with their keys (#178). The shared
1867
+ // lowering keeps such a loop without a key; one that awaits or yields, which
1868
+ // it suspends the template's closures for; one whose head destructures in a
1869
+ // way that runs code, which `getKey` and the row would each run; and one
1870
+ // whose row renders through an IIFE (`@switch`), which a row slot runs once
1871
+ // and which can return `null`.
1872
+ if (
1873
+ (node.empty || expression_can_skip_rendering(rendered)) &&
1874
+ (!key_expression ||
1875
+ suspends(node) ||
1876
+ destructuring_runs_code(loop_params[0]) ||
1877
+ !is_vapor_for_row(rendered) ||
1878
+ // A `@switch` row with `@empty` stays where #1378 left it, which
1879
+ // renders on the server.
1880
+ is_lowered_switch(rendered))
1881
+ ) {
1882
+ // A default in the head's pattern that reads the index can't be read in
1883
+ // the parameters, where the index comes second. The shared lowering
1884
+ // destructures the item in the callback.
1885
+ if (node.empty || pattern_reads_index) {
1886
+ return null;
1887
+ }
1888
+ return render_for_of_as_map_iterable(node, loop_params, rendered, transform_context);
1889
+ }
1817
1890
 
1891
+ const row = to_vapor_for_row(rendered, transform_context);
1818
1892
  const slot = key_expression
1819
- ? create_keyed_vapor_for_slot(loop_params, rendered, transform_context)
1820
- : { params: loop_params, body: rendered, expression: true };
1893
+ ? create_keyed_vapor_for_slot(loop_params, row, transform_context)
1894
+ : { params: loop_params, body: row, expression: true };
1821
1895
  if (!slot) {
1822
1896
  return null;
1823
1897
  }
1824
1898
 
1899
+ if (is_lowered_switch(rendered) && lowered_switch_statement(rendered).cases.length > 0) {
1900
+ // The name `switch_in_fragment` gave the row's `computed`.
1901
+ switch_counts.set(transform_context, (switch_counts.get(transform_context) ?? 0) + 1);
1902
+ transform_context.needs_vapor_computed = true;
1903
+ }
1904
+
1825
1905
  transform_context.needs_vapor_for = true;
1906
+ transform_context.needs_for_items = true;
1826
1907
 
1827
1908
  if (key_expression) {
1828
1909
  strip_top_level_jsx_keys(slot.rendered ?? slot.body);
1829
1910
  }
1830
1911
 
1912
+ // `VaporFor` reads an array by index and walks other iterables its own way,
1913
+ // so it gets the source's items as `for...of` walks them (#1147). With
1914
+ // `@empty`, one `computed` walks the source for both the check and the rows.
1915
+ const source_items = b.call(FOR_ITEMS_INTERNAL_NAME, clone_ast_node(node.right));
1916
+ const items_ref = get_empty_statements ? create_generated_identifier(VAPOR_ITEMS_NAME) : null;
1831
1917
  const attributes = [
1832
- b.jsx_attribute(b.jsx_id('in'), to_jsx_expression_container(clone_ast_node(node.right))),
1918
+ b.jsx_attribute(
1919
+ b.jsx_id('in'),
1920
+ to_jsx_expression_container(
1921
+ items_ref ? create_value_member_expression(items_ref) : source_items,
1922
+ ),
1923
+ ),
1833
1924
  ];
1834
1925
 
1835
1926
  if (key_expression) {
@@ -1848,11 +1939,447 @@ function render_for_of_as_vapor_for(node, loop_params, body_statements, transfor
1848
1939
  attributes.push(b.jsx_attribute(b.jsx_id('getKey'), to_jsx_expression_container(get_key)));
1849
1940
  }
1850
1941
 
1942
+ const vapor_for = b.jsx_element_fresh(
1943
+ b.jsx_opening_element(b.jsx_id(VAPOR_FOR_INTERNAL_NAME), attributes),
1944
+ b.jsx_closing_element(b.jsx_id(VAPOR_FOR_INTERNAL_NAME)),
1945
+ [to_jsx_expression_container(create_loop_callback(slot.params, slot.body, slot.expression))],
1946
+ );
1947
+
1948
+ if (!items_ref || !get_empty_statements) {
1949
+ return to_jsx_expression_container(vapor_for);
1950
+ }
1951
+
1952
+ transform_context.needs_vapor_computed = true;
1953
+ const empty_statements = get_empty_statements();
1954
+ const empty_return = empty_statements.length === 1 ? empty_statements[0] : null;
1955
+ const empty =
1956
+ empty_return?.type === 'ReturnStatement' && empty_return.argument
1957
+ ? to_vapor_branch(empty_return.argument)
1958
+ : b.call(
1959
+ b.arrow(
1960
+ [],
1961
+ b.block(empty_statements),
1962
+ false,
1963
+ undefined,
1964
+ has_location(node.empty) ? node.empty : undefined,
1965
+ ),
1966
+ );
1967
+
1968
+ // The choice sits in a fragment, so vue-jsx-vapor makes it a `createIf`:
1969
+ // `VaporFor` and its rows stay mounted while the source has items.
1851
1970
  return to_jsx_expression_container(
1852
- b.jsx_element_fresh(
1853
- b.jsx_opening_element(b.jsx_id(VAPOR_FOR_INTERNAL_NAME), attributes),
1854
- b.jsx_closing_element(b.jsx_id(VAPOR_FOR_INTERNAL_NAME)),
1855
- [to_jsx_expression_container(create_loop_callback(slot.params, slot.body, slot.expression))],
1971
+ b.call(
1972
+ b.arrow(
1973
+ [],
1974
+ b.block([
1975
+ b.const(items_ref, b.call(VUE_COMPUTED_INTERNAL_NAME, b.arrow([], source_items))),
1976
+ b.return(
1977
+ b.jsx_fragment([
1978
+ to_jsx_expression_container(
1979
+ b.conditional(
1980
+ b.binary(
1981
+ '===',
1982
+ b.member(
1983
+ create_value_member_expression(items_ref),
1984
+ create_generated_identifier('length'),
1985
+ ),
1986
+ b.literal(0),
1987
+ ),
1988
+ empty,
1989
+ vapor_for,
1990
+ ),
1991
+ ),
1992
+ ]),
1993
+ ),
1994
+ ]),
1995
+ ),
1996
+ ),
1997
+ );
1998
+ }
1999
+
2000
+ /**
2001
+ * Whether `node` awaits or yields outside a nested function.
2002
+ *
2003
+ * @param {AST.Node} node
2004
+ * @returns {boolean}
2005
+ */
2006
+ function suspends(node) {
2007
+ return !!findFirstTopLevelAwait(node, false) || yields(node);
2008
+ }
2009
+
2010
+ /**
2011
+ * Whether destructuring `pattern` can run code or read the value more than
2012
+ * once in a way that shows: an array pattern walks an iterator, and a default
2013
+ * or a computed key evaluates an expression.
2014
+ *
2015
+ * @param {AST.Pattern | AST.Property['value'] | null | undefined} pattern
2016
+ * @returns {boolean}
2017
+ */
2018
+ function destructuring_runs_code(pattern) {
2019
+ switch (pattern?.type) {
2020
+ case 'ArrayPattern':
2021
+ case 'AssignmentPattern':
2022
+ return true;
2023
+ case 'ObjectPattern':
2024
+ return pattern.properties.some((property) =>
2025
+ property.type === 'RestElement'
2026
+ ? destructuring_runs_code(property.argument)
2027
+ : property.computed || destructuring_runs_code(property.value),
2028
+ );
2029
+ case 'RestElement':
2030
+ return destructuring_runs_code(pattern.argument);
2031
+ default:
2032
+ return false;
2033
+ }
2034
+ }
2035
+
2036
+ /**
2037
+ * Whether a row can render through `VaporFor`: an element or fragment, or a
2038
+ * choice of them that `to_vapor_for_row` puts in a fragment.
2039
+ *
2040
+ * @param {AST.Expression} node
2041
+ * @returns {boolean}
2042
+ */
2043
+ function is_vapor_for_row(node) {
2044
+ return (
2045
+ is_lowered_switch(node) ||
2046
+ node.type === 'JSXElement' ||
2047
+ node.type === 'JSXFragment' ||
2048
+ node.type === 'ConditionalExpression' ||
2049
+ (node.type === 'LogicalExpression' && node.operator === '&&') ||
2050
+ (node.type === 'Literal' && node.value === null)
2051
+ );
2052
+ }
2053
+
2054
+ /**
2055
+ * @param {unknown} node
2056
+ * @returns {boolean}
2057
+ */
2058
+ function yields(node) {
2059
+ if (Array.isArray(node)) return node.some(yields);
2060
+ if (!node || typeof node !== 'object' || isFunctionNode(/** @type {AST.Node} */ (node))) {
2061
+ return false;
2062
+ }
2063
+ if (/** @type {AST.Node} */ (node).type === 'YieldExpression') return true;
2064
+ return Object.entries(node).some(
2065
+ ([key, value]) => key !== 'loc' && key !== 'metadata' && yields(value),
2066
+ );
2067
+ }
2068
+
2069
+ /**
2070
+ * The row a `VaporFor` slot returns. The slot runs once per row, so a ternary
2071
+ * it returns would keep the branch it picked first: a row that picks a branch,
2072
+ * or can skip itself, is a fragment around the choice, which vue-jsx-vapor
2073
+ * makes a `createIf` that follows its condition, and a `@switch` row is a
2074
+ * fragment around its cases (`switch_in_fragment`).
2075
+ *
2076
+ * @param {AST.Expression} node
2077
+ * @param {TransformContext} transform_context
2078
+ * @returns {AST.Expression}
2079
+ */
2080
+ function to_vapor_for_row(node, transform_context) {
2081
+ if (is_lowered_switch(node)) {
2082
+ return switch_in_fragment(/** @type {AST.CallExpression} */ (node), transform_context);
2083
+ }
2084
+ if (
2085
+ node.type === 'ConditionalExpression' ||
2086
+ (node.type === 'LogicalExpression' && node.operator === '&&')
2087
+ ) {
2088
+ return /** @type {AST.Expression} */ (
2089
+ /** @type {unknown} */ (b.jsx_fragment([to_jsx_expression_container(to_vapor_branch(node))]))
2090
+ );
2091
+ }
2092
+ return to_vapor_branch(node);
2093
+ }
2094
+
2095
+ /**
2096
+ * A branch of a `VaporFor` row or of its `@empty`, where Vapor can't mount
2097
+ * `null`: a skipped branch renders an empty fragment.
2098
+ *
2099
+ * @param {AST.Expression} node
2100
+ * @returns {AST.Expression}
2101
+ */
2102
+ function to_vapor_branch(node) {
2103
+ if (node.type === 'Literal' && node.value === null) {
2104
+ return /** @type {AST.Expression} */ (/** @type {unknown} */ (b.jsx_fragment()));
2105
+ }
2106
+
2107
+ if (node.type === 'ConditionalExpression') {
2108
+ return {
2109
+ ...node,
2110
+ consequent: to_vapor_branch(node.consequent),
2111
+ alternate: to_vapor_branch(node.alternate),
2112
+ };
2113
+ }
2114
+
2115
+ if (node.type === 'LogicalExpression' && node.operator === '&&') {
2116
+ return b.conditional(
2117
+ node.left,
2118
+ to_vapor_branch(node.right),
2119
+ /** @type {AST.Expression} */ (/** @type {unknown} */ (b.jsx_fragment())),
2120
+ );
2121
+ }
2122
+
2123
+ return node;
2124
+ }
2125
+
2126
+ /**
2127
+ * `@switch` on Vue: the shared lowering, an IIFE around a `switch`, marked so
2128
+ * a `VaporFor` row that is a `@switch` can render through
2129
+ * `switch_in_fragment`. A row slot runs once, so the shared IIFE would keep
2130
+ * the case it picked first and return `null` when no case matches, which
2131
+ * Vapor can't mount. Elsewhere vue-jsx-vapor evaluates the IIFE in an effect,
2132
+ * which follows the value.
2133
+ *
2134
+ * Not marked, so a row keeps the IIFE: the type-only output; a `@switch` that
2135
+ * awaits or yields; one whose case has setup statements or renders anything
2136
+ * but an element, a fragment or a choice of them (a nested `@switch`, a loop
2137
+ * through `map_iterable`), which as a branch of its own would render again,
2138
+ * components and all, whenever what it reads changes, such as the row's
2139
+ * item; and one with more than `MAX_SWITCH_ROW_CASES` cases, whose chain of
2140
+ * choices would nest as deep.
2141
+ *
2142
+ * @param {AST.SwitchStatement} node
2143
+ * @param {TransformContext} transform_context
2144
+ * @returns {ESTreeJSX.JSXRenderNode}
2145
+ */
2146
+ function render_switch_statement(node, transform_context) {
2147
+ const container = switchStatementToJsxChild(node, transform_context);
2148
+ const statement =
2149
+ container.type === 'JSXExpressionContainer' &&
2150
+ container.expression.type === 'CallExpression' &&
2151
+ container.expression.callee.type === 'ArrowFunctionExpression' &&
2152
+ container.expression.callee.body.type === 'BlockStatement'
2153
+ ? container.expression.callee.body.body[0]
2154
+ : null;
2155
+ if (
2156
+ !transform_context.typeOnly &&
2157
+ statement?.type === 'SwitchStatement' &&
2158
+ statement.cases.length <= MAX_SWITCH_ROW_CASES &&
2159
+ statement.cases.every(
2160
+ (switch_case) =>
2161
+ switch_case.consequent.length === 1 &&
2162
+ switch_case.consequent[0].type === 'ReturnStatement' &&
2163
+ renders_once(switch_case.consequent[0].argument),
2164
+ ) &&
2165
+ !suspends(node) &&
2166
+ container.type === 'JSXExpressionContainer'
2167
+ ) {
2168
+ /** @type {Record<string, unknown>} */ (
2169
+ /** @type {unknown} */ (container.expression.metadata ??= { path: [] })
2170
+ )[VAPOR_SWITCH_METADATA] = true;
2171
+ }
2172
+ return container;
2173
+ }
2174
+
2175
+ /**
2176
+ * Whether a case's output, as a `createIf` branch, renders once while the
2177
+ * branch stays: an element, a fragment, nothing, or a choice of them, which
2178
+ * vue-jsx-vapor makes `createIf`s too. Anything else is evaluated in an
2179
+ * effect of its own, which renders it again when what it reads changes.
2180
+ *
2181
+ * @param {AST.Expression | null | undefined} node
2182
+ * @returns {boolean}
2183
+ */
2184
+ function renders_once(node) {
2185
+ if (!node) return true;
2186
+ switch (node.type) {
2187
+ case 'JSXElement':
2188
+ case 'JSXFragment':
2189
+ return true;
2190
+ case 'Literal':
2191
+ return node.value === null;
2192
+ case 'ConditionalExpression':
2193
+ return renders_once(node.consequent) && renders_once(node.alternate);
2194
+ case 'LogicalExpression':
2195
+ return node.operator === '&&' && renders_once(node.right);
2196
+ default:
2197
+ return false;
2198
+ }
2199
+ }
2200
+
2201
+ /**
2202
+ * Whether `node` is a `@switch` that `render_switch_statement` marked.
2203
+ *
2204
+ * @param {AST.Node} node
2205
+ * @returns {boolean}
2206
+ */
2207
+ function is_lowered_switch(node) {
2208
+ return (
2209
+ node.type === 'CallExpression' &&
2210
+ !!(
2211
+ /** @type {Record<string, unknown> | undefined} */ (/** @type {unknown} */ (node.metadata))?.[
2212
+ VAPOR_SWITCH_METADATA
2213
+ ]
2214
+ )
2215
+ );
2216
+ }
2217
+
2218
+ /**
2219
+ * The `switch` in the IIFE of a `@switch` that `render_switch_statement`
2220
+ * marked.
2221
+ *
2222
+ * @param {AST.Expression} node
2223
+ * @returns {AST.SwitchStatement}
2224
+ */
2225
+ function lowered_switch_statement(node) {
2226
+ return /** @type {AST.SwitchStatement} */ (
2227
+ /** @type {AST.BlockStatement} */ (
2228
+ /** @type {AST.ArrowFunctionExpression} */ (/** @type {AST.CallExpression} */ (node).callee)
2229
+ .body
2230
+ ).body[0]
2231
+ );
2232
+ }
2233
+
2234
+ /**
2235
+ * A `VaporFor` row that is a `@switch`. Its slot runs once, so a `computed`
2236
+ * runs the `switch` for the index of the case it picks, and the row is a
2237
+ * fragment around the case chosen by that index, which vue-jsx-vapor makes
2238
+ * `createIf`s: the row follows its value, keeps its case mounted while the
2239
+ * index stays the same, and renders an empty fragment when no case matches,
2240
+ * since a row can't be `null`. The `computed` is made once per row, so the
2241
+ * `switch` runs once for each change it reads.
2242
+ *
2243
+ * @param {AST.CallExpression} node
2244
+ * @param {TransformContext} transform_context
2245
+ * @returns {AST.Expression}
2246
+ */
2247
+ function switch_in_fragment(node, transform_context) {
2248
+ const statement = lowered_switch_statement(node);
2249
+ // Without cases there is nothing to choose: the fragment runs the
2250
+ // discriminant in an effect, as the `switch` ran it elsewhere.
2251
+ if (statement.cases.length === 0) {
2252
+ return /** @type {AST.Expression} */ (
2253
+ /** @type {unknown} */ (
2254
+ b.jsx_fragment([
2255
+ to_jsx_expression_container(
2256
+ b.call(b.arrow([], b.block([statement, b.return(b.literal(null))]))),
2257
+ ),
2258
+ ])
2259
+ )
2260
+ );
2261
+ }
2262
+
2263
+ // Named with the next number, which `render_for_of_as_vapor_for` takes
2264
+ // only if the loop renders through `VaporFor`.
2265
+ const case_ref = create_generated_identifier(
2266
+ `${SWITCH_CASE_NAME}_${(switch_counts.get(transform_context) ?? 0) + 1}`,
2267
+ );
2268
+ const error_ref = create_generated_identifier(SWITCH_ERROR_NAME);
2269
+ const previous_ref = create_generated_identifier(SWITCH_PREVIOUS_NAME);
2270
+ /** The index the `computed` holds, or the last one it picked while it holds a throw. */
2271
+ const held_index = () =>
2272
+ b.conditional(
2273
+ b.binary(
2274
+ '===',
2275
+ b.unary('typeof', create_value_member_expression(case_ref)),
2276
+ b.literal('object'),
2277
+ ),
2278
+ b.member(create_value_member_expression(case_ref), 'index'),
2279
+ create_value_member_expression(case_ref),
2280
+ );
2281
+
2282
+ /** @type {AST.Expression} */
2283
+ let chain = b.jsx_fragment();
2284
+ for (let index = statement.cases.length - 1; index >= 0; index--) {
2285
+ const output = /** @type {AST.ReturnStatement} */ (statement.cases[index].consequent[0]);
2286
+ chain = b.conditional(
2287
+ b.binary(
2288
+ '===',
2289
+ // The first choice throws what the `switch` threw, in its
2290
+ // `createIf`'s effect, which keeps following the `computed`;
2291
+ // the others keep the case picked before the throw.
2292
+ index === 0
2293
+ ? b.conditional(
2294
+ b.binary(
2295
+ '===',
2296
+ b.unary('typeof', create_value_member_expression(case_ref)),
2297
+ b.literal('object'),
2298
+ ),
2299
+ b.call(
2300
+ b.arrow(
2301
+ [],
2302
+ b.block([
2303
+ /** @type {AST.ThrowStatement} */ ({
2304
+ type: 'ThrowStatement',
2305
+ argument: b.member(create_value_member_expression(case_ref), 'error'),
2306
+ metadata: { path: [] },
2307
+ }),
2308
+ ]),
2309
+ ),
2310
+ ),
2311
+ create_value_member_expression(case_ref),
2312
+ )
2313
+ : held_index(),
2314
+ b.literal(index),
2315
+ ),
2316
+ to_vapor_branch(output.argument ?? b.literal(null)),
2317
+ chain,
2318
+ );
2319
+ }
2320
+
2321
+ return b.call(
2322
+ b.arrow(
2323
+ [],
2324
+ b.block([
2325
+ // Vue stops running an effect that read a `computed` whose getter
2326
+ // threw, so the `computed` returns what the `switch` threw, with
2327
+ // the index it held before.
2328
+ b.const(
2329
+ case_ref,
2330
+ b.call(
2331
+ VUE_COMPUTED_INTERNAL_NAME,
2332
+ b.arrow(
2333
+ [previous_ref],
2334
+ b.block([
2335
+ b.try(
2336
+ b.block([
2337
+ setLocation(
2338
+ b.switch(
2339
+ statement.discriminant,
2340
+ statement.cases.map((switch_case, index) =>
2341
+ setLocation(
2342
+ b.switch_case(switch_case.test, [b.return(b.literal(index))]),
2343
+ has_location(switch_case) ? switch_case : undefined,
2344
+ ),
2345
+ ),
2346
+ ),
2347
+ has_location(statement) ? statement : undefined,
2348
+ ),
2349
+ b.return(b.literal(-1)),
2350
+ ]),
2351
+ b.catch_clause(
2352
+ error_ref,
2353
+ null,
2354
+ b.block([
2355
+ b.return(
2356
+ b.object([
2357
+ b.prop('init', b.id('error'), clone_identifier(error_ref)),
2358
+ b.prop(
2359
+ 'init',
2360
+ b.id('index'),
2361
+ b.conditional(
2362
+ b.binary(
2363
+ '===',
2364
+ b.unary('typeof', clone_identifier(previous_ref)),
2365
+ b.literal('object'),
2366
+ ),
2367
+ b.member(clone_identifier(previous_ref), 'index'),
2368
+ b.logical('??', clone_identifier(previous_ref), b.literal(-1)),
2369
+ ),
2370
+ ),
2371
+ ]),
2372
+ ),
2373
+ ]),
2374
+ ),
2375
+ null,
2376
+ ),
2377
+ ]),
2378
+ ),
2379
+ ),
2380
+ ),
2381
+ b.return(b.jsx_fragment([to_jsx_expression_container(chain)])),
2382
+ ]),
1856
2383
  ),
1857
2384
  );
1858
2385
  }
@@ -2196,6 +2723,14 @@ function rewrite_vapor_for_keyed_slot_refs(node, loop_params, replacements = new
2196
2723
  FunctionExpression: rewrite_function_shadowed_refs,
2197
2724
  ArrowFunctionExpression: rewrite_function_shadowed_refs,
2198
2725
  BlockStatement: rewrite_block_shadowed_refs,
2726
+ StaticBlock: rewrite_static_block_shadowed_refs,
2727
+ CatchClause: rewrite_head_shadowed_refs,
2728
+ ForStatement: rewrite_head_shadowed_refs,
2729
+ ForInStatement: rewrite_head_shadowed_refs,
2730
+ ForOfStatement: rewrite_head_shadowed_refs,
2731
+ SwitchStatement: rewrite_switch_shadowed_refs,
2732
+ ClassExpression: rewrite_class_shadowed_refs,
2733
+ TSEnumDeclaration: rewrite_enum_shadowed_refs,
2199
2734
  },
2200
2735
  )
2201
2736
  );
@@ -2307,7 +2842,7 @@ function collect_pattern_replacements(pattern, source, replacements) {
2307
2842
  * @param {import('zimmerframe').Context<AST.Node, S>} context
2308
2843
  * @returns {AST.Node | void}
2309
2844
  */
2310
- function rewrite_function_shadowed_refs(node, { state, next }) {
2845
+ function rewrite_function_shadowed_refs(node, { state, next, visit }) {
2311
2846
  const shadowed_names = new Set(state.shadowed_names);
2312
2847
  if (node.type !== 'ArrowFunctionExpression' && node.id) {
2313
2848
  collect_pattern_names(node.id, shadowed_names);
@@ -2316,7 +2851,59 @@ function rewrite_function_shadowed_refs(node, { state, next }) {
2316
2851
  collect_pattern_names(param, shadowed_names);
2317
2852
  }
2318
2853
  collect_function_var_names(node.body, shadowed_names);
2319
- return next({ ...state, shadowed_names });
2854
+ const inner = { ...state, shadowed_names };
2855
+
2856
+ // A parameter's decorators run in the enclosing scope, before the
2857
+ // parameters exist: they are walked with the outer names and put back.
2858
+ /** @typedef {AST.Node & { decorators?: AST.Node[] }} DecoratedNode */
2859
+ /** @param {AST.Node} param */
2860
+ const decorated = (param) =>
2861
+ /** @type {DecoratedNode} */ (
2862
+ param.type === 'TSParameterProperty'
2863
+ ? /** @type {{ parameter: AST.Node }} */ (/** @type {unknown} */ (param)).parameter
2864
+ : param
2865
+ );
2866
+ /** @type {Map<number, AST.Node[]>} */
2867
+ const decorators = new Map();
2868
+ const params = (node.params || []).map((param, index) => {
2869
+ const target = decorated(/** @type {AST.Node} */ (param));
2870
+ if (!target.decorators?.length) return param;
2871
+ decorators.set(
2872
+ index,
2873
+ target.decorators.map((decorator) => /** @type {AST.Node} */ (visit(decorator, state))),
2874
+ );
2875
+ return with_decorators(/** @type {AST.Node} */ (param), []);
2876
+ });
2877
+ if (decorators.size === 0) return next(inner);
2878
+
2879
+ const walked = /** @type {AST.Function} */ (
2880
+ visit(/** @type {AST.Node} */ ({ ...node, params }), inner)
2881
+ );
2882
+ return /** @type {AST.Node} */ ({
2883
+ ...walked,
2884
+ params: walked.params.map((param, index) => {
2885
+ const outer = decorators.get(index);
2886
+ return outer ? with_decorators(/** @type {AST.Node} */ (param), outer) : param;
2887
+ }),
2888
+ });
2889
+ }
2890
+
2891
+ /**
2892
+ * `param`, a parameter or a constructor's parameter property, with its
2893
+ * decorators replaced.
2894
+ *
2895
+ * @param {AST.Node} param
2896
+ * @param {AST.Node[]} decorators
2897
+ * @returns {AST.Pattern}
2898
+ */
2899
+ function with_decorators(param, decorators) {
2900
+ if (param.type === 'TSParameterProperty') {
2901
+ const property = /** @type {{ parameter: AST.Node }} */ (/** @type {unknown} */ (param));
2902
+ return /** @type {AST.Pattern} */ (
2903
+ /** @type {unknown} */ ({ ...param, parameter: { ...property.parameter, decorators } })
2904
+ );
2905
+ }
2906
+ return /** @type {AST.Pattern} */ (/** @type {unknown} */ ({ ...param, decorators }));
2320
2907
  }
2321
2908
 
2322
2909
  /**
@@ -2331,6 +2918,116 @@ function rewrite_block_shadowed_refs(node, { state, next }) {
2331
2918
  return next({ ...state, shadowed_names });
2332
2919
  }
2333
2920
 
2921
+ /**
2922
+ * A class `static` block is a function body: its `var`s are its own too.
2923
+ *
2924
+ * @template {{ shadowed_names: Set<string> }} S
2925
+ * @param {AST.StaticBlock} node
2926
+ * @param {import('zimmerframe').Context<AST.Node, S>} context
2927
+ * @returns {AST.Node | void}
2928
+ */
2929
+ function rewrite_static_block_shadowed_refs(node, { state, next }) {
2930
+ const shadowed_names = new Set(state.shadowed_names);
2931
+ collect_block_lexical_names(node.body, shadowed_names);
2932
+ collect_function_var_names(node.body, shadowed_names);
2933
+ return next({ ...state, shadowed_names });
2934
+ }
2935
+
2936
+ /**
2937
+ * The names a `catch` clause's parameter or a `for` head declares, which
2938
+ * shadow the outer ones in the whole statement. A `let` or `const` head's
2939
+ * names are in their temporal dead zone in the loop's own expressions, the
2940
+ * right-hand side of `for (const row of row.children)` included, which reads
2941
+ * the inner `row` and throws, so those stay as written too.
2942
+ *
2943
+ * @template {{ shadowed_names: Set<string> }} S
2944
+ * @param {AST.CatchClause | AST.ForStatement | AST.ForInStatement | AST.ForOfStatement} node
2945
+ * @param {import('zimmerframe').Context<AST.Node, S>} context
2946
+ * @returns {AST.Node | void}
2947
+ */
2948
+ function rewrite_head_shadowed_refs(node, { state, next }) {
2949
+ /** @type {AST.Node[]} */
2950
+ const bindings = [];
2951
+ if (node.type === 'CatchClause' && node.param) bindings.push(node.param);
2952
+ const head =
2953
+ node.type === 'ForStatement'
2954
+ ? node.init
2955
+ : node.type === 'ForInStatement' || node.type === 'ForOfStatement'
2956
+ ? node.left
2957
+ : null;
2958
+ if (head?.type === 'VariableDeclaration') {
2959
+ for (const declarator of head.declarations) bindings.push(declarator.id);
2960
+ }
2961
+ if (bindings.length === 0) return next();
2962
+ const shadowed_names = new Set(state.shadowed_names);
2963
+ for (const binding of bindings) collect_pattern_names(binding, shadowed_names);
2964
+ return next({ ...state, shadowed_names });
2965
+ }
2966
+
2967
+ /**
2968
+ * A `switch`'s cases share one block, which its discriminant is read outside of.
2969
+ *
2970
+ * @template {{ shadowed_names: Set<string> }} S
2971
+ * @param {AST.SwitchStatement} node
2972
+ * @param {import('zimmerframe').Context<AST.Node, S>} context
2973
+ * @returns {AST.SwitchStatement}
2974
+ */
2975
+ function rewrite_switch_shadowed_refs(node, { state, visit }) {
2976
+ const shadowed_names = new Set(state.shadowed_names);
2977
+ collect_block_lexical_names(
2978
+ node.cases.flatMap((switch_case) => switch_case.consequent),
2979
+ shadowed_names,
2980
+ );
2981
+ const inner = { ...state, shadowed_names };
2982
+ return {
2983
+ ...node,
2984
+ discriminant: /** @type {AST.Expression} */ (visit(node.discriminant, state)),
2985
+ cases: node.cases.map(
2986
+ (switch_case) => /** @type {AST.SwitchCase} */ (visit(switch_case, inner)),
2987
+ ),
2988
+ };
2989
+ }
2990
+
2991
+ /**
2992
+ * An `enum`'s members are bound inside it: a member's initializer reads an
2993
+ * earlier member by its name. (Members of another declaration of the same
2994
+ * `enum` are in scope too; those aren't collected.)
2995
+ *
2996
+ * @template {{ shadowed_names: Set<string> }} S
2997
+ * @param {AST.Node} node A `TSEnumDeclaration`.
2998
+ * @param {import('zimmerframe').Context<AST.Node, S>} context
2999
+ * @returns {AST.Node | void}
3000
+ */
3001
+ function rewrite_enum_shadowed_refs(node, { state, next }) {
3002
+ const members =
3003
+ /** @type {{ body?: { members?: { id: AST.Node }[] }, members?: { id: AST.Node }[] }} */ (
3004
+ /** @type {unknown} */ (node)
3005
+ );
3006
+ const shadowed_names = new Set(state.shadowed_names);
3007
+ for (const member of members.body?.members ?? members.members ?? []) {
3008
+ const id = /** @type {AST.Node} */ (member.id);
3009
+ if (id.type === 'Identifier') shadowed_names.add(id.name);
3010
+ // A quoted member (`"row" = 1`) is read by its name too.
3011
+ else if (id.type === 'Literal' && typeof id.value === 'string') shadowed_names.add(id.value);
3012
+ }
3013
+ return next({ ...state, shadowed_names });
3014
+ }
3015
+
3016
+ /**
3017
+ * A class expression's name is bound inside it, its heritage included.
3018
+ *
3019
+ * @template {{ shadowed_names: Set<string> }} S
3020
+ * @param {AST.ClassExpression} node
3021
+ * @param {import('zimmerframe').Context<AST.Node, S>} context
3022
+ * @returns {AST.Node | void}
3023
+ */
3024
+ function rewrite_class_shadowed_refs(node, { state, next }) {
3025
+ if (!node.id) return next();
3026
+ const shadowed_names = new Set(state.shadowed_names);
3027
+ collect_pattern_names(node.id, shadowed_names);
3028
+ return next({ ...state, shadowed_names });
3029
+ }
3030
+
2334
3031
  /**
2335
3032
  * @param {AST.Statement[]} statements
2336
3033
  * @param {Set<string>} names
@@ -2350,6 +3047,16 @@ function collect_block_lexical_names(statements, names) {
2350
3047
  statement.id
2351
3048
  ) {
2352
3049
  collect_pattern_names(statement.id, names);
3050
+ continue;
3051
+ }
3052
+
3053
+ // An `enum` or a namespace, which the statement types leave out.
3054
+ const declaration = /** @type {AST.Node} */ (statement);
3055
+ if (
3056
+ (declaration.type === 'TSEnumDeclaration' || declaration.type === 'TSModuleDeclaration') &&
3057
+ declaration.id.type === 'Identifier'
3058
+ ) {
3059
+ collect_pattern_names(declaration.id, names);
2353
3060
  }
2354
3061
  }
2355
3062
  }
@@ -2436,6 +3143,13 @@ function collect_pattern_names(node, names) {
2436
3143
  case 'Property':
2437
3144
  collect_pattern_names(node.value, names);
2438
3145
  break;
3146
+ // A constructor's parameter property (`constructor(public row)`).
3147
+ case 'TSParameterProperty':
3148
+ collect_pattern_names(
3149
+ /** @type {AST.Node} */ (/** @type {unknown} */ (node.parameter)),
3150
+ names,
3151
+ );
3152
+ break;
2439
3153
  }
2440
3154
  }
2441
3155
 
@@ -2943,6 +3657,9 @@ function inject_vue_imports(program, transform_context) {
2943
3657
 
2944
3658
  const iterable_source = transform_context.platform.imports.forOfIterableHelper;
2945
3659
  if (iterable_source) {
3660
+ if (transform_context.needs_for_items) {
3661
+ ensure_named_import(program, iterable_source, 'for_items', FOR_ITEMS_INTERNAL_NAME);
3662
+ }
2946
3663
  if (transform_context.needs_for_of_iterable) {
2947
3664
  ensure_named_import(program, iterable_source, 'map_iterable', MAP_ITERABLE_INTERNAL_NAME);
2948
3665
  }
@@ -3000,6 +3717,15 @@ function inject_vue_imports(program, transform_context) {
3000
3717
  );
3001
3718
  }
3002
3719
 
3720
+ if (transform_context.needs_pending_body) {
3721
+ ensure_named_import(
3722
+ program,
3723
+ transform_context.platform.imports.errorBoundary,
3724
+ 'TsrxPendingBody',
3725
+ PENDING_BODY_INTERNAL_NAME,
3726
+ );
3727
+ }
3728
+
3003
3729
  if (transform_context.needs_merge_refs && merge_refs_source) {
3004
3730
  ensure_named_import(program, merge_refs_source, 'mergeRefs', MERGE_REFS_INTERNAL_NAME);
3005
3731
  }