@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.
- package/package.json +5 -4
- package/src/index.js +6 -0
- package/src/plugin.js +131 -25
- package/src/runtime/language-helpers.js +57 -0
- package/src/runtime/ref.js +250 -0
- package/src/scope.js +7 -0
- package/src/transform/jsx/ast-builders.js +14 -13
- package/src/transform/jsx/index.js +490 -55
- package/src/transform/segments.js +19 -9
- package/types/index.d.ts +20 -1
- package/types/jsx-platform.d.ts +14 -1
- package/types/parse.d.ts +1 -1
- package/types/runtime/ref.d.ts +32 -0
- package/src/runtime/merge-refs.js +0 -61
- package/types/runtime/merge-refs.d.ts +0 -12
|
@@ -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.
|
|
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 = {
|
|
392
|
-
|
|
393
|
-
|
|
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 =
|
|
396
|
+
clone.metadata = node.metadata ? { ...node.metadata } : { path: [] };
|
|
396
397
|
continue;
|
|
397
398
|
}
|
|
398
|
-
clone[key] = clone_expression_node(
|
|
399
|
+
clone[key] = clone_expression_node(node[key], with_locations);
|
|
399
400
|
}
|
|
400
401
|
return clone;
|
|
401
402
|
}
|