@tsrx/core 0.1.30 → 0.1.31

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Core compiler infrastructure for TSRX syntax",
4
4
  "license": "MIT",
5
5
  "author": "Dominic Gannaway",
6
- "version": "0.1.30",
6
+ "version": "0.1.31",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
package/src/index.js CHANGED
@@ -164,6 +164,10 @@ export {
164
164
  in_jsx_child_context as inJsxChildContext,
165
165
  tsx_node_to_jsx_expression as tsxNodeToJsxExpression,
166
166
  tsx_with_ts_locations as tsxWithTsLocations,
167
+ is_template_if_node as isTemplateIfNode,
168
+ is_template_for_of_node as isTemplateForOfNode,
169
+ is_template_switch_node as isTemplateSwitchNode,
170
+ is_template_try_node as isTemplateTryNode,
167
171
  } from './transform/jsx/helpers.js';
168
172
  export {
169
173
  collect_style_ref_attributes as collectStyleRefAttributes,
package/src/plugin.js CHANGED
@@ -3650,15 +3650,17 @@ export function TSRXPlugin(config) {
3650
3650
  }
3651
3651
 
3652
3652
  /**
3653
- * `@try`/`@pending`/`@catch` blocks lower their direct `return`
3654
- * values into reactive boundary fallbacks, so unlike `@if`/`@for`/`@switch`
3655
- * blocks they legitimately allow `return <markup>` statements. Set the flag
3656
- * immediately before parsing each such block so its body sees it.
3653
+ * `@try`/`@pending`/`@catch` blocks are template control-flow blocks like
3654
+ * `@if`/`@for`/`@switch`: `return` is not allowed inside them. A `return`
3655
+ * is only valid in the JS setup at the top of a `@{ … }` code block, never
3656
+ * inside a `@`-directive block. Report any direct `return` with the same
3657
+ * template-return diagnostic used elsewhere.
3657
3658
  * @returns {AST.BlockStatement}
3658
3659
  */
3659
3660
  #parseTemplateControlFlowReturnBlock(createNewLexicalScope = true) {
3660
- this.#controlFlowBlockAllowsNativeReturn = true;
3661
- return this.#parseTemplateControlFlowBlock(createNewLexicalScope);
3661
+ const block = this.#parseTemplateControlFlowBlock(createNewLexicalScope);
3662
+ this.#report_invalid_template_return_statements(block.body);
3663
+ return block;
3662
3664
  }
3663
3665
 
3664
3666
  /**
@@ -260,3 +260,51 @@ export function tsx_with_ts_locations() {
260
260
 
261
261
  return { ...base, ...wrappers };
262
262
  }
263
+
264
+ /**
265
+ * @param {any} node
266
+ * @returns {boolean}
267
+ */
268
+ export function is_template_if_node(node) {
269
+ return (
270
+ node?.type === 'JSXIfExpression' ||
271
+ node?.metadata?.tsrxDirective === 'if' ||
272
+ (node?.type === 'IfStatement' && node?.statementType === 'IfStatement')
273
+ );
274
+ }
275
+
276
+ /**
277
+ * @param {any} node
278
+ * @returns {boolean}
279
+ */
280
+ export function is_template_for_of_node(node) {
281
+ return (
282
+ node?.type === 'JSXForExpression' ||
283
+ node?.metadata?.tsrxDirective === 'for' ||
284
+ (node?.type === 'ForOfStatement' && node?.statementType === 'ForOfStatement')
285
+ );
286
+ }
287
+
288
+ /**
289
+ * @param {any} node
290
+ * @returns {boolean}
291
+ */
292
+ export function is_template_switch_node(node) {
293
+ return (
294
+ node?.type === 'JSXSwitchExpression' ||
295
+ node?.metadata?.tsrxDirective === 'switch' ||
296
+ (node?.type === 'SwitchStatement' && node?.statementType === 'SwitchStatement')
297
+ );
298
+ }
299
+
300
+ /**
301
+ * @param {any} node
302
+ * @returns {boolean}
303
+ */
304
+ export function is_template_try_node(node) {
305
+ return (
306
+ node?.type === 'JSXTryExpression' ||
307
+ node?.metadata?.tsrxDirective === 'try' ||
308
+ (node?.type === 'TryStatement' && node?.statementType === 'TryStatement')
309
+ );
310
+ }
@@ -10,8 +10,11 @@ import { prune_css } from '../../analyze/prune.js';
10
10
  import {
11
11
  in_jsx_child_context,
12
12
  set_node_path_metadata,
13
- tsx_node_to_jsx_expression,
14
13
  tsx_with_ts_locations,
14
+ is_template_if_node,
15
+ is_template_for_of_node,
16
+ is_template_switch_node,
17
+ is_template_try_node,
15
18
  } from './helpers.js';
16
19
  import {
17
20
  add_extra_source_mappings_from_matching_expression,
@@ -4485,54 +4488,6 @@ function validate_if_body_control_flow(node, transform_context) {
4485
4488
  }
4486
4489
  }
4487
4490
 
4488
- /**
4489
- * @param {any} node
4490
- * @returns {boolean}
4491
- */
4492
- function is_template_if_node(node) {
4493
- return (
4494
- node?.type === 'JSXIfExpression' ||
4495
- node?.metadata?.tsrxDirective === 'if' ||
4496
- (node?.type === 'IfStatement' && node?.statementType === 'IfStatement')
4497
- );
4498
- }
4499
-
4500
- /**
4501
- * @param {any} node
4502
- * @returns {boolean}
4503
- */
4504
- function is_template_for_of_node(node) {
4505
- return (
4506
- node?.type === 'JSXForExpression' ||
4507
- node?.metadata?.tsrxDirective === 'for' ||
4508
- (node?.type === 'ForOfStatement' && node?.statementType === 'ForOfStatement')
4509
- );
4510
- }
4511
-
4512
- /**
4513
- * @param {any} node
4514
- * @returns {boolean}
4515
- */
4516
- function is_template_switch_node(node) {
4517
- return (
4518
- node?.type === 'JSXSwitchExpression' ||
4519
- node?.metadata?.tsrxDirective === 'switch' ||
4520
- (node?.type === 'SwitchStatement' && node?.statementType === 'SwitchStatement')
4521
- );
4522
- }
4523
-
4524
- /**
4525
- * @param {any} node
4526
- * @returns {boolean}
4527
- */
4528
- function is_template_try_node(node) {
4529
- return (
4530
- node?.type === 'JSXTryExpression' ||
4531
- node?.metadata?.tsrxDirective === 'try' ||
4532
- (node?.type === 'TryStatement' && node?.statementType === 'TryStatement')
4533
- );
4534
- }
4535
-
4536
4491
  /**
4537
4492
  * @param {any} node
4538
4493
  * @returns {boolean}