@barefootjs/jinja 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,
187318
- derivesScopeFromSlot
187317
+ derivesScopeFromSlot,
187318
+ BindingScope
187319
187319
  } from "@barefootjs/jsx";
187320
187320
 
187321
187321
  // src/adapter/boolean-result.ts
@@ -188320,8 +188320,7 @@ class JinjaAdapter extends BaseAdapter {
188320
188320
  _searchParamsLocals = new Set;
188321
188321
  _loweringMatchers = [];
188322
188322
  localConstants = [];
188323
- staticLoopSourceBoundNames = new Set;
188324
- loopBoundNames = new Map;
188323
+ scope = BindingScope.EMPTY;
188325
188324
  nullableOptionalProps = new Set;
188326
188325
  constructor(options = {}) {
188327
188326
  super();
@@ -188337,8 +188336,7 @@ class JinjaAdapter extends BaseAdapter {
188337
188336
  this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name }));
188338
188337
  this.booleanTypedProps = collectBooleanTypedProps(ir);
188339
188338
  this.localConstants = ir.metadata.localConstants ?? [];
188340
- this.staticLoopSourceBoundNames = collectLoopBoundNames(ir);
188341
- this.loopBoundNames.clear();
188339
+ this.scope = BindingScope.EMPTY;
188342
188340
  this.nullableOptionalProps = collectNullableOptionalProps(ir);
188343
188341
  this.stringValueNames = collectStringValueNames(ir);
188344
188342
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
@@ -188633,7 +188631,7 @@ ${whenTrue}
188633
188631
  });
188634
188632
  }
188635
188633
  const staticItems = resolveStaticLoopSource(loop.arrayParsed, this.localConstants, {
188636
- isNameShadowed: (name) => this.staticLoopSourceBoundNames.has(name)
188634
+ isNameShadowed: this.scope.asShadowPredicate()
188637
188635
  });
188638
188636
  const staticArray = staticItems !== null ? staticValueToJinja(staticItems) : null;
188639
188637
  const arrayName = loop.array.trim();
@@ -188687,40 +188685,15 @@ ${whenTrue}
188687
188685
  this.inLoop = true;
188688
188686
  const prevLoopKeyDepth = this.currentLoopKeyDepth;
188689
188687
  this.currentLoopKeyDepth = loop.depth;
188688
+ const prevScope = this.scope;
188689
+ this.scope = prevScope.enterLoopRow(loop);
188690
188690
  const preambleLines = (loop.preamble?.declarations ?? []).map((d) => `{% set ${jinjaIdent(d.name)} = ${this.convertExpressionToJinja(d.raw, d.valueParsed)} %}`);
188691
- const loopBound = [];
188692
- if (loop.objectIteration === "entries") {
188693
- loopBound.push(loop.index ?? param, param);
188694
- } else if (loop.objectIteration === "keys" || loop.objectIteration === "values") {
188695
- loopBound.push(param);
188696
- } else if (loop.iterationShape === "keys") {
188697
- loopBound.push("__bf_item", param);
188698
- } else if (supportableDestructure) {
188699
- loopBound.push("__bf_item", ...(loop.paramBindings ?? []).map((b) => b.name));
188700
- if (loop.index)
188701
- loopBound.push(loop.index);
188702
- } else {
188703
- loopBound.push(param);
188704
- if (loop.index)
188705
- loopBound.push(loop.index);
188706
- }
188707
- for (const d of loop.preamble?.declarations ?? [])
188708
- loopBound.push(d.name);
188709
- for (const n of loopBound) {
188710
- this.loopBoundNames.set(n, (this.loopBoundNames.get(n) ?? 0) + 1);
188711
- }
188712
188691
  const childrenUnderLoop = this.renderChildren(loop.children);
188713
- for (const n of loopBound) {
188714
- const c = (this.loopBoundNames.get(n) ?? 1) - 1;
188715
- if (c <= 0)
188716
- this.loopBoundNames.delete(n);
188717
- else
188718
- this.loopBoundNames.set(n, c);
188719
- }
188720
188692
  this.currentLoopKeyDepth = prevLoopKeyDepth;
188721
188693
  this.inLoop = prevInLoop;
188722
188694
  const bodyChildren = loop.bodyIsItemConditional && loop.key ? `{{ bf.comment("loop-i:" ~ bf.string(${this.convertExpressionToJinja(loop.key)})) | safe }}
188723
188695
  ${childrenUnderLoop}` : childrenUnderLoop;
