@tsrx/core 0.1.46 → 0.1.47
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 +2 -2
- package/src/parse/index.js +3 -2
- package/src/transform/jsx/ast-builders.js +131 -110
- package/src/transform/jsx/helpers.js +76 -81
- package/src/transform/jsx/index.js +342 -360
- package/src/transform/lazy.js +5 -5
- package/src/transform/segments.js +29 -28
- package/src/transform/style-ref.js +9 -13
- package/src/utils/ast.js +11 -0
- package/src/utils/builders.js +3 -3
- package/types/index.d.ts +86 -11
- package/types/jsx-platform.d.ts +88 -54
package/src/transform/lazy.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/** @import * as AST from 'estree' */
|
|
2
2
|
|
|
3
3
|
import * as b from '../utils/builders.js';
|
|
4
|
-
import { is_function_or_component_node } from '../utils/ast.js';
|
|
4
|
+
import { has_location, is_function_or_component_node } from '../utils/ast.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Lazy destructuring transform — framework-agnostic.
|
|
@@ -57,7 +57,7 @@ function generate_lazy_id(context) {
|
|
|
57
57
|
* @returns {any}
|
|
58
58
|
*/
|
|
59
59
|
function set_source_location(node, loc_info) {
|
|
60
|
-
if (loc_info
|
|
60
|
+
if (has_location(loc_info)) {
|
|
61
61
|
node.start = loc_info.start;
|
|
62
62
|
node.end = loc_info.end;
|
|
63
63
|
node.loc = loc_info.loc;
|
|
@@ -84,7 +84,7 @@ function create_generated_identifier(name, loc_info, source_name, source_length)
|
|
|
84
84
|
* @returns {{ start: number, end: number, loc: any, source_length: number } | null}
|
|
85
85
|
*/
|
|
86
86
|
function get_lazy_pattern_mapping_range(pattern) {
|
|
87
|
-
if (!pattern
|
|
87
|
+
if (!has_location(pattern)) return null;
|
|
88
88
|
|
|
89
89
|
const end = pattern.typeAnnotation?.start ?? pattern.end;
|
|
90
90
|
const end_loc = pattern.typeAnnotation?.loc?.start ?? pattern.loc.end;
|
|
@@ -148,11 +148,11 @@ function set_lazy_param_binding_mappings(lazy_id, pattern) {
|
|
|
148
148
|
|
|
149
149
|
const value = prop.value;
|
|
150
150
|
const actual = value.type === 'AssignmentPattern' ? value.left : value;
|
|
151
|
-
if (actual.type !== 'Identifier' || !actual
|
|
151
|
+
if (actual.type !== 'Identifier' || !has_location(actual)) continue;
|
|
152
152
|
|
|
153
153
|
const key_name = get_static_property_name(prop.key);
|
|
154
154
|
const generated = key_name == null ? null : type_keys.get(key_name);
|
|
155
|
-
if (generated
|
|
155
|
+
if (has_location(generated)) {
|
|
156
156
|
generated.metadata = { ...generated.metadata, disable_verification: true };
|
|
157
157
|
mappings.push({ source: actual, generated });
|
|
158
158
|
}
|
|
@@ -65,6 +65,7 @@ import {
|
|
|
65
65
|
get_mapping_from_node,
|
|
66
66
|
} from '../source-map-utils.js';
|
|
67
67
|
import { should_preserve_comment } from '../comment-utils.js';
|
|
68
|
+
import { has_location } from '../utils/ast.js';
|
|
68
69
|
|
|
69
70
|
const LAZY_PARAM_IDENTIFIER_REGEX = /^__lazy\d+$/;
|
|
70
71
|
|
|
@@ -453,8 +454,8 @@ export function convert_source_map_to_mappings(
|
|
|
453
454
|
* @returns {void}
|
|
454
455
|
*/
|
|
455
456
|
function set_bracket_computed_mapping(node, mappings) {
|
|
456
|
-
if (node.
|
|
457
|
-
const key =
|
|
457
|
+
if (has_location(node.key)) {
|
|
458
|
+
const key = node.key;
|
|
458
459
|
mappings.push(
|
|
459
460
|
get_mapping_from_node(
|
|
460
461
|
/** @type {AST.NodeWithLocation} */ ({
|
|
@@ -513,7 +514,7 @@ export function convert_source_map_to_mappings(
|
|
|
513
514
|
* @param {AST.Literal} node
|
|
514
515
|
*/
|
|
515
516
|
function handle_literal(node) {
|
|
516
|
-
if (node
|
|
517
|
+
if (has_location(node)) {
|
|
517
518
|
const mapping = get_mapping_from_node(node, src_to_gen_map, gen_line_offsets);
|
|
518
519
|
mappings.push(mapping);
|
|
519
520
|
}
|
|
@@ -524,12 +525,15 @@ export function convert_source_map_to_mappings(
|
|
|
524
525
|
* @returns {void}
|
|
525
526
|
*/
|
|
526
527
|
function add_extra_source_mapping_tokens(generated_node) {
|
|
527
|
-
if (
|
|
528
|
+
if (
|
|
529
|
+
!has_location(generated_node) ||
|
|
530
|
+
!Array.isArray(generated_node.metadata?.extra_source_mappings)
|
|
531
|
+
) {
|
|
528
532
|
return;
|
|
529
533
|
}
|
|
530
534
|
|
|
531
535
|
for (const source_node of generated_node.metadata.extra_source_mappings) {
|
|
532
|
-
if (!source_node
|
|
536
|
+
if (!has_location(source_node)) continue;
|
|
533
537
|
|
|
534
538
|
tokens.push({
|
|
535
539
|
source: source_node.name ?? generated_node.name,
|
|
@@ -537,10 +541,7 @@ export function convert_source_map_to_mappings(
|
|
|
537
541
|
loc: source_node.loc,
|
|
538
542
|
generatedLoc: generated_node.loc,
|
|
539
543
|
metadata: {},
|
|
540
|
-
sourceLength:
|
|
541
|
-
typeof source_node.start === 'number' && typeof source_node.end === 'number'
|
|
542
|
-
? source_node.end - source_node.start
|
|
543
|
-
: undefined,
|
|
544
|
+
sourceLength: source_node.end - source_node.start,
|
|
544
545
|
});
|
|
545
546
|
}
|
|
546
547
|
}
|
|
@@ -602,7 +603,7 @@ export function convert_source_map_to_mappings(
|
|
|
602
603
|
for (const binding_mapping of node.metadata.lazy_param_binding_mappings) {
|
|
603
604
|
const source_node = binding_mapping.source;
|
|
604
605
|
const generated_node = binding_mapping.generated;
|
|
605
|
-
if (!source_node
|
|
606
|
+
if (!has_location(source_node) || !has_location(generated_node)) continue;
|
|
606
607
|
|
|
607
608
|
const mapping = get_mapping_from_node(
|
|
608
609
|
generated_node,
|
|
@@ -610,8 +611,8 @@ export function convert_source_map_to_mappings(
|
|
|
610
611
|
gen_line_offsets,
|
|
611
612
|
mapping_data_verify_only,
|
|
612
613
|
);
|
|
613
|
-
const source_start =
|
|
614
|
-
const source_end =
|
|
614
|
+
const source_start = source_node.start;
|
|
615
|
+
const source_end = source_node.end;
|
|
615
616
|
mapping.sourceOffsets = [source_start];
|
|
616
617
|
mapping.lengths = [source_end - source_start];
|
|
617
618
|
mappings.push(mapping);
|
|
@@ -649,7 +650,7 @@ export function convert_source_map_to_mappings(
|
|
|
649
650
|
// We only map the 'import' and the last character
|
|
650
651
|
// to avoid overlapping with individual specifier mappings
|
|
651
652
|
// which would interfere when only SOME imports are unused.
|
|
652
|
-
if (node
|
|
653
|
+
if (has_location(node)) {
|
|
653
654
|
tokens.push({
|
|
654
655
|
source: 'import',
|
|
655
656
|
generated: 'import',
|
|
@@ -842,7 +843,7 @@ export function convert_source_map_to_mappings(
|
|
|
842
843
|
}
|
|
843
844
|
return;
|
|
844
845
|
} else if (node.type === 'JSXExpressionContainer') {
|
|
845
|
-
if (node
|
|
846
|
+
if (has_location(node)) {
|
|
846
847
|
mappings.push(
|
|
847
848
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
848
849
|
);
|
|
@@ -929,9 +930,9 @@ export function convert_source_map_to_mappings(
|
|
|
929
930
|
}
|
|
930
931
|
}
|
|
931
932
|
|
|
932
|
-
|
|
933
|
+
const target_node = closing ?? opening;
|
|
934
|
+
if (has_location(target_node) && (closing || opening.selfClosing)) {
|
|
933
935
|
// Add the whole closing tag or the self-closing.
|
|
934
|
-
const target_node = closing ? closing : opening;
|
|
935
936
|
const mapping = get_mapping_from_node(
|
|
936
937
|
target_node,
|
|
937
938
|
src_to_gen_map,
|
|
@@ -948,7 +949,7 @@ export function convert_source_map_to_mappings(
|
|
|
948
949
|
mapping.generatedLengths = [mapping.generatedLengths[0] + 1];
|
|
949
950
|
if (!closing && opening.selfClosing) {
|
|
950
951
|
const generated_close_length = '/>;'.length;
|
|
951
|
-
mapping.sourceOffsets = [
|
|
952
|
+
mapping.sourceOffsets = [target_node.end - 2];
|
|
952
953
|
mapping.lengths = ['/>'.length];
|
|
953
954
|
mapping.generatedOffsets = [
|
|
954
955
|
mapping.generatedOffsets[0] + mapping.generatedLengths[0] - generated_close_length,
|
|
@@ -970,7 +971,7 @@ export function convert_source_map_to_mappings(
|
|
|
970
971
|
) {
|
|
971
972
|
const is_method = node.metadata?.is_method;
|
|
972
973
|
|
|
973
|
-
if (node.type === 'ArrowFunctionExpression' && node
|
|
974
|
+
if (node.type === 'ArrowFunctionExpression' && has_location(node)) {
|
|
974
975
|
// The printer emits node-level boundary markers for arrows (their
|
|
975
976
|
// span can start at a bare `(`), so the strict lookup always
|
|
976
977
|
// resolves — no defensive has() guard.
|
|
@@ -1258,7 +1259,7 @@ export function convert_source_map_to_mappings(
|
|
|
1258
1259
|
visit(node.empty);
|
|
1259
1260
|
}
|
|
1260
1261
|
|
|
1261
|
-
if (node
|
|
1262
|
+
if (has_location(node)) {
|
|
1262
1263
|
mappings.push(
|
|
1263
1264
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
1264
1265
|
);
|
|
@@ -1328,7 +1329,7 @@ export function convert_source_map_to_mappings(
|
|
|
1328
1329
|
}
|
|
1329
1330
|
return;
|
|
1330
1331
|
} else if (node.type === 'CallExpression' || node.type === 'NewExpression') {
|
|
1331
|
-
if (node.type === 'NewExpression' && node
|
|
1332
|
+
if (node.type === 'NewExpression' && has_location(node)) {
|
|
1332
1333
|
mappings.push(
|
|
1333
1334
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
1334
1335
|
);
|
|
@@ -1358,7 +1359,7 @@ export function convert_source_map_to_mappings(
|
|
|
1358
1359
|
}
|
|
1359
1360
|
return;
|
|
1360
1361
|
} else if (node.type === 'MemberExpression') {
|
|
1361
|
-
if (node
|
|
1362
|
+
if (has_location(node)) {
|
|
1362
1363
|
const mapping = get_mapping_from_node(
|
|
1363
1364
|
node,
|
|
1364
1365
|
src_to_gen_map,
|
|
@@ -1375,7 +1376,7 @@ export function convert_source_map_to_mappings(
|
|
|
1375
1376
|
if (node.property) {
|
|
1376
1377
|
visit(node.property);
|
|
1377
1378
|
|
|
1378
|
-
if (node.computed && node.property
|
|
1379
|
+
if (node.computed && has_location(node.property)) {
|
|
1379
1380
|
mappings.push(
|
|
1380
1381
|
get_mapping_from_node(
|
|
1381
1382
|
node.property,
|
|
@@ -1411,7 +1412,7 @@ export function convert_source_map_to_mappings(
|
|
|
1411
1412
|
|
|
1412
1413
|
return;
|
|
1413
1414
|
} else if (node.type === 'ObjectExpression' || node.type === 'ObjectPattern') {
|
|
1414
|
-
if (node.
|
|
1415
|
+
if (node.type === 'ObjectExpression' && has_location(node)) {
|
|
1415
1416
|
mappings.push(
|
|
1416
1417
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
1417
1418
|
);
|
|
@@ -1474,7 +1475,7 @@ export function convert_source_map_to_mappings(
|
|
|
1474
1475
|
}
|
|
1475
1476
|
return;
|
|
1476
1477
|
} else if (node.type === 'TemplateLiteral') {
|
|
1477
|
-
if (node
|
|
1478
|
+
if (has_location(node)) {
|
|
1478
1479
|
mappings.push(
|
|
1479
1480
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
1480
1481
|
);
|
|
@@ -1505,7 +1506,7 @@ export function convert_source_map_to_mappings(
|
|
|
1505
1506
|
visit(node.argument);
|
|
1506
1507
|
}
|
|
1507
1508
|
|
|
1508
|
-
if (node.type === 'ReturnStatement' && node
|
|
1509
|
+
if (node.type === 'ReturnStatement' && has_location(node)) {
|
|
1509
1510
|
const mapping = get_mapping_from_node(
|
|
1510
1511
|
node,
|
|
1511
1512
|
src_to_gen_map,
|
|
@@ -1545,7 +1546,7 @@ export function convert_source_map_to_mappings(
|
|
|
1545
1546
|
}
|
|
1546
1547
|
}
|
|
1547
1548
|
|
|
1548
|
-
if (node
|
|
1549
|
+
if (has_location(node)) {
|
|
1549
1550
|
mappings.push(
|
|
1550
1551
|
get_mapping_from_node(node, src_to_gen_map, gen_line_offsets, mapping_data_verify_only),
|
|
1551
1552
|
);
|
|
@@ -1762,7 +1763,7 @@ export function convert_source_map_to_mappings(
|
|
|
1762
1763
|
}
|
|
1763
1764
|
return;
|
|
1764
1765
|
} else if (node.type === 'ParenthesizedExpression') {
|
|
1765
|
-
if (node.metadata.forceMapping && node
|
|
1766
|
+
if (node.metadata.forceMapping && has_location(node)) {
|
|
1766
1767
|
const mapping = get_mapping_from_node(node, src_to_gen_map, gen_line_offsets);
|
|
1767
1768
|
if (node.metadata.skipParenthesisMapping) {
|
|
1768
1769
|
mapping.generatedOffsets[0] = mapping.generatedOffsets[0] + 1; // Skip the opening parenthesis
|
|
@@ -1801,7 +1802,7 @@ export function convert_source_map_to_mappings(
|
|
|
1801
1802
|
node.type === 'TSTypeParameterInstantiation' ||
|
|
1802
1803
|
node.type === 'TSTypeParameterDeclaration'
|
|
1803
1804
|
) {
|
|
1804
|
-
if (node
|
|
1805
|
+
if (has_location(node)) {
|
|
1805
1806
|
const mapping = get_mapping_from_node(
|
|
1806
1807
|
node,
|
|
1807
1808
|
src_to_gen_map,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import * as b from '../utils/builders.js';
|
|
4
4
|
import { is_function_or_class_node as is_function_or_class_boundary } from '../utils/ast.js';
|
|
5
|
-
import {
|
|
5
|
+
import { clone_ast_node, clone_identifier } from './jsx/ast-builders.js';
|
|
6
6
|
|
|
7
7
|
const regex_backslash_and_following_character = /\\(.)/g;
|
|
8
8
|
|
|
@@ -131,14 +131,10 @@ function create_style_ref_expression_statements(source, style_map, options) {
|
|
|
131
131
|
options.allowMutableRefTarget !== false &&
|
|
132
132
|
(source.type === 'Identifier' || source.type === 'MemberExpression')
|
|
133
133
|
) {
|
|
134
|
-
const target =
|
|
134
|
+
const target = clone_ast_node(source, false);
|
|
135
135
|
return [
|
|
136
136
|
b.stmt(
|
|
137
|
-
b.assignment(
|
|
138
|
-
'=',
|
|
139
|
-
/** @type {AST.Pattern} */ (target),
|
|
140
|
-
clone_expression_node(style_map, false),
|
|
141
|
-
),
|
|
137
|
+
b.assignment('=', /** @type {AST.Pattern} */ (target), clone_ast_node(style_map, false)),
|
|
142
138
|
),
|
|
143
139
|
];
|
|
144
140
|
}
|
|
@@ -147,8 +143,8 @@ function create_style_ref_expression_statements(source, style_map, options) {
|
|
|
147
143
|
return [
|
|
148
144
|
b.stmt(
|
|
149
145
|
b.call(
|
|
150
|
-
visit_expression(
|
|
151
|
-
|
|
146
|
+
visit_expression(clone_ast_node(source, false), options),
|
|
147
|
+
clone_ast_node(style_map, false),
|
|
152
148
|
),
|
|
153
149
|
),
|
|
154
150
|
];
|
|
@@ -167,17 +163,17 @@ function create_dynamic_style_ref_statement(source, style_map, options) {
|
|
|
167
163
|
const ref_id = options.createTempIdentifier?.() ?? b.id('__tsrx_style_ref');
|
|
168
164
|
const ref_read = () => clone_identifier(ref_id);
|
|
169
165
|
const current_write = b.stmt(
|
|
170
|
-
b.assignment('=', b.member(ref_read(), 'current'),
|
|
166
|
+
b.assignment('=', b.member(ref_read(), 'current'), clone_ast_node(style_map, false)),
|
|
171
167
|
);
|
|
172
168
|
const value_write = b.stmt(
|
|
173
|
-
b.assignment('=', b.member(ref_read(), 'value'),
|
|
169
|
+
b.assignment('=', b.member(ref_read(), 'value'), clone_ast_node(style_map, false)),
|
|
174
170
|
);
|
|
175
171
|
|
|
176
172
|
return [
|
|
177
|
-
b.let(ref_id, visit_expression(
|
|
173
|
+
b.let(ref_id, visit_expression(clone_ast_node(source, false), options)),
|
|
178
174
|
b.if(
|
|
179
175
|
b.binary('===', b.unary('typeof', ref_read()), b.literal('function')),
|
|
180
|
-
b.block([b.stmt(b.call(ref_read(),
|
|
176
|
+
b.block([b.stmt(b.call(ref_read(), clone_ast_node(style_map, false)))]),
|
|
181
177
|
b.if(
|
|
182
178
|
b.logical(
|
|
183
179
|
'&&',
|
package/src/utils/ast.js
CHANGED
|
@@ -20,6 +20,17 @@
|
|
|
20
20
|
|
|
21
21
|
import * as b from './builders.js';
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* @template {object} T
|
|
25
|
+
* @param {T | null | undefined} node
|
|
26
|
+
* @returns {node is T & AST.NodeWithLocation}
|
|
27
|
+
*/
|
|
28
|
+
export function has_location(node) {
|
|
29
|
+
if (node == null) return false;
|
|
30
|
+
const location = /** @type {Partial<AST.NodeWithLocation>} */ (node);
|
|
31
|
+
return location.loc != null && location.start !== undefined && location.end !== undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
23
34
|
/**
|
|
24
35
|
* @param {AST.Node} node
|
|
25
36
|
* @returns {node is AST.Function}
|
package/src/utils/builders.js
CHANGED
|
@@ -1121,7 +1121,7 @@ export function key(name) {
|
|
|
1121
1121
|
|
|
1122
1122
|
/**
|
|
1123
1123
|
* @param {ESTreeJSX.JSXIdentifier | ESTreeJSX.JSXNamespacedName} name
|
|
1124
|
-
* @param {
|
|
1124
|
+
* @param {ESTreeJSX.JSXAttribute['value']} value
|
|
1125
1125
|
* @param {boolean} [shorthand]
|
|
1126
1126
|
* @param {AST.NodeWithLocation} [loc_info]
|
|
1127
1127
|
* @returns {ESTreeJSX.JSXAttribute}
|
|
@@ -1142,7 +1142,7 @@ export function jsx_attribute(name, value = null, shorthand = false, loc_info) {
|
|
|
1142
1142
|
* Build a fresh `JSXOpeningElement`. For elements derived from an existing
|
|
1143
1143
|
* JSX element node, prefer `jsx_element` which spreads from the source.
|
|
1144
1144
|
*
|
|
1145
|
-
* @param {ESTreeJSX.
|
|
1145
|
+
* @param {ESTreeJSX.TSRXJSXOpeningElement['name']} name
|
|
1146
1146
|
* @param {ESTreeJSX.JSXOpeningElement['attributes']} [attributes]
|
|
1147
1147
|
* @param {boolean} [self_closing]
|
|
1148
1148
|
* @param {ESTreeJSX.JSXOpeningElement['typeArguments']} [type_arguments]
|
|
@@ -1171,7 +1171,7 @@ export function jsx_opening_element(
|
|
|
1171
1171
|
/**
|
|
1172
1172
|
* Build a fresh `JSXClosingElement`.
|
|
1173
1173
|
*
|
|
1174
|
-
* @param {ESTreeJSX.
|
|
1174
|
+
* @param {ESTreeJSX.TSRXJSXClosingElement['name']} name
|
|
1175
1175
|
* @param {AST.NodeWithLocation} [loc_info]
|
|
1176
1176
|
* @returns {ESTreeJSX.JSXClosingElement}
|
|
1177
1177
|
*/
|
package/types/index.d.ts
CHANGED
|
@@ -24,11 +24,23 @@ export type {
|
|
|
24
24
|
};
|
|
25
25
|
export { createJsxTransform };
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
export
|
|
29
|
-
|
|
27
|
+
/** Result of extracting a branch body into a generated helper component. */
|
|
28
|
+
export interface JsxHelperComponent {
|
|
29
|
+
setup_statements: AST.Statement[];
|
|
30
|
+
component_element: ESTreeJSX.JSXElement;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function collectStyleRefAttributes(
|
|
34
|
+
node: AST.Node | AST.Node[],
|
|
35
|
+
refs?: ESTreeJSX.JSXAttribute[],
|
|
36
|
+
): ESTreeJSX.JSXAttribute[];
|
|
37
|
+
export function createStyleClassMap(
|
|
38
|
+
component: AST.Node,
|
|
39
|
+
css: AST.CSS.StyleSheet,
|
|
40
|
+
): AST.ObjectExpression;
|
|
41
|
+
export function createStyleClassMapFromStylesheet(css: AST.CSS.StyleSheet): AST.ObjectExpression;
|
|
30
42
|
export function createStyleRefSetupStatements(
|
|
31
|
-
refAttributes:
|
|
43
|
+
refAttributes: ESTreeJSX.JSXAttribute[],
|
|
32
44
|
styleMap: AST.Expression,
|
|
33
45
|
options?: {
|
|
34
46
|
allowMutableRefTarget?: boolean;
|
|
@@ -36,7 +48,9 @@ export function createStyleRefSetupStatements(
|
|
|
36
48
|
visitExpression?: (expression: AST.Expression) => AST.Expression;
|
|
37
49
|
},
|
|
38
50
|
): AST.Statement[];
|
|
39
|
-
export function getStyleElementStylesheet(
|
|
51
|
+
export function getStyleElementStylesheet(
|
|
52
|
+
styleElement: AST.JSXStyleElement,
|
|
53
|
+
): AST.CSS.StyleSheet | null;
|
|
40
54
|
|
|
41
55
|
/**
|
|
42
56
|
* Compile error interface
|
|
@@ -119,11 +133,11 @@ interface BaseNodeMetaData {
|
|
|
119
133
|
/** Memoized `<> … </>` wrapper for a value-position directive (see get_directive_value_wrapper). */
|
|
120
134
|
tsrx_value_wrapper?: AST.TSRXJSXFragment;
|
|
121
135
|
ts_name?: string;
|
|
122
|
-
delegated?:
|
|
136
|
+
delegated?: boolean;
|
|
123
137
|
returned_tsrx_return?: AST.ReturnStatement;
|
|
124
138
|
styleScopeHash?: string;
|
|
125
139
|
css?: {
|
|
126
|
-
scopedClasses:
|
|
140
|
+
scopedClasses: TopScopedClasses;
|
|
127
141
|
hash: string;
|
|
128
142
|
};
|
|
129
143
|
elementLeadingComments?: AST.Comment[];
|
|
@@ -139,6 +153,12 @@ interface BaseNodeMetaData {
|
|
|
139
153
|
generated_loop_skip_if?: boolean;
|
|
140
154
|
lazy_id?: string;
|
|
141
155
|
disable_verification?: boolean;
|
|
156
|
+
extra_source_mappings?: AST.NodeWithLocation[];
|
|
157
|
+
generated_setup_declarations?: AST.Statement[];
|
|
158
|
+
has_unmappable_value?: boolean;
|
|
159
|
+
synthetic_ref?: boolean;
|
|
160
|
+
tsrx_reactive_block?: boolean;
|
|
161
|
+
vapor_pending_fallback?: ESTreeJSX.JSXRenderNode;
|
|
142
162
|
lazy_param_binding_mappings?: Array<{
|
|
143
163
|
source: AST.Identifier;
|
|
144
164
|
generated: AST.Identifier | AST.Literal;
|
|
@@ -156,8 +176,8 @@ interface FunctionMetaData extends BaseNodeMetaData {
|
|
|
156
176
|
/** Top-level scoped classes collected while pruning the component's CSS. */
|
|
157
177
|
topScopedClasses?: TopScopedClasses;
|
|
158
178
|
synthetic_children?: boolean;
|
|
159
|
-
generated_helpers?:
|
|
160
|
-
generated_statics?:
|
|
179
|
+
generated_helpers?: AST.Statement[];
|
|
180
|
+
generated_statics?: AST.Statement[];
|
|
161
181
|
}
|
|
162
182
|
|
|
163
183
|
// Strip parent, loc, and range from TSESTree nodes to match @sveltejs/acorn-typescript output
|
|
@@ -445,6 +465,25 @@ declare module 'estree' {
|
|
|
445
465
|
| JSXSwitchExpression
|
|
446
466
|
| JSXTryExpression;
|
|
447
467
|
|
|
468
|
+
/** A statement-form template directive after its parser node has been retyped. */
|
|
469
|
+
type JSXTemplateStatement =
|
|
470
|
+
| (AST.IfStatement & { statementType: 'IfStatement' })
|
|
471
|
+
| (AST.ForOfStatement & { statementType: 'ForOfStatement' })
|
|
472
|
+
| (AST.SwitchStatement & { statementType: 'SwitchStatement' })
|
|
473
|
+
| (AST.TryStatement & { statementType: 'TryStatement' });
|
|
474
|
+
|
|
475
|
+
/** A source node that the shared JSX transform can lower into a JSX child. */
|
|
476
|
+
type TSRXRenderChild =
|
|
477
|
+
| ESTreeJSX.JSXElement
|
|
478
|
+
| ESTreeJSX.JSXFragment
|
|
479
|
+
| ESTreeJSX.JSXExpressionContainer
|
|
480
|
+
| ESTreeJSX.JSXText
|
|
481
|
+
| JSXTemplateDirective
|
|
482
|
+
| JSXTemplateStatement;
|
|
483
|
+
|
|
484
|
+
/** An AST node that represents component-level `await` during validation. */
|
|
485
|
+
type TSRXAwaitNode = AST.AwaitExpression | AST.ForOfStatement | JSXForOfExpression;
|
|
486
|
+
|
|
448
487
|
/** Any node that can be the rendered output of a TSRX template or statement container. */
|
|
449
488
|
type TSRXRenderOutput =
|
|
450
489
|
| ESTreeJSX.JSXElement
|
|
@@ -453,6 +492,9 @@ declare module 'estree' {
|
|
|
453
492
|
| JSXCodeBlock
|
|
454
493
|
| JSXTemplateDirective;
|
|
455
494
|
|
|
495
|
+
/** A parser node whose body uses native TSRX template semantics. */
|
|
496
|
+
type NativeTSRXNode = TSRXJSXElement | TSRXJSXFragment | JSXStyleElement | JSXCodeBlock;
|
|
497
|
+
|
|
456
498
|
interface ParenthesizedExpression extends AST.BaseNode {
|
|
457
499
|
type: 'ParenthesizedExpression';
|
|
458
500
|
expression: AST.Expression;
|
|
@@ -480,14 +522,24 @@ declare module 'estree' {
|
|
|
480
522
|
type CommentWithLocation = AST.Comment & NodeWithLocation;
|
|
481
523
|
|
|
482
524
|
interface TryStatement {
|
|
525
|
+
statementType?: 'TryStatement';
|
|
483
526
|
pending?: AST.BlockStatement | null;
|
|
484
527
|
}
|
|
485
528
|
|
|
529
|
+
interface IfStatement {
|
|
530
|
+
statementType?: 'IfStatement';
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
interface SwitchStatement {
|
|
534
|
+
statementType?: 'SwitchStatement';
|
|
535
|
+
}
|
|
536
|
+
|
|
486
537
|
interface CatchClause {
|
|
487
538
|
resetParam?: AST.Pattern | null;
|
|
488
539
|
}
|
|
489
540
|
|
|
490
541
|
interface ForOfStatement {
|
|
542
|
+
statementType?: 'ForOfStatement';
|
|
491
543
|
index?: AST.Identifier | null;
|
|
492
544
|
key?: AST.Expression | null;
|
|
493
545
|
empty?: AST.BlockStatement | null;
|
|
@@ -733,6 +785,27 @@ declare module 'estree' {
|
|
|
733
785
|
}
|
|
734
786
|
|
|
735
787
|
declare module 'estree-jsx' {
|
|
788
|
+
/** A node that can be returned from a platform hook into a JSX render slot. */
|
|
789
|
+
type JSXRenderNode = AST.Expression | JSXExpressionContainer | JSXText | JSXSpreadChild;
|
|
790
|
+
|
|
791
|
+
/** A JSX child produced by the transform's render-body lowering. */
|
|
792
|
+
type JSXRenderChild = JSXElement | JSXFragment | JSXExpressionContainer | JSXText;
|
|
793
|
+
|
|
794
|
+
/** An attribute accepted by and emitted from the shared JSX transformer. */
|
|
795
|
+
type JSXAttributeNode = JSXAttribute | JSXSpreadAttribute;
|
|
796
|
+
|
|
797
|
+
/** A `ref` attribute whose value has been narrowed to a non-empty expression. */
|
|
798
|
+
interface JSXRefAttribute extends JSXAttribute {
|
|
799
|
+
name: JSXIdentifier;
|
|
800
|
+
value: JSXExpressionContainer & { expression: AST.Expression };
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/** A child accepted while TSRX JSX is being lowered to standard ESTree JSX. */
|
|
804
|
+
type JSXTransformChild =
|
|
805
|
+
| JSXElement['children'][number]
|
|
806
|
+
| AST.TSRXJSXElement
|
|
807
|
+
| AST.TSRXJSXFragment;
|
|
808
|
+
|
|
736
809
|
interface JSXAttribute {
|
|
737
810
|
shorthand: boolean;
|
|
738
811
|
}
|
|
@@ -785,7 +858,8 @@ declare module 'estree-jsx' {
|
|
|
785
858
|
| JSXIdentifier
|
|
786
859
|
| JSXNamespacedName
|
|
787
860
|
| JSXExpressionContainer
|
|
788
|
-
|
|
|
861
|
+
| AST.Identifier
|
|
862
|
+
| AST.MemberExpression;
|
|
789
863
|
}
|
|
790
864
|
|
|
791
865
|
interface TSRXJSXClosingElement extends Omit<JSXClosingElement, 'name'> {
|
|
@@ -795,7 +869,8 @@ declare module 'estree-jsx' {
|
|
|
795
869
|
| JSXIdentifier
|
|
796
870
|
| JSXNamespacedName
|
|
797
871
|
| JSXExpressionContainer
|
|
798
|
-
|
|
|
872
|
+
| AST.Identifier
|
|
873
|
+
| AST.MemberExpression;
|
|
799
874
|
}
|
|
800
875
|
|
|
801
876
|
interface ExpressionMap {
|