@barefootjs/xslate 0.31.3 → 0.31.5

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.
@@ -187314,8 +187314,8 @@ import {
187314
187314
  dangerousInnerHtmlMetacharViolation,
187315
187315
  dangerousInnerHtmlDiagnostic,
187316
187316
  resolveStaticLoopSource,
187317
- collectLoopBoundNames as collectLoopBoundNames2,
187318
- derivesScopeFromSlot
187317
+ derivesScopeFromSlot,
187318
+ BindingScope
187319
187319
  } from "@barefootjs/jsx";
187320
187320
 
187321
187321
  // src/adapter/boolean-result.ts
@@ -188280,8 +188280,7 @@ class XslateAdapter extends BaseAdapter {
188280
188280
  _searchParamsLocals = new Set;
188281
188281
  _loweringMatchers = [];
188282
188282
  localConstants = [];
188283
- staticLoopSourceBoundNames = new Set;
188284
- loopBoundNames = new Map;
188283
+ scope = BindingScope.EMPTY;
188285
188284
  nullableOptionalProps = new Set;
188286
188285
  constructor(options = {}) {
188287
188286
  super();
@@ -188297,8 +188296,7 @@ class XslateAdapter extends BaseAdapter {
188297
188296
  this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name }));
188298
188297
  this.booleanTypedProps = collectBooleanTypedProps(ir);
188299
188298
  this.localConstants = ir.metadata.localConstants ?? [];
188300
- this.staticLoopSourceBoundNames = collectLoopBoundNames2(ir);
188301
- this.loopBoundNames.clear();
188299
+ this.scope = BindingScope.EMPTY;
188302
188300
  this.nullableOptionalProps = collectNullableOptionalProps(ir);
188303
188301
  this.stringValueNames = collectStringValueNames(ir);
188304
188302
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
@@ -188581,7 +188579,7 @@ ${whenTrue}
188581
188579
  });
188582
188580
  }
188583
188581
  const staticItems = resolveStaticLoopSource(loop.arrayParsed, this.localConstants, {
188584
- isNameShadowed: (name) => this.staticLoopSourceBoundNames.has(name)
188582
+ isNameShadowed: this.scope.asShadowPredicate()
188585
188583
  });
188586
188584
  const staticArray = staticItems !== null ? staticValueToKolon(staticItems) : null;
188587
188585
  const arrayName = loop.array.trim();
@@ -188638,40 +188636,15 @@ ${whenTrue}
188638
188636
  this.inLoop = true;
188639
188637
  const prevLoopKeyDepth = this.currentLoopKeyDepth;
188640
188638
  this.currentLoopKeyDepth = loop.depth;
188639
+ const prevScope = this.scope;
188640
+ this.scope = prevScope.enterLoopRow(loop);
188641
188641
  const preambleLines = (loop.preamble?.declarations ?? []).map((d) => `: my $${d.name} = ${this.convertExpressionToKolon(d.raw, d.valueParsed)};`);
188642
- const loopBound = [];
188643
- if (loop.objectIteration === "entries") {
188644
- loopBound.push("__bf_pair", loop.index ?? param, param);
188645
- } else if (loop.objectIteration === "keys" || loop.objectIteration === "values") {
188646
- loopBound.push(param);
188647
- } else if (loop.iterationShape === "keys") {
188648
- loopBound.push("__bf_item", param);
188649
- } else if (supportableDestructure) {
188650
- loopBound.push("__bf_item", ...(loop.paramBindings ?? []).map((b) => b.name));
188651
- if (loop.index)
188652
- loopBound.push(loop.index);
188653
- } else {
188654
- loopBound.push(param);
188655
- if (loop.index)
188656
- loopBound.push(loop.index);
188657
- }
188658
- for (const d of loop.preamble?.declarations ?? [])
188659
- loopBound.push(d.name);
188660
- for (const n of loopBound) {
188661
- this.loopBoundNames.set(n, (this.loopBoundNames.get(n) ?? 0) + 1);
188662
- }
188663
188642
  const childrenUnderLoop = this.renderChildren(loop.children);
