@tsrx/core 0.1.47 → 0.1.49

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.
@@ -3,6 +3,7 @@
3
3
 
4
4
  import tsx from 'esrap/languages/tsx';
5
5
  import { should_preserve_comment, format_comment } from '../../comment-utils.js';
6
+ import { with_deferred_imports } from '../imports.js';
6
7
 
7
8
  /**
8
9
  * Zimmerframe provides `path` as the ancestor chain. A native template node in
@@ -75,7 +76,7 @@ export function set_node_path_metadata(node, path) {
75
76
  * TS input — dropping a leading pragma changes how the whole file checks.
76
77
  */
77
78
  export function tsx_with_ts_locations(boundary_tokens = false, comments = undefined) {
78
- const base = tsx({ boundaryTokens: boundary_tokens });
79
+ const base = with_deferred_imports(tsx({ boundaryTokens: boundary_tokens }));
79
80
  const { _: base_visitor, ...base_visitors } = base;
80
81
 
81
82
  const leading_preserved = (/** @type {AST.Program} */ program) => {
@@ -251,7 +252,7 @@ const LOCATION_WRAPPED_NODE_TYPES = new Set([
251
252
 
252
253
  /**
253
254
  * @param {AST.Node | null | undefined} node
254
- * @returns {boolean}
255
+ * @returns {node is AST.JSXIfExpression | (AST.IfStatement & { statementType: 'IfStatement' })}
255
256
  */
256
257
  export function is_template_if_node(node) {
257
258
  return (
@@ -261,19 +262,24 @@ export function is_template_if_node(node) {
261
262
  }
262
263
 
263
264
  /**
265
+ * A `@for … of …` directive, in either the expression or the retyped statement
266
+ * form. `JSXForExpression` also covers `@for … in …` and plain `@for (;;)`, so
267
+ * both arms must check `statementType` — callers read for-of-only fields such
268
+ * as `await` off the result.
269
+ *
264
270
  * @param {AST.Node | null | undefined} node
265
- * @returns {boolean}
271
+ * @returns {node is AST.JSXForOfExpression | (AST.ForOfStatement & { statementType: 'ForOfStatement' })}
266
272
  */
267
273
  export function is_template_for_of_node(node) {
268
274
  return (
269
- node?.type === 'JSXForExpression' ||
270
- (node?.type === 'ForOfStatement' && node?.statementType === 'ForOfStatement')
275
+ (node?.type === 'JSXForExpression' || node?.type === 'ForOfStatement') &&
276
+ node.statementType === 'ForOfStatement'
271
277
  );
272
278
  }
273
279
 
274
280
  /**
275
281
  * @param {AST.Node | null | undefined} node
276
- * @returns {boolean}
282
+ * @returns {node is AST.JSXSwitchExpression | (AST.SwitchStatement & { statementType: 'SwitchStatement' })}
277
283
  */
278
284
  export function is_template_switch_node(node) {
279
285
  return (
@@ -284,7 +290,7 @@ export function is_template_switch_node(node) {
284
290
 
285
291
  /**
286
292
  * @param {AST.Node | null | undefined} node
287
- * @returns {boolean}
293
+ * @returns {node is AST.JSXTryExpression | (AST.TryStatement & { statementType: 'TryStatement' })}
288
294
  */
289
295
  export function is_template_try_node(node) {
290
296
  return (