@tsrx/solid 0.0.18 → 0.0.19
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 +2 -2
- package/src/index.js +19 -4
- package/src/transform.js +53 -16
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Solid compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.19",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"esrap": "^2.1.0",
|
|
24
24
|
"zimmerframe": "^1.1.2",
|
|
25
|
-
"@tsrx/core": "0.0.
|
|
25
|
+
"@tsrx/core": "0.0.19"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"solid-js": ">=1.8 || >=2.0.0-beta"
|
package/src/index.js
CHANGED
|
@@ -26,9 +26,19 @@ export function parse(source, filename, options) {
|
|
|
26
26
|
*/
|
|
27
27
|
export function compile(source, filename, options) {
|
|
28
28
|
const errors = /** @type {CompileError[]} */ ([]);
|
|
29
|
+
const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
|
|
29
30
|
const collect = !!options?.loose;
|
|
30
|
-
const ast = parseModule(
|
|
31
|
-
|
|
31
|
+
const ast = parseModule(
|
|
32
|
+
source,
|
|
33
|
+
filename,
|
|
34
|
+
collect ? { loose: true, errors, comments } : undefined,
|
|
35
|
+
);
|
|
36
|
+
const { ast: _ast, ...result } = transform(
|
|
37
|
+
ast,
|
|
38
|
+
source,
|
|
39
|
+
filename,
|
|
40
|
+
collect ? { loose: true, errors, comments } : undefined,
|
|
41
|
+
);
|
|
32
42
|
return { ...result, errors };
|
|
33
43
|
}
|
|
34
44
|
|
|
@@ -42,8 +52,13 @@ export function compile(source, filename, options) {
|
|
|
42
52
|
*/
|
|
43
53
|
export function compile_to_volar_mappings(source, filename, options) {
|
|
44
54
|
const errors = /** @type {import('@tsrx/core/types').CompileError[]} */ ([]);
|
|
45
|
-
const
|
|
46
|
-
const
|
|
55
|
+
const comments = /** @type {AST.CommentWithLocation[]} */ ([]);
|
|
56
|
+
const ast = parseModule(source, filename, { ...options, errors, comments });
|
|
57
|
+
const transformed = transform(ast, source, filename, {
|
|
58
|
+
loose: true,
|
|
59
|
+
errors,
|
|
60
|
+
comments,
|
|
61
|
+
});
|
|
47
62
|
const result = createVolarMappingsResult({
|
|
48
63
|
ast: transformed.ast,
|
|
49
64
|
ast_from_source: ast,
|
package/src/transform.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** @import * as AST from 'estree' */
|
|
2
2
|
/** @import * as ESTreeJSX from 'estree-jsx' */
|
|
3
|
+
/** @import { JsxTransformContext } from '@tsrx/core/types' */
|
|
3
4
|
|
|
4
5
|
import {
|
|
5
6
|
createJsxTransform,
|
|
7
|
+
error,
|
|
6
8
|
mergeDuplicateRefs,
|
|
7
9
|
toJsxAttribute,
|
|
8
10
|
validateAtMostOneRefAttribute,
|
|
@@ -18,7 +20,6 @@ import {
|
|
|
18
20
|
clone_expression_node,
|
|
19
21
|
clone_identifier,
|
|
20
22
|
clone_jsx_name,
|
|
21
|
-
create_compile_error,
|
|
22
23
|
create_generated_identifier,
|
|
23
24
|
create_null_literal,
|
|
24
25
|
flatten_switch_consequent,
|
|
@@ -31,15 +32,19 @@ import {
|
|
|
31
32
|
} from '@tsrx/core';
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
|
-
*
|
|
35
|
+
* Solid extends the shared `JsxTransformContext` with `needs_*` flags that
|
|
36
|
+
* track which Solid runtime primitives (`Show`, `For`, `Switch`, `Match`,
|
|
37
|
+
* `Errored`, `Loading`) the lowered output requires. The factory seeds these
|
|
38
|
+
* via `hooks.initialState`; everything else (filename, loose, errors,
|
|
39
|
+
* helper_state, …) comes from the shared base.
|
|
40
|
+
*
|
|
41
|
+
* @typedef {JsxTransformContext & {
|
|
35
42
|
* needs_show: boolean,
|
|
36
43
|
* needs_for: boolean,
|
|
37
44
|
* needs_switch: boolean,
|
|
38
45
|
* needs_match: boolean,
|
|
39
46
|
* needs_errored: boolean,
|
|
40
47
|
* needs_loading: boolean,
|
|
41
|
-
* lazy_next_id: number,
|
|
42
|
-
* current_css_hash: string | null,
|
|
43
48
|
* }} TransformContext
|
|
44
49
|
*/
|
|
45
50
|
|
|
@@ -95,14 +100,20 @@ const solid_platform = {
|
|
|
95
100
|
needs_errored: false,
|
|
96
101
|
needs_loading: false,
|
|
97
102
|
}),
|
|
98
|
-
validateComponentAwait: (await_expression, _component,
|
|
103
|
+
validateComponentAwait: (await_expression, _component, ctx, _requires, source) => {
|
|
99
104
|
const await_start = get_await_keyword_start(await_expression, source);
|
|
100
105
|
const adjusted_node = /** @type {any} */ ({
|
|
101
106
|
...await_expression,
|
|
102
107
|
start: await_start,
|
|
103
108
|
end: await_start + 'await'.length,
|
|
104
109
|
});
|
|
105
|
-
|
|
110
|
+
error(
|
|
111
|
+
'`await` is not allowed inside Solid components.',
|
|
112
|
+
ctx?.filename ?? null,
|
|
113
|
+
adjusted_node,
|
|
114
|
+
ctx?.errors,
|
|
115
|
+
ctx?.comments,
|
|
116
|
+
);
|
|
106
117
|
},
|
|
107
118
|
controlFlow: {
|
|
108
119
|
ifStatement: if_statement_to_jsx_child,
|
|
@@ -332,7 +343,7 @@ function to_jsx_child(node, transform_context) {
|
|
|
332
343
|
// containers wrapped. See helpers.js.
|
|
333
344
|
return tsx_node_to_jsx_expression(node, true);
|
|
334
345
|
case 'TsxCompat':
|
|
335
|
-
return tsx_compat_node_to_jsx_expression(node, true);
|
|
346
|
+
return tsx_compat_node_to_jsx_expression(node, transform_context, true);
|
|
336
347
|
case 'Element':
|
|
337
348
|
return to_jsx_element(node, transform_context);
|
|
338
349
|
case 'Text':
|
|
@@ -858,17 +869,24 @@ function try_statement_to_jsx_child(node, transform_context) {
|
|
|
858
869
|
const finalizer = node.finalizer;
|
|
859
870
|
|
|
860
871
|
if (finalizer) {
|
|
861
|
-
|
|
862
|
-
finalizer,
|
|
872
|
+
error(
|
|
863
873
|
'Solid TSRX does not support JavaScript `try/finally` in component templates. `finally` is not part of TSRX control flow; move the try/finally into a function if you need cleanup logic.',
|
|
874
|
+
transform_context.filename,
|
|
875
|
+
finalizer,
|
|
876
|
+
transform_context.errors,
|
|
877
|
+
transform_context.comments,
|
|
864
878
|
);
|
|
865
879
|
}
|
|
866
880
|
|
|
867
881
|
if (!pending && !handler) {
|
|
868
|
-
|
|
869
|
-
node,
|
|
882
|
+
error(
|
|
870
883
|
'Component try statements must have a `pending` or `catch` block.',
|
|
884
|
+
transform_context.filename,
|
|
885
|
+
node,
|
|
886
|
+
transform_context.errors,
|
|
887
|
+
transform_context.comments,
|
|
871
888
|
);
|
|
889
|
+
return to_jsx_expression_container(create_null_literal());
|
|
872
890
|
}
|
|
873
891
|
|
|
874
892
|
const try_body_nodes = node.block.body || [];
|
|
@@ -1056,7 +1074,22 @@ function to_jsx_element(node, transform_context, pre_walk_children) {
|
|
|
1056
1074
|
}
|
|
1057
1075
|
|
|
1058
1076
|
if (!node.id) {
|
|
1059
|
-
|
|
1077
|
+
error(
|
|
1078
|
+
TEMPLATE_FRAGMENT_ERROR,
|
|
1079
|
+
transform_context.filename,
|
|
1080
|
+
node,
|
|
1081
|
+
transform_context.errors,
|
|
1082
|
+
transform_context.comments,
|
|
1083
|
+
);
|
|
1084
|
+
return set_loc(
|
|
1085
|
+
/** @type {any} */ ({
|
|
1086
|
+
type: 'JSXFragment',
|
|
1087
|
+
openingFragment: { type: 'JSXOpeningFragment' },
|
|
1088
|
+
closingFragment: { type: 'JSXClosingFragment' },
|
|
1089
|
+
children: [],
|
|
1090
|
+
}),
|
|
1091
|
+
node,
|
|
1092
|
+
);
|
|
1060
1093
|
}
|
|
1061
1094
|
|
|
1062
1095
|
if (is_dynamic_element_id(node.id)) {
|
|
@@ -1246,7 +1279,7 @@ function has_text_content_attribute(attributes) {
|
|
|
1246
1279
|
*/
|
|
1247
1280
|
function transform_element_attributes(raw_attrs, is_composite, transform_context) {
|
|
1248
1281
|
void is_composite;
|
|
1249
|
-
validateAtMostOneRefAttribute(raw_attrs);
|
|
1282
|
+
validateAtMostOneRefAttribute(raw_attrs, /** @type {any} */ (transform_context));
|
|
1250
1283
|
/** @type {any[]} */
|
|
1251
1284
|
const result = [];
|
|
1252
1285
|
|
|
@@ -1406,14 +1439,18 @@ function build_return_expression(render_nodes) {
|
|
|
1406
1439
|
|
|
1407
1440
|
/**
|
|
1408
1441
|
* @param {any} node
|
|
1442
|
+
* @param {TransformContext} transform_context
|
|
1409
1443
|
* @param {boolean} [in_jsx_child]
|
|
1410
1444
|
* @returns {any}
|
|
1411
1445
|
*/
|
|
1412
|
-
function tsx_compat_node_to_jsx_expression(node, in_jsx_child = false) {
|
|
1446
|
+
function tsx_compat_node_to_jsx_expression(node, transform_context, in_jsx_child = false) {
|
|
1413
1447
|
if (node.kind !== 'solid') {
|
|
1414
|
-
|
|
1415
|
-
node,
|
|
1448
|
+
error(
|
|
1416
1449
|
`Solid TSRX does not support <tsx:${node.kind}> blocks. Use <tsx> or <tsx:solid>.`,
|
|
1450
|
+
transform_context.filename,
|
|
1451
|
+
node,
|
|
1452
|
+
transform_context.errors,
|
|
1453
|
+
transform_context.comments,
|
|
1417
1454
|
);
|
|
1418
1455
|
}
|
|
1419
1456
|
return tsx_node_to_jsx_expression(node, in_jsx_child);
|