@tsrx/core 0.1.22 → 0.1.25
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 +1 -1
- package/src/analyze/prune.js +12 -23
- package/src/analyze/validation.js +1 -1
- package/src/diagnostics.js +1 -0
- package/src/index.js +0 -2
- package/src/plugin.js +267 -126
- package/src/runtime/html.js +1 -1
- package/src/runtime/language-helpers.js +39 -0
- package/src/transform/jsx/ast-builders.js +2 -62
- package/src/transform/jsx/index.js +596 -1138
- package/src/transform/scoping.js +1 -1
- package/src/transform/segments.js +13 -43
- package/types/index.d.ts +2 -7
- package/types/jsx-platform.d.ts +11 -8
- package/types/runtime/html.d.ts +1 -0
- package/types/runtime/language-helpers.d.ts +4 -0
|
@@ -89,3 +89,42 @@ export function iterable_array_from(iterable, index = 0) {
|
|
|
89
89
|
}
|
|
90
90
|
return result;
|
|
91
91
|
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a shallow forwarding object without one prop. Values are exposed through
|
|
95
|
+
* getters so compiler-emitted reactive prop accessors are not snapshotted.
|
|
96
|
+
* @param {Record<PropertyKey, any> | null | undefined} props
|
|
97
|
+
* @param {PropertyKey} exclude_prop
|
|
98
|
+
* @returns {Record<PropertyKey, any>}
|
|
99
|
+
*/
|
|
100
|
+
export function exclude_prop_from_object(props, exclude_prop) {
|
|
101
|
+
/** @type {Record<PropertyKey, any>} */
|
|
102
|
+
const next = {};
|
|
103
|
+
if (props == null) return next;
|
|
104
|
+
|
|
105
|
+
for (const prop of Reflect.ownKeys(props)) {
|
|
106
|
+
if (prop === exclude_prop) continue;
|
|
107
|
+
|
|
108
|
+
const descriptor = get_descriptor(props, prop);
|
|
109
|
+
if (!descriptor?.enumerable) continue;
|
|
110
|
+
|
|
111
|
+
/** @type {PropertyDescriptor} */
|
|
112
|
+
const forwarding_descriptor = {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
configurable: true,
|
|
115
|
+
get() {
|
|
116
|
+
return props[prop];
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (descriptor.writable === true || typeof descriptor.set === 'function') {
|
|
121
|
+
forwarding_descriptor.set = (value) => {
|
|
122
|
+
props[prop] = value;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
define_property(next, prop, forwarding_descriptor);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return next;
|
|
130
|
+
}
|
|
@@ -89,44 +89,6 @@ export function clone_jsx_name(name, source_node = name) {
|
|
|
89
89
|
return name;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
/**
|
|
93
|
-
* Convert a JSX tag name back into a JavaScript expression. Dynamic element
|
|
94
|
-
* tags are parsed as JSX-shaped names, but the runtime alias needs ordinary JS.
|
|
95
|
-
*
|
|
96
|
-
* @param {any} name
|
|
97
|
-
* @returns {any}
|
|
98
|
-
*/
|
|
99
|
-
export function jsx_name_to_expression(name) {
|
|
100
|
-
if (!name) return name;
|
|
101
|
-
if (name.type === 'JSXIdentifier') {
|
|
102
|
-
return set_loc(
|
|
103
|
-
/** @type {any} */ ({
|
|
104
|
-
type: 'Identifier',
|
|
105
|
-
name: name.name,
|
|
106
|
-
metadata: name.metadata || { path: [] },
|
|
107
|
-
}),
|
|
108
|
-
name,
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
if (name.type === 'JSXMemberExpression') {
|
|
112
|
-
return set_loc(
|
|
113
|
-
/** @type {any} */ ({
|
|
114
|
-
type: 'MemberExpression',
|
|
115
|
-
object: jsx_name_to_expression(name.object),
|
|
116
|
-
property: jsx_name_to_expression(name.property),
|
|
117
|
-
computed: false,
|
|
118
|
-
optional: false,
|
|
119
|
-
metadata: name.metadata || { path: [] },
|
|
120
|
-
}),
|
|
121
|
-
name,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
if (name.type === 'Identifier' || name.type === 'MemberExpression') {
|
|
125
|
-
return clone_expression_node(name);
|
|
126
|
-
}
|
|
127
|
-
return name;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
92
|
/**
|
|
131
93
|
* @returns {AST.Literal}
|
|
132
94
|
*/
|
|
@@ -342,26 +304,6 @@ export function is_bare_render_expression(node) {
|
|
|
342
304
|
}
|
|
343
305
|
}
|
|
344
306
|
|
|
345
|
-
/**
|
|
346
|
-
* A dynamic element id is one whose identifier is `tracked` — i.e. it was
|
|
347
|
-
* introduced by reactive destructuring so its value can change at runtime.
|
|
348
|
-
*
|
|
349
|
-
* @param {any} id
|
|
350
|
-
* @returns {boolean}
|
|
351
|
-
*/
|
|
352
|
-
export function is_dynamic_element_id(id) {
|
|
353
|
-
if (!id || typeof id !== 'object') {
|
|
354
|
-
return false;
|
|
355
|
-
}
|
|
356
|
-
if (id.type === 'Identifier' || id.type === 'JSXIdentifier') {
|
|
357
|
-
return !!id.tracked;
|
|
358
|
-
}
|
|
359
|
-
if (id.type === 'MemberExpression' || id.type === 'JSXMemberExpression') {
|
|
360
|
-
return is_dynamic_element_id(id.object);
|
|
361
|
-
}
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
|
|
365
307
|
/**
|
|
366
308
|
* Gather the params a `for (x of y; index i)` loop should expose to its body
|
|
367
309
|
* JSX (value first, optional index second).
|
|
@@ -431,10 +373,8 @@ function is_static_string_expression(expression) {
|
|
|
431
373
|
* When the expression is statically a non-null string at the AST level —
|
|
432
374
|
* a string `Literal` (`"hello"`, `'hello'`) or a `TemplateLiteral` with no
|
|
433
375
|
* interpolations (`` `hello` ``) — the coercion is provably a no-op and
|
|
434
|
-
* the literal is emitted as-is.
|
|
435
|
-
*
|
|
436
|
-
* still get the ternary because the AST alone can't prove they're non-null
|
|
437
|
-
* strings.
|
|
376
|
+
* the literal is emitted as-is. Identifiers and any other expression type still
|
|
377
|
+
* get the ternary because the AST alone can't prove they're non-null strings.
|
|
438
378
|
*
|
|
439
379
|
* @param {AST.Expression} expression
|
|
440
380
|
* @param {any} [source_node]
|