188696
+ this.scope = prevScope;
188724
188697
  const lines = [];
188725
188698
  lines.push(`{{ bf.comment("loop:${loop.markerId}") | safe }}`);
188726
188699
  const forHeader = loop.objectIteration === "entries" ? `{% for ${jinjaIdent(loop.index ?? param)}, ${jinjaIdent(param)} in ${array}.items() %}` : loop.objectIteration === "keys" ? `{% for ${jinjaIdent(param)} in ${array}.keys() %}` : loop.objectIteration === "values" ? `{% for ${jinjaIdent(param)} in ${array}.values() %}` : `{% for ${jinjaIdent(loopVar)} in ${array} %}`;
@@ -188952,7 +188925,7 @@ ${name}="{{ bf.string(${val}) }}"
188952
188925
  if (ternaryDict !== null) {
188953
188926
  return `{{ bf.spread_attrs(${ternaryDict}) | safe }}`;
188954
188927
  }
188955
- if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.loopBoundNames.has(trimmed)) {
188928
+ if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.scope.isBound(trimmed)) {
188956
188929
  const localConst = (this.localConstants ?? []).find((c) => c.name === trimmed && !c.isModule);
188957
188930
  if (localConst?.value !== undefined) {
188958
188931
  const initTrimmed = localConst.value.trim();
@@ -189187,7 +189160,7 @@ Options:
189187
189160
  return this.booleanTypedProps.has(bare);
189188
189161
  }
189189
189162
  isLoopBoundName(name) {
189190
- return this.loopBoundNames.has(name);
189163
+ return this.scope.isBound(name);
189191
189164
  }
189192
189165
  shouldBoolStr(expr, name) {
189193
189166
  if (isExplicitStringCall(expr))
@@ -189195,7 +189168,7 @@ Options:
189195
189168
  return isBooleanResultExpr(expr) || isAriaBooleanAttr(name) || this.isBooleanTypedPropRef(expr);
189196
189169
  }
189197
189170
  _resolveLiteralConst(name) {
189198
- if (this.staticLoopSourceBoundNames.has(name))
189171
+ if (this.scope.isBound(name))
189199
189172
  return null;
189200
189173
  const c = (this.localConstants ?? []).find((lc) => lc.name === name);
189201
189174
  if (c?.value === undefined)
@@ -189209,9 +189182,7 @@ Options:
189209
189182
  return null;
189210
189183
  }
189211
189184
  _resolveStaticRecordLiteral(objectName, key) {
189212
- if (this.staticLoopSourceBoundNames.has(objectName))
189213
- return null;
189214
- const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants);
189185
+ const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants, (name) => this.scope.isBound(name));
189215
189186
  if (!hit)
189216
189187
  return null;
189217
189188
  return hit.kind === "number" ? hit.text : `'${escapeJinjaSingleQuoted(hit.text)}'`;
@@ -168,29 +168,24 @@ export declare class JinjaAdapter extends BaseAdapter implements IRNodeEmitter<J
168
168
  */
169
169
  private localConstants;
