@tsrx/preact 0.0.2 → 0.0.3
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/transform.js +15 -10
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Preact compiler built on @tsrx/core",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Dominic Gannaway",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.3",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"publishConfig": {
|
|
9
9
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"esrap": "^2.1.0",
|
|
27
27
|
"zimmerframe": "^1.1.2",
|
|
28
|
-
"@tsrx/core": "0.0.
|
|
28
|
+
"@tsrx/core": "0.0.8"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"preact": ">=10"
|
package/src/transform.js
CHANGED
|
@@ -1137,6 +1137,9 @@ function is_jsx_child(node) {
|
|
|
1137
1137
|
);
|
|
1138
1138
|
}
|
|
1139
1139
|
|
|
1140
|
+
const TEMPLATE_FRAGMENT_ERROR =
|
|
1141
|
+
'JSX fragment syntax is not needed in TSRX templates. TSRX renders in immediate mode, so everything is already a fragment. Use `<>...</>` only within <tsx>...</tsx>.';
|
|
1142
|
+
|
|
1140
1143
|
/**
|
|
1141
1144
|
* @param {any} node
|
|
1142
1145
|
* @param {TransformContext} transform_context
|
|
@@ -1149,6 +1152,9 @@ function to_jsx_element(node, transform_context) {
|
|
|
1149
1152
|
'`{html ...}` is not supported on the Preact target. Use `dangerouslySetInnerHTML={{ __html: ... }}` as an element attribute instead.',
|
|
1150
1153
|
);
|
|
1151
1154
|
}
|
|
1155
|
+
if (!node.id) {
|
|
1156
|
+
throw create_compile_error(node, TEMPLATE_FRAGMENT_ERROR);
|
|
1157
|
+
}
|
|
1152
1158
|
if (is_dynamic_element_id(node.id)) {
|
|
1153
1159
|
return dynamic_element_to_jsx_child(node, transform_context);
|
|
1154
1160
|
}
|
|
@@ -1636,24 +1642,23 @@ function for_of_statement_to_jsx_child(node, transform_context) {
|
|
|
1636
1642
|
);
|
|
1637
1643
|
}
|
|
1638
1644
|
|
|
1639
|
-
if (node.key) {
|
|
1640
|
-
throw create_compile_error(
|
|
1641
|
-
node.key,
|
|
1642
|
-
'Preact TSRX does not support `key` in `for` control flow. Put the key on the rendered element instead, for example `<div key={i}>...</div>`.',
|
|
1643
|
-
);
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
1645
|
const loop_params = get_for_of_iteration_params(node.left, node.index);
|
|
1647
1646
|
const loop_body = node.body.type === 'BlockStatement' ? node.body.body : [node.body];
|
|
1648
1647
|
const has_hooks = body_contains_top_level_hook_call(loop_body);
|
|
1649
|
-
const
|
|
1648
|
+
const body_key_expression = find_key_expression_in_body(loop_body);
|
|
1649
|
+
const explicit_key_expression =
|
|
1650
|
+
body_key_expression ?? (node.key ? clone_expression_node(node.key) : undefined);
|
|
1650
1651
|
const key_expression =
|
|
1651
1652
|
has_hooks && explicit_key_expression == null && node.index
|
|
1652
1653
|
? clone_expression_node(node.index)
|
|
1653
1654
|
: explicit_key_expression;
|
|
1654
1655
|
const implicit_non_hook_key_expression =
|
|
1655
|
-
!has_hooks &&
|
|
1656
|
-
?
|
|
1656
|
+
!has_hooks && body_key_expression == null
|
|
1657
|
+
? node.key
|
|
1658
|
+
? clone_expression_node(node.key)
|
|
1659
|
+
: node.index
|
|
1660
|
+
? clone_expression_node(node.index)
|
|
1661
|
+
: undefined
|
|
1657
1662
|
: undefined;
|
|
1658
1663
|
|
|
1659
1664
|
// Add loop params to available bindings so hoisted helpers receive them as props
|