@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.
- package/package.json +1 -1
- package/src/index.js +1 -1
- package/src/plugin.js +177 -42
- package/src/transform/await.js +14 -12
- package/src/transform/imports.js +96 -0
- package/src/transform/jsx/ast-builders.js +2 -81
- package/src/transform/jsx/helpers.js +13 -7
- package/src/transform/jsx/index.js +951 -727
- package/src/transform/jsx-hoist.js +2 -1
- package/src/transform/jsx-interleave.js +22 -36
- package/src/transform/scoping.js +4 -2
- package/src/transform/segments.js +20 -6
- package/src/utils/ast.js +37 -0
- package/src/utils/builders.js +22 -15
- package/types/helpers.d.ts +1 -2
- package/types/index.d.ts +88 -17
- package/types/jsx-platform.d.ts +18 -8
- package/types/parse.d.ts +66 -8
- package/types/runtime/ref.d.ts +1 -5
|
@@ -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 {
|
|
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 {
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
293
|
+
* @returns {node is AST.JSXTryExpression | (AST.TryStatement & { statementType: 'TryStatement' })}
|
|
288
294
|
*/
|
|
289
295
|
export function is_template_try_node(node) {
|
|
290
296
|
return (
|