170
170
  /**
171
- * Every name a `.map()`/`.filter()` loop callback binds as its item/index
172
- * parameter anywhere in the component (#2208 fable review). A static
173
- * loop-SOURCE name (e.g. a function-scope `const items = [...]`) must
174
- * never resolve through `resolveStaticLoopSource` at a use site where a
175
- * DIFFERENT, enclosing loop's own callback param shadows it — same
176
- * shadowing hazard, and same coarse-but-safe mitigation, as #2212's
177
- * `collectLoopBoundNames` use in `collectStringValueNames`.
178
- */
179
- private staticLoopSourceBoundNames;
180
- /**
181
- * Names currently bound by an enclosing loop body — the block-param
182
- * locals `renderLoop` introduces (item, index, per-binding destructure
183
- * fields, `.map()` preamble declarations) — ref-counted so nested loops
184
- * compose. This is the POSITION-ACCURATE twin of the coarse
185
- * `staticLoopSourceBoundNames` above: that set is a whole-component
186
- * union used only to guard static-const inlining (safe to over-suppress
187
- * there — the fallback is just "don't inline"), whereas the boolean-prop
188
- * and nullable-optional classification sites (#2488) and `emitSpread`'s
189
- * local-const fallback (#2489) need to know whether a name is loop-bound
190
- * AT THIS POSITION, because for those the coarse fallback would silently
191
- * mis-render a genuine occurrence of the same name outside the loop too.
192
- */
193
- private loopBoundNames;
171
+ * The one canonical, position-accurate "names bound by an enclosing loop
172
+ * callback" service (#2482 Stage 2) replaces the two ad-hoc devices
173
+ * this adapter used to carry side by side: a coarse whole-component
174
+ * shadow-name Set (built once at `generate()` entry, used only to guard
175
+ * static-const inlining) and a ref-counted, position-accurate live map
176
+ * (pushed/popped around `renderLoop`'s body, used for the boolean-prop/
177
+ * nullable-optional classification sites (#2488) and `emitSpread`'s
178
+ * local-const fallback (#2489)). Both consulted the "is this name
179
+ * loop-bound" question with DIFFERENT meanings — the coarse/live drift
180
+ * #2482 Stage 2 ends. Every shadow-guard site now reads this ONE
181
+ * threaded, immutable scope: `enterLoopRow`/pop-by-reference around
182
+ * `renderChildren(loop.children)` in `renderLoop`, mirroring the Stage
183
+ * 1a/1b `ctx.scope` precedent in `jsx-to-ir.ts`. `IRLoop` already
184
+ * structurally satisfies `LoopBindingSource`
185
+ * (`param`/`index`/`paramBindings`/`preamble`), so `renderLoop` passes
186
+ * the loop node straight to `enterLoopRow`.
187
+ */
188
+ private scope;
194
189
  /**
195
190
  * Optional, no-default props that are `None` when the caller omits them.
196
191
  * Their bare-reference attribute emission is guarded with a Jinja
@@ -403,7 +398,7 @@ export declare class JinjaAdapter extends BaseAdapter implements IRNodeEmitter<J
403
398
  consequent: string;
404
399
  } | null;
405
400
  isBooleanTypedPropRef(expr: string): boolean;
406
- /** Position-accurate loop-bound-name check — see `loopBoundNames`'s docstring. */
401
+ /** Position-accurate loop-bound-name check — see `this.scope`'s docstring. */
407
402
  private isLoopBoundName;
408
403
  /**
409
404
  * Whether an attribute-value expression should route through
@@ -425,14 +420,13 @@ export declare class JinjaAdapter extends BaseAdapter implements IRNodeEmitter<J
425
420
  * context, so a bare reference would resolve to Undefined.
426
421
  *
427
422
  * The lookup is a flat name match with no notion of AST scope, so a
428
- * name that any loop callback binds as its item/index param never
429
- * inlines (#2221) — the occurrence may be the loop's own (shadowing)
430
- * binding, and substituting the outer const's value there renders every
431
- * iteration with the same hard-coded literal. Coarse (a genuinely
432
- * non-shadowed same-named const elsewhere in the component also stops
433
- * inlining, falling back to the bare identifier) but safe — the same
434
- * trade-off as #2212's `collectLoopBoundNames` use in
435
- * `collectStringValueNames`.
423
+ * name bound by the CURRENTLY ENCLOSING loop's item/index/destructure/
424
+ * preamble param never inlines (#2221) — the occurrence may be the
425
+ * loop's own (shadowing) binding, and substituting the outer const's
426
+ * value there renders every iteration with the same hard-coded literal.
427
+ * Position-accurate via the threaded `this.scope` (#2482 Stage 2) — a
428
+ * same-named const elsewhere in the component, outside any loop that
429
+ * shadows it, still inlines.
436
430
  */
437
431
  private _resolveLiteralConst;
438
432
  /**
@@ -443,11 +437,13 @@ export declare class JinjaAdapter extends BaseAdapter implements IRNodeEmitter<J
443
437
  * scope, so an enclosing loop callback's own param of the same name
444
438
  * (`.map((cfg) => <li>{cfg.x}</li>)` shadowing a module `const cfg = {…}`)
445
439
  * still resolved to the OUTER const's member value at every iteration
446
- * (#2237) — the sibling hazard to #2221's `_resolveLiteralConst`. Same
447
- * coarse-but-safe `staticLoopSourceBoundNames` guard: any name a loop
448
- * binds anywhere in the component never inlines, falling back to the bare
440
+ * (#2237) — the sibling hazard to #2221's `_resolveLiteralConst`.
441
+ * Position-accurate via the threaded `this.scope` (#2482 Stage 2), passed
442
+ * as `lookupStaticRecordLiteral`'s required guard: a name the CURRENTLY
443
+ * ENCLOSING loop binds never inlines, falling back to the bare
449
444
  * `cfg['x']` member expression (which a Jinja for-loop binds correctly
450
- * at the shadowed occurrences).
445
+ * at the shadowed occurrence); a same-named const elsewhere, outside any
446
+ * loop that shadows it, still inlines.
451
447
  */
452
448
  private _resolveStaticRecordLiteral;
453
449
  private _resolveModuleStringConst;
@@ -1 +1 @@
1
- {"version":3,"file":"jinja-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/jinja-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwFG;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,EAE1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AO,CAAC,oBAAoB;IAW5B;;;;;;;;;;;;;;;OAeG;IACH,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,yBAAyB;IAUjC,OAAO,CAAC,gBAAgB;IAcxB,iFAAiF;IACjF,OAAO,CAAC,4BAA4B;CAGrC;AAED,eAAO,MAAM,YAAY,cAAqB,CAAA"}
package/dist/index.js CHANGED
@@ -187314,8 +187314,8 @@ import {
187314
187314
  dangerousInnerHtmlMetacharViolation,
187315
187315
  dangerousInnerHtmlDiagnostic,
187316
187316
  resolveStaticLoopSource,
187317
- collectLoopBoundNames,
187318
- derivesScopeFromSlot
187317
+ derivesScopeFromSlot,
187318
+ BindingScope
187319
187319
  } from "@barefootjs/jsx";
187320
187320
 
187321
187321
  // src/adapter/boolean-result.ts
@@ -188320,8 +188320,7 @@ class JinjaAdapter extends BaseAdapter {
188320
188320
  _searchParamsLocals = new Set;
188321
188321
  _loweringMatchers = [];
188322
188322
  localConstants = [];
188323
- staticLoopSourceBoundNames = new Set;
188324
- loopBoundNames = new Map;
188323
+ scope = BindingScope.EMPTY;
188325
188324
  nullableOptionalProps = new Set;
188326
188325
  constructor(options = {}) {
188327
188326
  super();
@@ -188337,8 +188336,7 @@ class JinjaAdapter extends BaseAdapter {
188337
188336
  this.propsParams = ir.metadata.propsParams.map((p) => ({ name: p.name }));
188338
188337
  this.booleanTypedProps = collectBooleanTypedProps(ir);
188339
188338
  this.localConstants = ir.metadata.localConstants ?? [];
188340
- this.staticLoopSourceBoundNames = collectLoopBoundNames(ir);
188341
- this.loopBoundNames.clear();
188339
+ this.scope = BindingScope.EMPTY;
188342
188340
  this.nullableOptionalProps = collectNullableOptionalProps(ir);
188343
188341
  this.stringValueNames = collectStringValueNames(ir);
188344
188342
  this.moduleStringConsts = collectModuleStringConsts(ir.metadata.localConstants);
@@ -188633,7 +188631,7 @@ ${whenTrue}
188633
188631
  });
188634
188632
  }
188635
188633
  const staticItems = resolveStaticLoopSource(loop.arrayParsed, this.localConstants, {
188636
- isNameShadowed: (name) => this.staticLoopSourceBoundNames.has(name)
188634
+ isNameShadowed: this.scope.asShadowPredicate()
188637
188635
  });
188638
188636
  const staticArray = staticItems !== null ? staticValueToJinja(staticItems) : null;
188639
188637
  const arrayName = loop.array.trim();
@@ -188687,40 +188685,15 @@ ${whenTrue}
188687
188685
  this.inLoop = true;
188688
188686
  const prevLoopKeyDepth = this.currentLoopKeyDepth;
188689
188687
  this.currentLoopKeyDepth = loop.depth;
188688
+ const prevScope = this.scope;
188689
+ this.scope = prevScope.enterLoopRow(loop);
188690
188690
  const preambleLines = (loop.preamble?.declarations ?? []).map((d) => `{% set ${jinjaIdent(d.name)} = ${this.convertExpressionToJinja(d.raw, d.valueParsed)} %}`);
188691
- const loopBound = [];
188692
- if (loop.objectIteration === "entries") {
188693
- loopBound.push(loop.index ?? param, param);
188694
- } else if (loop.objectIteration === "keys" || loop.objectIteration === "values") {
188695
- loopBound.push(param);
188696
- } else if (loop.iterationShape === "keys") {
188697
- loopBound.push("__bf_item", param);
188698
- } else if (supportableDestructure) {
188699
- loopBound.push("__bf_item", ...(loop.paramBindings ?? []).map((b) => b.name));
188700
- if (loop.index)
188701
- loopBound.push(loop.index);
188702
- } else {
188703
- loopBound.push(param);
188704
- if (loop.index)
188705
- loopBound.push(loop.index);
188706
- }
188707
- for (const d of loop.preamble?.declarations ?? [])
188708
- loopBound.push(d.name);
188709
- for (const n of loopBound) {
188710
- this.loopBoundNames.set(n, (this.loopBoundNames.get(n) ?? 0) + 1);
188711
- }
188712
188691
  const childrenUnderLoop = this.renderChildren(loop.children);
188713
- for (const n of loopBound) {
188714
- const c = (this.loopBoundNames.get(n) ?? 1) - 1;
188715
- if (c <= 0)
188716
- this.loopBoundNames.delete(n);
188717
- else
188718
- this.loopBoundNames.set(n, c);
188719
- }
188720
188692
  this.currentLoopKeyDepth = prevLoopKeyDepth;
188721
188693
  this.inLoop = prevInLoop;
188722
188694
  const bodyChildren = loop.bodyIsItemConditional && loop.key ? `{{ bf.comment("loop-i:" ~ bf.string(${this.convertExpressionToJinja(loop.key)})) | safe }}
188723
188695
  ${childrenUnderLoop}` : childrenUnderLoop;
188696
+ this.scope = prevScope;
188724
188697
  const lines = [];
188725
188698
  lines.push(`{{ bf.comment("loop:${loop.markerId}") | safe }}`);
188726
188699
  const forHeader = loop.objectIteration === "entries" ? `{% for ${jinjaIdent(loop.index ?? param)}, ${jinjaIdent(param)} in ${array}.items() %}` : loop.objectIteration === "keys" ? `{% for ${jinjaIdent(param)} in ${array}.keys() %}` : loop.objectIteration === "values" ? `{% for ${jinjaIdent(param)} in ${array}.values() %}` : `{% for ${jinjaIdent(loopVar)} in ${array} %}`;
@@ -188952,7 +188925,7 @@ ${name}="{{ bf.string(${val}) }}"
188952
188925
  if (ternaryDict !== null) {
188953
188926
  return `{{ bf.spread_attrs(${ternaryDict}) | safe }}`;
188954
188927
  }
188955
- if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.loopBoundNames.has(trimmed)) {
188928
+ if (/^[A-Za-z_$][\w$]*$/.test(trimmed) && !this.scope.isBound(trimmed)) {
188956
188929
  const localConst = (this.localConstants ?? []).find((c) => c.name === trimmed && !c.isModule);
188957
188930
  if (localConst?.value !== undefined) {
188958
188931
  const initTrimmed = localConst.value.trim();
@@ -189187,7 +189160,7 @@ Options:
189187
189160
  return this.booleanTypedProps.has(bare);
189188
189161
  }
189189
189162
  isLoopBoundName(name) {
189190
- return this.loopBoundNames.has(name);
189163
+ return this.scope.isBound(name);
189191
189164
  }
189192
189165
  shouldBoolStr(expr, name) {
189193
189166
  if (isExplicitStringCall(expr))
@@ -189195,7 +189168,7 @@ Options:
189195
189168
  return isBooleanResultExpr(expr) || isAriaBooleanAttr(name) || this.isBooleanTypedPropRef(expr);
189196
189169
  }
189197
189170
  _resolveLiteralConst(name) {
189198
- if (this.staticLoopSourceBoundNames.has(name))
189171
+ if (this.scope.isBound(name))
189199
189172
  return null;
189200
189173
  const c = (this.localConstants ?? []).find((lc) => lc.name === name);
189201
189174
  if (c?.value === undefined)
@@ -189209,9 +189182,7 @@ Options:
189209
189182
  return null;
189210
189183
  }
189211
189184
  _resolveStaticRecordLiteral(objectName, key) {
189212
- if (this.staticLoopSourceBoundNames.has(objectName))
189213
- return null;
189214
- const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants);
189185
+ const hit = lookupStaticRecordLiteral(objectName, key, this.localConstants, (name) => this.scope.isBound(name));
189215
189186
  if (!hit)
189216
189187
  return null;
189217
189188
  return hit.kind === "number" ? hit.text : `'${escapeJinjaSingleQuoted(hit.text)}'`;