@tsrx/core 0.1.49 → 0.1.50

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/plugin.js +17 -13
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.49",
6
+ "version": "0.1.50",
7
7
  "type": "module",
8
8
  "repository": {
9
9
  "type": "git",
package/src/plugin.js CHANGED
@@ -3411,17 +3411,20 @@ export function TSRXPlugin(config) {
3411
3411
  let node = /** @type {ESTreeJSX.JSXExpressionContainer} */ (this.startNode());
3412
3412
  this.#jsxExpressionContainerDepth++;
3413
3413
  let pushed_context_baseline = false;
3414
- /** @type {number} */
3415
- let context_baseline;
3414
+ // The stack depth with the container's `{` brace context on top, taken
3415
+ // before `next()` so the first expression token's own context pushes
3416
+ // (e.g. a fragment's `<` pushing its tag contexts) are not counted.
3417
+ // This is the depth the stack must return to when the container's
3418
+ // closing `}` is the current token.
3419
+ const container_context_depth = this.context.length;
3416
3420
  try {
3417
3421
  this.next();
3418
3422
 
3419
- // Record the context-stack depth now that the container's `{` brace
3420
- // context is on the stack. A control-flow directive parsed inside this
3423
+ // Record the context-stack depth now that the first expression token
3424
+ // has been read. A control-flow directive parsed inside this
3421
3425
  // container must not strip anything below this floor (see
3422
3426
  // `#filterTemplateScriptContexts`).
3423
- context_baseline = this.context.length;
3424
- this.#expressionContainerContextBaselines.push(context_baseline);
3427
+ this.#expressionContainerContextBaselines.push(this.context.length);
3425
3428
  this.#expressionContainerPathBaselines.push(this.#path.length);
3426
3429
  pushed_context_baseline = true;
3427
3430
 
@@ -3442,13 +3445,14 @@ export function TSRXPlugin(config) {
3442
3445
  // a snapshot taken inside this container
3443
3446
  // (`#parseTemplateControlFlowBlock`), so the container's closing `}`
3444
3447
  // — read while that stale snapshot was active — pops the wrong entry
3445
- // and leaves stale brace contexts above the enclosing tag's contexts.
3446
- // Once the `}` has been read the stack must be back at one below the
3447
- // baseline (the container's own brace context popped); drop anything
3448
- // above that so the token after `}` (e.g. the `>` finishing the
3449
- // enclosing opening tag) tokenizes in the right context.
3450
- if (this.type === tt.braceR && this.context.length >= context_baseline) {
3451
- this.context.length = context_baseline - 1;
3448
+ // and leaves stale contexts above the enclosing tag's contexts (the
3449
+ // directive's statement brace, or a wrapping fragment's child
3450
+ // context). Once the `}` has been read the stack must be back at one
3451
+ // below the container's depth (its own brace context popped); drop
3452
+ // anything above that so the token after `}` (e.g. the `>` finishing
3453
+ // the enclosing opening tag) tokenizes in the right context.
3454
+ if (this.type === tt.braceR && this.context.length >= container_context_depth) {
3455
+ this.context.length = container_context_depth - 1;
3452
3456
  }
3453
3457
  this.expect(tt.braceR);
3454
3458
  }