188664
- for (const n of loopBound) {
188665
- const c = (this.loopBoundNames.get(n) ?? 1) - 1;
188666
- if (c <= 0)
188667
- this.loopBoundNames.delete(n);
188668
- else
188669
- this.loopBoundNames.set(n, c);
188670
- }
188671
188643
  this.currentLoopKeyDepth = prevLoopKeyDepth;
188672
188644
  this.inLoop = prevInLoop;
188673
188645
  const bodyChildren = loop.bodyIsItemConditional && loop.key ? `<: $bf.comment("loop-i:" ~ ${this.convertExpressionToKolon(loop.key)}) | mark_raw :>
188674
188646
  ${childrenUnderLoop}` : childrenUnderLoop;
188647
+ this.scope = prevScope;
188675
188648
  const lines = [];
188676
188649
  lines.push(`<: $bf.comment("loop:${loop.markerId}") | mark_raw :>`);
188677
188650
  const forHeader = loop.objectIteration === "entries" ? `: for ${array}.kv() -> $${loopVar} {` : loop.objectIteration === "keys" ? `: for ${array}.keys() -> $${loopVar} {` : loop.objectIteration === "values" ? `: for ${array}.values() -> $${loopVar} {` : `: for ${array} -> $${loopVar} {`;
@@ -188901,7 +188874,7 @@ ${name}="<: ${val} :>"
188901
188874
  if (ternaryHashref !== null) {
188902
188875
  return `<: $bf.spread_attrs(${ternaryHashref}) | mark_raw :>`;
188903
188876
  }
188904
- if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.loopBoundNames.has(trimmed)) {
188877
+ if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.scope.isBound(trimmed)) {
188905
188878
  const localConst = (this.localConstants ?? []).find((c) => c.name === trimmed && !c.isModule);
188906
188879
  if (localConst?.value !== undefined) {
188907
188880
  const initTrimmed = localConst.value.trim();
@@ -189125,10 +189098,10 @@ Options:
189125
189098
  return this.booleanTypedProps.has(bare);
189126
189099
  }
189127
189100
  isLoopBoundName(name) {
189128
- return this.loopBoundNames.has(name);
189101
+ return this.scope.isBound(name);
189129
189102
  }
189130
189103
  _resolveLiteralConst(name) {
189131
- if (this.staticLoopSourceBoundNames.has(name))
189104
+ if (this.scope.isBound(name))
189132
189105
  return null;
189133
189106
  const c = (this.localConstants ?? []).find((lc) => lc.name === name);
189134
189107
  if (c?.value === undefined)
@@ -189142,9 +189115,7 @@ Options:
189142
189115
  return null;
189143
189116
  }
189144
189117
  _resolveStaticRecordLiteral(objectName, key) {
189145
- if (this.staticLoopSourceBoundNames.has(objectName))
189146
- return null;
189147
- const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants);
189118
+ const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants, (name) => this.scope.isBound(name));
189148
189119
  if (!hit)
189149
189120
  return null;
189150
189121
  return hit.kind === "number" ? hit.text : `'${hit.text.replace(/[\\']/g, (m) => `\\${m}`)}'`;
@@ -104,29 +104,24 @@ export declare class XslateAdapter extends BaseAdapter implements IRNodeEmitter<
104
104
  */
105
105
  private localConstants;
