@tsrx/core 0.0.27 → 0.1.0

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.
@@ -143,7 +143,7 @@ export function identifier_to_jsx_name(id) {
143
143
  /** @type {any} */ ({
144
144
  type: 'JSXIdentifier',
145
145
  name: id.name,
146
- metadata: { path: [], is_component: /^[A-Z]/.test(id.name) },
146
+ metadata: { ...(id.metadata || {}), path: [], is_component: /^[A-Z]/.test(id.name) },
147
147
  }),
148
148
  id,
149
149
  );
@@ -175,6 +175,7 @@ export function is_jsx_child(node) {
175
175
  t === 'JSXExpressionContainer' ||
176
176
  t === 'JSXText' ||
177
177
  t === 'Tsx' ||
178
+ t === 'Tsrx' ||
178
179
  t === 'TsxCompat' ||
179
180
  t === 'Element' ||
180
181
  t === 'Text' ||
@@ -376,26 +377,26 @@ export function to_text_expression(expression, source_node = expression) {
376
377
  }
377
378
 
378
379
  /**
379
- * Deep-clone an AST subtree. `loc` / `start` / `end` are shallow-shared by
380
- * reference rather than recursed into — `loc` objects can contain back-refs
381
- * to sub-objects that would blow the stack with a naive deep clone, and
382
- * every other traversal in the targets treats these positional keys as
383
- * shared.
380
+ * Deep-clone an AST subtree.
384
381
  *
385
382
  * @param {any} node
383
+ * @param {boolean} with_locations
386
384
  * @returns {any}
387
385
  */
388
- export function clone_expression_node(node) {
386
+ export function clone_expression_node(node, with_locations = true) {
389
387
  if (!node || typeof node !== 'object') return node;
390
- if (Array.isArray(node)) return node.map(clone_expression_node);
391
- const clone = { ...node };
392
- for (const key of Object.keys(clone)) {
393
- if (key === 'loc' || key === 'start' || key === 'end') continue;
388
+ if (Array.isArray(node)) return node.map((child) => clone_expression_node(child, with_locations));
389
+ const clone = /** @type {Record<string, any>} */ ({});
390
+
391
+ for (const key of Object.keys(node)) {
392
+ if (!with_locations && (key === 'loc' || key === 'start' || key === 'end')) {
393
+ continue;
394
+ }
394
395
  if (key === 'metadata') {
395
- clone.metadata = clone.metadata ? { ...clone.metadata } : { path: [] };
396
+ clone.metadata = node.metadata ? { ...node.metadata } : { path: [] };
396
397
  continue;
397
398
  }
398
- clone[key] = clone_expression_node(clone[key]);
399
+ clone[key] = clone_expression_node(node[key], with_locations);
399
400
  }
400
401
  return clone;
401
402
  }