106
106
  /**
107
- * Every name a `.map()`/`.filter()` loop callback binds as its item/index
108
- * parameter anywhere in the component (#2208 fable review). A static
109
- * loop-SOURCE name (e.g. a function-scope `const items = [...]`) must
110
- * never resolve through `resolveStaticLoopSource` at a use site where a
111
- * DIFFERENT, enclosing loop's own callback param shadows it — same
112
- * shadowing hazard, and same coarse-but-safe mitigation, as #2212's
113
- * `collectLoopBoundNames` use in `collectStringValueNames`.
114
- */
115
- private staticLoopSourceBoundNames;
116
- /**
117
- * Names currently bound by an enclosing loop body — the block-param
118
- * locals `renderLoop` introduces (item, index, per-binding destructure
119
- * fields, `.map()` preamble declarations) — ref-counted so nested loops
120
- * compose. This is the POSITION-ACCURATE twin of the coarse
121
- * `staticLoopSourceBoundNames` above: that set is a whole-component
122
- * union used only to guard static-const inlining (safe to over-suppress
123
- * there — the fallback is just "don't inline"), whereas the boolean-prop
124
- * and nullable-optional classification sites (#2488) and `emitSpread`'s
125
- * local-const fallback (#2489) need to know whether a name is loop-bound
126
- * AT THIS POSITION, because for those the coarse fallback would silently
127
- * mis-render a genuine occurrence of the same name outside the loop too.
128
- */
129
- private loopBoundNames;
107
+ * The one canonical, position-accurate "names bound by an enclosing loop
108
+ * callback" service (#2482 Stage 2) replaces the two ad-hoc devices
109
+ * this adapter used to carry side by side: a coarse whole-component
110
+ * shadow-name Set (built once at `generate()` entry, used only to guard
111
+ * static-const inlining) and a ref-counted, position-accurate live map
112
+ * (pushed/popped around `renderLoop`'s body, used for the boolean-prop/
113
+ * nullable-optional classification sites (#2488) and `emitSpread`'s
114
+ * local-const fallback (#2489)). Both consulted the "is this name
115
+ * loop-bound" question with DIFFERENT meanings — the coarse/live drift
116
+ * #2482 Stage 2 ends. Every shadow-guard site now reads this ONE
117
+ * threaded, immutable scope: `enterLoopRow`/pop-by-reference around
118
+ * `renderChildren(loop.children)` in `renderLoop`, mirroring the Stage
119
+ * 1a/1b `ctx.scope` precedent in `jsx-to-ir.ts`. `IRLoop` already
120
+ * structurally satisfies `LoopBindingSource`
121
+ * (`param`/`index`/`paramBindings`/`preamble`), so `renderLoop` passes
122
+ * the loop node straight to `enterLoopRow`.
123
+ */
124
+ private scope;
130
125
  /**
131
126
  * Optional, no-default props that are `undef` when the caller omits them.
132
127
  * Their bare-reference attribute emission is guarded with Kolon `defined` so
@@ -339,7 +334,7 @@ export declare class XslateAdapter extends BaseAdapter implements IRNodeEmitter<
339
334
  consequent: string;
340
335
  } | null;
341
336
  isBooleanTypedPropRef(expr: string): boolean;
342
- /** Position-accurate loop-bound-name check — see `loopBoundNames`'s docstring. */
337
+ /** Position-accurate loop-bound-name check — see `this.scope`'s docstring. */
343
338
  private isLoopBoundName;
344
339
  /**
345
340
  * Inline a const (any scope) whose initializer is a pure numeric or
@@ -348,14 +343,13 @@ export declare class XslateAdapter extends BaseAdapter implements IRNodeEmitter<
348
343
  * stash, so a bare `$totalPages` renders empty.
349
344
  *
350
345
  * The lookup is a flat name match with no notion of AST scope, so a
351
- * name that any loop callback binds as its item/index param never
352
- * inlines (#2221) — the occurrence may be the loop's own (shadowing)
353
- * binding, and substituting the outer const's value there renders every
354
- * iteration with the same hard-coded literal. Coarse (a genuinely
355
- * non-shadowed same-named const elsewhere in the component also stops
356
- * inlining, falling back to the bare identifier) but safe — the same
357
- * trade-off as #2212's `collectLoopBoundNames` use in
358
- * `collectStringValueNames`.
346
+ * name bound by the CURRENTLY ENCLOSING loop's item/index/destructure/
347
+ * preamble param never inlines (#2221) — the occurrence may be the
348
+ * loop's own (shadowing) binding, and substituting the outer const's
349
+ * value there renders every iteration with the same hard-coded literal.
350
+ * Position-accurate via the threaded `this.scope` (#2482 Stage 2) — a
351
+ * same-named const elsewhere in the component, outside any loop that
352
+ * shadows it, still inlines.
359
353
  */
360
354
  private _resolveLiteralConst;
361
355
  /**
@@ -366,11 +360,13 @@ export declare class XslateAdapter extends BaseAdapter implements IRNodeEmitter<
366
360
  * scope, so an enclosing loop callback's own param of the same name
367
361
  * (`.map((cfg) => <li>{cfg.x}</li>)` shadowing a module `const cfg = {…}`)
368
362
  * still resolved to the OUTER const's member value at every iteration
369
- * (#2237) — the sibling hazard to #2221's `_resolveLiteralConst`. Same
370
- * coarse-but-safe `staticLoopSourceBoundNames` guard: any name a loop
371
- * binds anywhere in the component never inlines, falling back to the bare
372
- * `$cfg.x` member expression (which an Xslate `: for` loop binds
373
- * correctly at the shadowed occurrences).
363
+ * (#2237) — the sibling hazard to #2221's `_resolveLiteralConst`.
364
+ * Position-accurate via the threaded `this.scope` (#2482 Stage 2), passed
365
+ * as `lookupStaticRecordLiteral`'s required guard: a name the CURRENTLY
366
+ * ENCLOSING loop binds never inlines, falling back to the bare `$cfg.x`
367
+ * member expression (which an Xslate `: for` loop binds correctly at the
368
+ * shadowed occurrence); a same-named const elsewhere, outside any loop
369
+ * that shadows it, still inlines.
374
370
  */
375
371
  private _resolveStaticRecordLiteral;
376
372
  private _resolveModuleStringConst;
@@ -1 +1 @@
1
- {"version":3,"file":"xslate-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/xslate-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,OAAO,EAKP,yBAAyB,EAG1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAClB,KAAK,UAAU,EAgChB,MAAM,iBAAiB,CAAA;AAMxB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AA6BrD,YAAY,EAAE,oBAAoB,E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,CAAC,iCAAiC;IAmBzC;;;;;OAKG;IACH,OAAO,CAAC,+BAA+B;IAuBvC;;;;;;;OAOG;IACH,OAAO,KAAK,OAAO,GAUlB;IAED;;;;;OAKG;IACH,OAAO,KAAK,SAAS,GAQpB;IAED,sEAAsE;IACtE,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,CAAC,wBAAwB;IAyEhC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAI/B;oEACgE;IAChE,OAAO,CAAC,kBAAkB;IAI1B;;;;;OAKG;IACH;;;;;OAKG;IACH;;;;;OAKG;IACH;;;;OAIG;IACH,8BAA8B,CAC5B,IAAI,EAAE,MAAM,GACX;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAgBlD;IAED,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW3C;IAED,kFAAkF;IAClF,OAAO,CAAC,eAAe;IAIvB;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;;;;;;;;;;;;OAaG;IACH,OAAO,CAAC,2BAA2B;IASnC,OAAO,CAAC,yBAAyB;IASjC,OAAO,CAAC,gBAAgB;IAcxB,iFAAiF;IACjF,OAAO,CAAC,4BAA4B;CAGrC;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
1
+ {"version":3,"file":"xslate-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/xslate-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,OAAO,EAKP,yBAAyB,EAG1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EA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EvC;IAMD;;;;;OAKG;IACH,OAAO,CAAC,qBAAqB;IAuB7B,OAAO,CAAC,kCAAkC;IAwB1C;;;;OAIG;IACH,OAAO,CAAC,iCAAiC;IAmBzC;;;;;OAKG;IACH,OAAO,CAAC,+BAA+B;IAuBvC;;;;;;;OAOG;IACH,OAAO,KAAK,OAAO,GAUlB;IAED;;;;;OAKG;IACH,OAAO,KAAK,SAAS,GAQpB;IAED,sEAAsE;IACtE,OAAO,KAAK,OAAO,GAElB;IAED,OAAO,CAAC,wBAAwB;IAyEhC;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAI/B;oEACgE;IAChE,OAAO,CAAC,kBAAkB;IAI1B;;;;;OAKG;IACH;;;;;OAKG;IACH;;;;;OAKG;IACH;;;;OAIG;IACH,8BAA8B,CAC5B,IAAI,EAAE,MAAM,GACX;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAgBlD;IAED,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAW3C;IAED,8EAA8E;IAC9E,OAAO,CAAC,eAAe;IAIvB;;;;;;;;;;;;;;OAcG;IACH,OAAO,CAAC,oBAAoB;IAW5B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,yBAAyB;IASjC,OAAO,CAAC,gBAAgB;IAcxB,iFAAiF;IACjF,OAAO,CAAC,4BAA4B;CAGrC;AAED,eAAO,MAAM,aAAa,eAAsB,CAAA"}
package/dist/index.js CHANGED
@@ -187314,8 +187314,8 @@ import {
187314
187314
  dangerousInnerHtmlMetacharViolation,
187315
187315
  dangerousInnerHtmlDiagnostic,
187316
187316
  resolveStaticLoopSource,
187317
- collectLoopBoundNames as collectLoopBoundNames2,
187318
- derivesScopeFromSlot
187317
+ derivesScopeFromSlot,
187318
+ BindingScope
187319
187319
  } from "@barefootjs/jsx";
187320
187320
 
187321
187321
  // src/adapter/boolean-result.ts
@@ -188280,8 +188280,7 @@ class XslateAdapter extends BaseAdapter {
188280
188280
  _searchParamsLocals = new Set;
188281
188281
  _loweringMatchers = [];
188282
188282
  localConstants = [];
188283
- staticLoopSourceBoundNames = new Set;
188284
- loopBoundNames = new Map;
188283
+ scope = BindingScope.EMPTY;
188285
188284
  nullableOptionalProps = new Set;
188286
188285
  constructor(options = {}) {
188287
188286
  super();
@@ -188297,8 +188296,7 @@ class XslateAdapter extends BaseAdapter {
188297
188296
  this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name }));
188298
188297
  this.booleanTypedProps = collectBooleanTypedProps(ir);
188299
188298
  this.localConstants = ir.metadata.localConstants ?? [];
188300
- this.staticLoopSourceBoundNames = collectLoopBoundNames2(ir);
188301
- this.loopBoundNames.clear();
188299
+ this.scope = BindingScope.EMPTY;
188302
188300
  this.nullableOptionalProps = collectNullableOptionalProps(ir);
188303
188301
  this.stringValueNames = collectStringValueNames(ir);
188304
188302
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
@@ -188581,7 +188579,7 @@ ${whenTrue}
188581
188579
  });
188582
188580
  }
188583
188581
  const staticItems = resolveStaticLoopSource(loop.arrayParsed, this.localConstants, {
188584
- isNameShadowed: (name) => this.staticLoopSourceBoundNames.has(name)
188582
+ isNameShadowed: this.scope.asShadowPredicate()
188585
188583
  });
188586
188584
  const staticArray = staticItems !== null ? staticValueToKolon(staticItems) : null;
188587
188585
  const arrayName = loop.array.trim();
@@ -188638,40 +188636,15 @@ ${whenTrue}
188638
188636
  this.inLoop = true;
188639
188637
  const prevLoopKeyDepth = this.currentLoopKeyDepth;
188640
188638
  this.currentLoopKeyDepth = loop.depth;
188639
+ const prevScope = this.scope;
188640
+ this.scope = prevScope.enterLoopRow(loop);
188641
188641
  const preambleLines = (loop.preamble?.declarations ?? []).map((d) => `: my $${d.name} = ${this.convertExpressionToKolon(d.raw, d.valueParsed)};`);
188642
- const loopBound = [];
188643
- if (loop.objectIteration === "entries") {
188644
- loopBound.push("__bf_pair", loop.index ?? param, param);
188645
- } else if (loop.objectIteration === "keys" || loop.objectIteration === "values") {
188646
- loopBound.push(param);
188647
- } else if (loop.iterationShape === "keys") {
188648
- loopBound.push("__bf_item", param);
188649
- } else if (supportableDestructure) {
188650
- loopBound.push("__bf_item", ...(loop.paramBindings ?? []).map((b) => b.name));
188651
- if (loop.index)
188652
- loopBound.push(loop.index);
188653
- } else {
188654
- loopBound.push(param);
188655
- if (loop.index)
188656
- loopBound.push(loop.index);
188657
- }
188658
- for (const d of loop.preamble?.declarations ?? [])
188659
- loopBound.push(d.name);
188660
- for (const n of loopBound) {
188661
- this.loopBoundNames.set(n, (this.loopBoundNames.get(n) ?? 0) + 1);
188662
- }
188663
188642
  const childrenUnderLoop = this.renderChildren(loop.children);
188664
- for (const n of loopBound) {
188665
- const c = (this.loopBoundNames.get(n) ?? 1) - 1;
188666
- if (c <= 0)
188667
- this.loopBoundNames.delete(n);
188668
- else
188669
- this.loopBoundNames.set(n, c);
188670
- }
188671
188643
  this.currentLoopKeyDepth = prevLoopKeyDepth;
188672
188644
  this.inLoop = prevInLoop;
188673
188645
  const bodyChildren = loop.bodyIsItemConditional && loop.key ? `<: $bf.comment("loop-i:" ~ ${this.convertExpressionToKolon(loop.key)}) | mark_raw :>
188674
188646
  ${childrenUnderLoop}` : childrenUnderLoop;
188647
+ this.scope = prevScope;
188675
188648
  const lines = [];
188676
188649
  lines.push(`<: $bf.comment("loop:${loop.markerId}") | mark_raw :>`);
188677
188650
  const forHeader = loop.objectIteration === "entries" ? `: for ${array}.kv() -> $${loopVar} {` : loop.objectIteration === "keys" ? `: for ${array}.keys() -> $${loopVar} {` : loop.objectIteration === "values" ? `: for ${array}.values() -> $${loopVar} {` : `: for ${array} -> $${loopVar} {`;
@@ -188901,7 +188874,7 @@ ${name}="<: ${val} :>"
188901
188874
  if (ternaryHashref !== null) {
188902
188875
  return `<: $bf.spread_attrs(${ternaryHashref}) | mark_raw :>`;
188903
188876
  }
188904
- if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.loopBoundNames.has(trimmed)) {
188877
+ if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.scope.isBound(trimmed)) {
188905
188878
  const localConst = (this.localConstants ?? []).find((c) => c.name === trimmed && !c.isModule);
188906
188879
  if (localConst?.value !== undefined) {
188907
188880
  const initTrimmed = localConst.value.trim();
@@ -189125,10 +189098,10 @@ Options:
189125
189098
  return this.booleanTypedProps.has(bare);
189126
189099
  }
189127
189100
  isLoopBoundName(name) {
189128
- return this.loopBoundNames.has(name);
189101
+ return this.scope.isBound(name);
189129
189102
  }
189130
189103
  _resolveLiteralConst(name) {
189131
- if (this.staticLoopSourceBoundNames.has(name))
189104
+ if (this.scope.isBound(name))
189132
189105
  return null;
189133
189106
  const c = (this.localConstants ?? []).find((lc) => lc.name === name);
189134
189107
  if (c?.value === undefined)
@@ -189142,9 +189115,7 @@ Options:
189142
189115
  return null;
189143
189116
  }
189144
189117
  _resolveStaticRecordLiteral(objectName, key) {
189145
- if (this.staticLoopSourceBoundNames.has(objectName))
189146
- return null;
189147
- const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants);
189118
+ const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants, (name) => this.scope.isBound(name));
189148
189119
  if (!hit)
189149
189120
  return null;
189150
189121
  return hit.kind === "number" ? hit.text : `'${hit.text.replace(/[\\']/g, (m) => `\\${m}`)}'`;