@barefootjs/mojolicious 0.33.6 → 0.34.0

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.
@@ -17,13 +17,23 @@
17
17
  * genuinely needs it, so the seam documents the real cross-module coupling
18
18
  * rather than re-exposing the whole adapter.
19
19
  */
20
- import type { ParsedExpr, CompilerError, IRMetadata } from '@barefootjs/jsx';
20
+ import type { ParsedExpr, CompilerError, IRMetadata, LoweringMatcher } from '@barefootjs/jsx';
21
21
  export interface MojoEmitContext {
22
22
  /**
23
23
  * (#1922) Local binding names the request-scoped `searchParams()` env signal
24
24
  * is imported under. Non-empty enables the env-signal method-call lowering.
25
25
  */
26
26
  readonly _searchParamsLocals: Set<string>;
27
+ /**
28
+ * Registered lowering-plugin matchers (#2057), bound to this component's
29
+ * metadata at init. Read by `MojoTopLevelEmitter`'s `lowering` seam (#2843)
30
+ * so a registered call — the built-in `queryHref`, or any userland plugin —
31
+ * is recognised no matter where it sits in an expression tree (a ternary
32
+ * branch, a template-literal interpolation, …), not only when it's the call
33
+ * the adapter's own top-level conversion entry point
34
+ * (`convertExpressionToPerl`) is asked to lower directly.
35
+ */
36
+ readonly _loweringMatchers: readonly LoweringMatcher[];
27
37
  /**
28
38
  * Inline a module-scope pure string-literal const by name as the resolved
29
39
  * literal value, or null when the name is not such a const.
@@ -1 +1 @@
1
- {"version":3,"file":"emit-context.d.ts","sourceRoot":"","sources":["../../src/adapter/emit-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5E,MAAM,WAAW,eAAe;IAC9B;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAEzC;;;OAGG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;I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AAC,EAAE,UAAU,GAAG,MAAM,CAAA;CACtE;AAED;;;;;GAKG;AACH,MAAM,WAAW,eAAe;IAC9B;;;;;;;;;;;;OAYG;IACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;CAClG"}
@@ -10,7 +10,7 @@
10
10
  * - `MojoTopLevelEmitter` — top-level / stash context; depends on the
11
11
  * adapter only through the narrow `MojoEmitContext` seam.
12
12
  */
13
- import { type ParsedExprEmitter, type ArrayMethod, type LiteralType, type ParsedExpr, type ObjectLiteralProperty, type FlatDepth, type TemplatePart } from '@barefootjs/jsx';
13
+ import { type ParsedExprEmitter, type ArrayMethod, type LiteralType, type ParsedExpr, type ObjectLiteralProperty, type FlatDepth, type TemplatePart, type LoweringEmitter } from '@barefootjs/jsx';
14
14
  import type { MojoEmitContext } from '../emit-context.ts';
15
15
  export declare class MojoFilterEmitter implements ParsedExprEmitter {
16
16
  private readonly param;
@@ -55,6 +55,16 @@ export declare class MojoFilterEmitter implements ParsedExprEmitter {
55
55
  export declare class MojoTopLevelEmitter implements ParsedExprEmitter {
56
56
  private readonly ctx;
57
57
  constructor(ctx: MojoEmitContext);
58
+ /**
59
+ * Registered-lowering seam (#2843): `emitParsedExpr`'s shared `call` case
60
+ * tries every matcher here BEFORE `call()` itself, so a registered call
61
+ * (the built-in `queryHref`, or any userland plugin) is recognised no
62
+ * matter where it sits in the tree. `render` is what used to live inline
63
+ * in `MojoAdapter.convertExpressionToPerl` before the object-literal
64
+ * support-gate refusal (`checkSupport`'s `call` arm, now itself
65
+ * registry-aware) made the pre-gate special case unnecessary.
66
+ */
67
+ get lowering(): LoweringEmitter;
58
68
  identifier(name: string): string;
59
69
  literal(value: string | number | boolean | null, literalType: LiteralType): string;
60
70
  member(object: ParsedExpr, property: string, _computed: boolean, _optional: boolean, emit: (e: ParsedExpr) => string): string;
@@ -1 +1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U,EACrB,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,CAER;IAED,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CA6B9E;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CAOpF;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK1B;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAOjD;IAED,aAAa,CAAC,UAAU,EAAE,qBAAqB,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CAoBxG;CACF"}
@@ -17,8 +17,6 @@ import {
17
17
  lookupStaticRecordLiteral,
18
18
  searchParamsLocalNames,
19
19
  prepareLoweringMatchers,
20
- queryHrefArgs,
21
- isValidHelperId,
22
20
  sortComparatorFromArrow as sortComparatorFromArrow2,
23
21
  isLowerableLoopDestructure,
24
22
  isDangerousInnerHtmlAttr,
@@ -363,7 +361,9 @@ import {
363
361
  identifierPath,
364
362
  matchSearchParamsMethodCall,
365
363
  sortComparatorFromArrow,
366
- asCallbackMethodCall
364
+ asCallbackMethodCall,
365
+ queryHrefArgs,
366
+ isValidHelperId
367
367
  } from "@barefootjs/jsx";
368
368
 
369
369
  // src/adapter/expr/operand.ts
@@ -525,6 +525,21 @@ class MojoTopLevelEmitter {
525
525
  constructor(ctx) {
526
526
  this.ctx = ctx;
527
527
  }
528
+ get lowering() {
529
+ return {
530
+ matchers: this.ctx._loweringMatchers,
531
+ render: (node, emit) => {
532
+ if (node.kind === "guard-list" && node.helper === "query") {
533
+ const qArgs = queryHrefArgs(node, emit);
534
+ return `bf->query(${qArgs.join(", ")})`;
535
+ }
536
+ if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
537
+ return `bf->${node.helper}(${node.args.map(emit).join(", ")})`;
538
+ }
539
+ return null;
540
+ }
541
+ };
542
+ }
528
543
  identifier(name) {
529
544
  if (name === "undefined" || name === "null")
530
545
  return "undef";
@@ -1102,7 +1117,9 @@ class MojoAdapter extends BaseAdapter {
1102
1117
  return null;
1103
1118
  return {
1104
1119
  condition: exprToString(parsed.test),
1105
- consequent: exprToString(parsed.consequent)
1120
+ consequent: exprToString(parsed.consequent),
1121
+ testParsed: parsed.test,
1122
+ consequentParsed: parsed.consequent
1106
1123
  };
1107
1124
  }
1108
1125
  resolveLiteralConst(name) {
@@ -1630,8 +1647,8 @@ ${children}`;
1630
1647
  {
1631
1648
  const m = this.parseUndefinedAlternateTernary(value.expr);
1632
1649
  if (m) {
1633
- const cond = this.convertExpressionToPerl(m.condition);
1634
- const val = this.convertExpressionToPerl(m.consequent);
1650
+ const cond = this.convertExpressionToPerl("", m.testParsed);
1651
+ const val = this.convertExpressionToPerl("", m.consequentParsed);
1635
1652
  return `<% if (${cond}) { %>${name}="<%= ${val} %>"<% } %>`;
1636
1653
  }
1637
1654
  }
@@ -1760,7 +1777,7 @@ ${children}`;
1760
1777
  if (!startsAsObjectLiteral && !hasTaggedTemplate)
1761
1778
  return false;
1762
1779
  const parsed = parseExpression2(expr.trim());
1763
- const support = isSupported(parsed);
1780
+ const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
1764
1781
  if (parsed.kind !== "unsupported" && support.supported)
1765
1782
  return false;
1766
1783
  const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
@@ -1780,6 +1797,7 @@ ${reason}` : "";
1780
1797
  get emitCtx() {
1781
1798
  return {
1782
1799
  _searchParamsLocals: this._searchParamsLocals,
1800
+ _loweringMatchers: this._loweringMatchers,
1783
1801
  resolveModuleStringConst: (name) => this.resolveModuleStringConst(name),
1784
1802
  resolveLiteralConst: (name) => this.resolveLiteralConst(name),
1785
1803
  resolveStaticRecordLiteral: (o, k) => this.resolveStaticRecordLiteral(o, k),
@@ -1810,20 +1828,8 @@ ${reason}` : "";
1810
1828
  return "''";
1811
1829
  parsed = parseExpression2(trimmed);
1812
1830
  }
1813
- if (parsed.kind === "call") {
1814
- for (const matcher of this._loweringMatchers) {
1815
- const node = matcher(parsed.callee, parsed.args);
1816
- if (node?.kind === "guard-list" && node.helper === "query") {
1817
- const argsGo = queryHrefArgs(node, (n) => this.renderParsedExprToPerl(n));
1818
- return `bf->query(${argsGo.join(", ")})`;
1819
- }
1820
- if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
1821
- const argsX = node.args.map((a) => this.renderParsedExprToPerl(a));
1822
- return `bf->${node.helper}(${argsX.join(", ")})`;
1823
- }
1824
- }
1825
- }
1826
- const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
1831
+ const supportOpts = { loweringMatchers: this._loweringMatchers };
1832
+ const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
1827
1833
  if (!support.supported) {
1828
1834
  this.errors.push({
1829
1835
  code: "BF101",
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import type { ComponentIR, IRNode, IRElement, IRText, IRExpression, IRConditional, IRLoop, IRComponent, IRFragment, IRSlot, IRIfStatement, IRProvider, IRAsync, TemplatePrimitiveRegistry } from '@barefootjs/jsx';
7
7
  import { BaseAdapter, type AdapterOutput, type AdapterGenerateOptions, type IRNodeEmitter, type EmitIRNode } from '@barefootjs/jsx';
8
+ import type { ParsedExpr } from '@barefootjs/jsx';
8
9
  import type { MojoRenderCtx } from './lib/types.ts';
9
10
  export type { MojoAdapterOptions } from './lib/types.ts';
10
11
  import type { MojoAdapterOptions } from './lib/types.ts';
@@ -162,6 +163,8 @@ export declare class MojoAdapter extends BaseAdapter implements IRNodeEmitter<Mo
162
163
  parseUndefinedAlternateTernary(expr: string): {
163
164
  condition: string;
164
165
  consequent: string;
166
+ testParsed: ParsedExpr;
167
+ consequentParsed: ParsedExpr;
165
168
  } | null;
166
169
  /**
167
170
  * Inline a const (any scope) whose initializer is a pure numeric or
@@ -1 +1 @@
1
- {"version":3,"file":"mojo-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/mojo-adapter.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EACV,WAAW,EAEX,MAAM,EACN,SAAS,EACT,MAAM,EACN,YAAY,EACZ,aAAa,EACb,MAAM,EACN,WAAW,EACX,UAAU,EACV,MAAM,EACN,aAAa,EACb,UAAU,EACV,OAAO,EAMP,yBAAyB,EAE1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAClB,KAAK,UAAU,EAkChB,MAAM,iBAAiB,CAAA;AAKxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AA0BnD,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAuCxD,qBAAa,WAAY,SAAQ,WAAY,YAAW,aAAa,CAAC,aAAa,CAAC;IAClF,IAAI,SAAgB;IACpB,SAAS,SAAa;IACtB,qBAAqB,UAAO;IAE5B;;;;;;;;;;;OAWG;IACH,kBAAkB,EAAE,yBAAyB,CAA0B;IAEvE,OAAO,CAAC,aAAa,CAAa;IAClC,OAAO,CAAC,OAAO,CAA8B;IAC7C,OAAO,CAAC,MAAM,CAAsB;IACpC;;;;;;OAMG;IACH,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,WAAW,CAAyB;IAC5C,OAAO,CAAC,iBAAiB,CAAyB;IAClD;;;;;;OAMG;IACH,OAAO,CAAC,iBAAiB,CAAyB;IAClD;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB,CAAyB;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D/B;;;;;OAKG;IACH,OAAO,CAAC,sBAAsB;IAI9B;;;;OAIG;IACH;4EACwE;IACxE,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,gBAAgB;IAcxB,iFAAiF;IACjF,OAAO,CAAC,2BAA2B;CAGpC;AAED,eAAO,MAAM,WAAW,aAAoB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"conformance-pins.d.ts","sourceRoot":"","sources":["../src/conformance-pins.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,eAAO,MAAM,eAAe,EAAE,eAsD7B,CAAA"}
1
+ {"version":3,"file":"conformance-pins.d.ts","sourceRoot":"","sources":["../src/conformance-pins.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,eAAO,MAAM,eAAe,EAAE,eA0D7B,CAAA"}
package/dist/index.js CHANGED
@@ -17,8 +17,6 @@ import {
17
17
  lookupStaticRecordLiteral,
18
18
  searchParamsLocalNames,
19
19
  prepareLoweringMatchers,
20
- queryHrefArgs,
21
- isValidHelperId,
22
20
  sortComparatorFromArrow as sortComparatorFromArrow2,
23
21
  isLowerableLoopDestructure,
24
22
  isDangerousInnerHtmlAttr,
@@ -363,7 +361,9 @@ import {
363
361
  identifierPath,
364
362
  matchSearchParamsMethodCall,
365
363
  sortComparatorFromArrow,
366
- asCallbackMethodCall
364
+ asCallbackMethodCall,
365
+ queryHrefArgs,
366
+ isValidHelperId
367
367
  } from "@barefootjs/jsx";
368
368
 
369
369
  // src/adapter/expr/operand.ts
@@ -525,6 +525,21 @@ class MojoTopLevelEmitter {
525
525
  constructor(ctx) {
526
526
  this.ctx = ctx;
527
527
  }
528
+ get lowering() {
529
+ return {
530
+ matchers: this.ctx._loweringMatchers,
531
+ render: (node, emit) => {
532
+ if (node.kind === "guard-list" && node.helper === "query") {
533
+ const qArgs = queryHrefArgs(node, emit);
534
+ return `bf->query(${qArgs.join(", ")})`;
535
+ }
536
+ if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
537
+ return `bf->${node.helper}(${node.args.map(emit).join(", ")})`;
538
+ }
539
+ return null;
540
+ }
541
+ };
542
+ }
528
543
  identifier(name) {
529
544
  if (name === "undefined" || name === "null")
530
545
  return "undef";
@@ -1102,7 +1117,9 @@ class MojoAdapter extends BaseAdapter {
1102
1117
  return null;
1103
1118
  return {
1104
1119
  condition: exprToString(parsed.test),
1105
- consequent: exprToString(parsed.consequent)
1120
+ consequent: exprToString(parsed.consequent),
1121
+ testParsed: parsed.test,
1122
+ consequentParsed: parsed.consequent
1106
1123
  };
1107
1124
  }
1108
1125
  resolveLiteralConst(name) {
@@ -1630,8 +1647,8 @@ ${children}`;
1630
1647
  {
1631
1648
  const m = this.parseUndefinedAlternateTernary(value.expr);
1632
1649
  if (m) {
1633
- const cond = this.convertExpressionToPerl(m.condition);
1634
- const val = this.convertExpressionToPerl(m.consequent);
1650
+ const cond = this.convertExpressionToPerl("", m.testParsed);
1651
+ const val = this.convertExpressionToPerl("", m.consequentParsed);
1635
1652
  return `<% if (${cond}) { %>${name}="<%= ${val} %>"<% } %>`;
1636
1653
  }
1637
1654
  }
@@ -1760,7 +1777,7 @@ ${children}`;
1760
1777
  if (!startsAsObjectLiteral && !hasTaggedTemplate)
1761
1778
  return false;
1762
1779
  const parsed = parseExpression2(expr.trim());
1763
- const support = isSupported(parsed);
1780
+ const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
1764
1781
  if (parsed.kind !== "unsupported" && support.supported)
1765
1782
  return false;
1766
1783
  const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
@@ -1780,6 +1797,7 @@ ${reason}` : "";
1780
1797
  get emitCtx() {
1781
1798
  return {
1782
1799
  _searchParamsLocals: this._searchParamsLocals,
1800
+ _loweringMatchers: this._loweringMatchers,
1783
1801
  resolveModuleStringConst: (name) => this.resolveModuleStringConst(name),
1784
1802
  resolveLiteralConst: (name) => this.resolveLiteralConst(name),
1785
1803
  resolveStaticRecordLiteral: (o, k) => this.resolveStaticRecordLiteral(o, k),
@@ -1810,20 +1828,8 @@ ${reason}` : "";
1810
1828
  return "''";
1811
1829
  parsed = parseExpression2(trimmed);
1812
1830
  }
1813
- if (parsed.kind === "call") {
1814
- for (const matcher of this._loweringMatchers) {
1815
- const node = matcher(parsed.callee, parsed.args);
1816
- if (node?.kind === "guard-list" && node.helper === "query") {
1817
- const argsGo = queryHrefArgs(node, (n) => this.renderParsedExprToPerl(n));
1818
- return `bf->query(${argsGo.join(", ")})`;
1819
- }
1820
- if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
1821
- const argsX = node.args.map((a) => this.renderParsedExprToPerl(a));
1822
- return `bf->${node.helper}(${argsX.join(", ")})`;
1823
- }
1824
- }
1825
- }
1826
- const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
1831
+ const supportOpts = { loweringMatchers: this._loweringMatchers };
1832
+ const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
1827
1833
  if (!support.supported) {
1828
1834
  this.errors.push({
1829
1835
  code: "BF101",
package/dist/vite.js CHANGED
@@ -12,6 +12,41 @@ import ts10 from "typescript";
12
12
 
13
13
  // ../jsx/src/expression-parser.ts
14
14
  import ts from "typescript";
15
+
16
+ // ../jsx/src/lowering-registry.ts
17
+ var plugins = [];
18
+ function registerLoweringPlugin(plugin) {
19
+ const existing = plugins.findIndex((p) => p.name === plugin.name);
20
+ if (existing >= 0)
21
+ plugins[existing] = plugin;
22
+ else
23
+ plugins.push(plugin);
24
+ }
25
+ function prepareLoweringMatchers(metadata) {
26
+ const matchers = [];
27
+ for (const plugin of plugins) {
28
+ const matcher = plugin.prepare(metadata);
29
+ if (matcher)
30
+ matchers.push(matcher);
31
+ }
32
+ return matchers;
33
+ }
34
+ function loweringNodeChildren(node) {
35
+ if (node.kind === "helper-call")
36
+ return [...node.args];
37
+ const children = [node.base];
38
+ for (const t of node.triples) {
39
+ if (t.guard)
40
+ children.push(t.guard);
41
+ children.push(t.value);
42
+ }
43
+ return children;
44
+ }
45
+ function isValidHelperId(helper) {
46
+ return /^[A-Za-z_][A-Za-z0-9_]*$/.test(helper);
47
+ }
48
+
49
+ // ../jsx/src/expression-parser.ts
15
50
  var UNSUPPORTED_METHODS = new Set([
16
51
  "filter",
17
52
  "map",
@@ -263,7 +298,7 @@ function convertNode(node, raw) {
263
298
  }
264
299
  if (n === undefined || Number.isNaN(n)) {
265
300
  const parsedDepth = convertNode(depthNode, raw);
266
- if (checkSupport(parsedDepth, "rendered").supported) {
301
+ if (checkSupport(parsedDepth, "rendered", []).supported) {
267
302
  depthExpr = parsedDepth;
268
303
  flatDepth = 1;
269
304
  } else {
@@ -1041,13 +1076,13 @@ function getUnaryOperatorString(op) {
1041
1076
  return "unknown";
1042
1077
  }
1043
1078
  }
1044
- function isSupported(expr) {
1045
- return checkSupport(expr, "rendered");
1079
+ function isSupported(expr, opts) {
1080
+ return checkSupport(expr, "rendered", opts?.loweringMatchers ?? []);
1046
1081
  }
1047
- function isSupportedValue(expr) {
1048
- return checkSupport(expr, "value");
1082
+ function isSupportedValue(expr, opts) {
1083
+ return checkSupport(expr, "value", opts?.loweringMatchers ?? []);
1049
1084
  }
1050
- function checkSupport(expr, pos) {
1085
+ function checkSupport(expr, pos, matchers) {
1051
1086
  switch (expr.kind) {
1052
1087
  case "unsupported":
1053
1088
  return { supported: false, reason: expr.reason };
@@ -1056,7 +1091,7 @@ function checkSupport(expr, pos) {
1056
1091
  return { supported: false, reason: "Unsupported syntax: ObjectLiteralExpression" };
1057
1092
  }
1058
1093
  for (const prop of expr.properties) {
1059
- const propSupport = checkSupport(prop.kind === "spread" ? prop.expr : prop.value, pos);
1094
+ const propSupport = checkSupport(prop.kind === "spread" ? prop.expr : prop.value, pos, matchers);
1060
1095
  if (!propSupport.supported)
1061
1096
  return propSupport;
1062
1097
  }
@@ -1071,7 +1106,7 @@ function checkSupport(expr, pos) {
1071
1106
  return { supported: false, reason: "Standalone arrow functions / regex literals are not supported" };
1072
1107
  case "array-literal": {
1073
1108
  for (const el of expr.elements) {
1074
- const elSupport = checkSupport(el, pos);
1109
+ const elSupport = checkSupport(el, pos, matchers);
1075
1110
  if (!elSupport.supported)
1076
1111
  return elSupport;
1077
1112
  }
@@ -1084,28 +1119,39 @@ function checkSupport(expr, pos) {
1084
1119
  reason: `String.prototype.${expr.method} supports only a string pattern + string replacement (the regex form is deferred); use a string pattern or wrap the expression in /* @client */`
1085
1120
  };
1086
1121
  }
1087
- const objSupport = checkSupport(expr.object, pos);
1122
+ const objSupport = checkSupport(expr.object, pos, matchers);
1088
1123
  if (!objSupport.supported)
1089
1124
  return objSupport;
1090
1125
  for (const arg of expr.args) {
1091
- const argSupport = checkSupport(arg, pos);
1126
+ const argSupport = checkSupport(arg, pos, matchers);
1092
1127
  if (!argSupport.supported)
1093
1128
  return argSupport;
1094
1129
  }
1095
1130
  if (expr.method === "flat" && expr.depthExpr) {
1096
- const depthSupport = checkSupport(expr.depthExpr, pos);
1131
+ const depthSupport = checkSupport(expr.depthExpr, pos, matchers);
1097
1132
  if (!depthSupport.supported)
1098
1133
  return depthSupport;
1099
1134
  }
1100
1135
  return { supported: true, level: "L2" };
1101
1136
  }
1102
1137
  case "call": {
1138
+ for (const matcher of matchers) {
1139
+ const node = matcher(expr.callee, expr.args);
1140
+ if (!node)
1141
+ continue;
1142
+ for (const child of loweringNodeChildren(node)) {
1143
+ const childSupport = checkSupport(child, pos, matchers);
1144
+ if (!childSupport.supported)
1145
+ return childSupport;
1146
+ }
1147
+ return { supported: true, level: "L2" };
1148
+ }
1103
1149
  const cb = asCallbackMethodCall(expr);
1104
1150
  if (cb) {
1105
- const objSupport = checkSupport(cb.object, pos);
1151
+ const objSupport = checkSupport(cb.object, pos, matchers);
1106
1152
  if (!objSupport.supported)
1107
1153
  return objSupport;
1108
- const bodySupport = checkSupport(cb.arrow.body, pos);
1154
+ const bodySupport = checkSupport(cb.arrow.body, pos, matchers);
1109
1155
  if (!bodySupport.supported) {
1110
1156
  return {
1111
1157
  supported: false,
@@ -1114,13 +1160,13 @@ function checkSupport(expr, pos) {
1114
1160
  };
1115
1161
  }
1116
1162
  for (const rest of cb.args) {
1117
- const restSupport = checkSupport(rest, pos);
1163
+ const restSupport = checkSupport(rest, pos, matchers);
1118
1164
  if (!restSupport.supported)
1119
1165
  return restSupport;
1120
1166
  }
1121
1167
  return { supported: true, level: "L5" };
1122
1168
  }
1123
- const calleeSupport = checkSupport(expr.callee, pos);
1169
+ const calleeSupport = checkSupport(expr.callee, pos, matchers);
1124
1170
  if (!calleeSupport.supported) {
1125
1171
  return calleeSupport;
1126
1172
  }
@@ -1139,7 +1185,7 @@ function checkSupport(expr, pos) {
1139
1185
  return { supported: true, level: "L1" };
1140
1186
  }
1141
1187
  for (const arg of expr.args) {
1142
- const argSupport = checkSupport(arg, pos);
1188
+ const argSupport = checkSupport(arg, pos, matchers);
1143
1189
  if (!argSupport.supported) {
1144
1190
  return argSupport;
1145
1191
  }
@@ -1147,7 +1193,7 @@ function checkSupport(expr, pos) {
1147
1193
  return { supported: true, level: "L2" };
1148
1194
  }
1149
1195
  case "member": {
1150
- const objSupport = checkSupport(expr.object, pos);
1196
+ const objSupport = checkSupport(expr.object, pos, matchers);
1151
1197
  if (!objSupport.supported) {
1152
1198
  return objSupport;
1153
1199
  }
@@ -1157,19 +1203,19 @@ function checkSupport(expr, pos) {
1157
1203
  return { supported: true, level: "L2" };
1158
1204
  }
1159
1205
  case "index-access": {
1160
- const objSupport = checkSupport(expr.object, pos);
1206
+ const objSupport = checkSupport(expr.object, pos, matchers);
1161
1207
  if (!objSupport.supported)
1162
1208
  return objSupport;
1163
- const indexSupport = checkSupport(expr.index, pos);
1209
+ const indexSupport = checkSupport(expr.index, pos, matchers);
1164
1210
  if (!indexSupport.supported)
1165
1211
  return indexSupport;
1166
1212
  return { supported: true, level: "L2" };
1167
1213
  }
1168
1214
  case "binary": {
1169
- const leftSupport = checkSupport(expr.left, pos);
1215
+ const leftSupport = checkSupport(expr.left, pos, matchers);
1170
1216
  if (!leftSupport.supported)
1171
1217
  return leftSupport;
1172
- const rightSupport = checkSupport(expr.right, pos);
1218
+ const rightSupport = checkSupport(expr.right, pos, matchers);
1173
1219
  if (!rightSupport.supported)
1174
1220
  return rightSupport;
1175
1221
  if (["===", "==", "!==", "!=", ">", "<", ">=", "<="].includes(expr.op)) {
@@ -1181,7 +1227,7 @@ function checkSupport(expr, pos) {
1181
1227
  return { supported: false, reason: `Unknown operator: ${expr.op}` };
1182
1228
  }
1183
1229
  case "unary": {
1184
- const argSupport = checkSupport(expr.argument, pos);
1230
+ const argSupport = checkSupport(expr.argument, pos, matchers);
1185
1231
  if (!argSupport.supported)
1186
1232
  return argSupport;
1187
1233
  if (expr.op === "!") {
@@ -1193,25 +1239,25 @@ function checkSupport(expr, pos) {
1193
1239
  return { supported: false, reason: `Unsupported unary operator: ${expr.op}` };
1194
1240
  }
1195
1241
  case "logical": {
1196
- const leftSupport = checkSupport(expr.left, pos);
1242
+ const leftSupport = checkSupport(expr.left, pos, matchers);
1197
1243
  if (!leftSupport.supported)
1198
1244
  return leftSupport;
1199
1245
  if (expr.op === "??" && expr.right.kind === "object-literal" && expr.right.properties.length === 0) {
1200
1246
  return { supported: true, level: "L4" };
1201
1247
  }
1202
- const rightSupport = checkSupport(expr.right, pos);
1248
+ const rightSupport = checkSupport(expr.right, pos, matchers);
1203
1249
  if (!rightSupport.supported)
1204
1250
  return rightSupport;
1205
1251
  return { supported: true, level: "L4" };
1206
1252
  }
1207
1253
  case "conditional": {
1208
- const testSupport = checkSupport(expr.test, pos);
1254
+ const testSupport = checkSupport(expr.test, pos, matchers);
1209
1255
  if (!testSupport.supported)
1210
1256
  return testSupport;
1211
- const consSupport = checkSupport(expr.consequent, pos);
1257
+ const consSupport = checkSupport(expr.consequent, pos, matchers);
1212
1258
  if (!consSupport.supported)
1213
1259
  return consSupport;
1214
- const altSupport = checkSupport(expr.alternate, pos);
1260
+ const altSupport = checkSupport(expr.alternate, pos, matchers);
1215
1261
  if (!altSupport.supported)
1216
1262
  return altSupport;
1217
1263
  return { supported: true, level: "L4" };
@@ -1219,7 +1265,7 @@ function checkSupport(expr, pos) {
1219
1265
  case "template-literal": {
1220
1266
  for (const part of expr.parts) {
1221
1267
  if (part.type === "expression") {
1222
- const partSupport = checkSupport(part.expr, pos);
1268
+ const partSupport = checkSupport(part.expr, pos, matchers);
1223
1269
  if (!partSupport.supported)
1224
1270
  return partSupport;
1225
1271
  }
@@ -3173,30 +3219,6 @@ import ts16 from "typescript";
3173
3219
 
3174
3220
  // ../jsx/src/relocate.ts
3175
3221
  import ts18 from "typescript";
3176
-
3177
- // ../jsx/src/lowering-registry.ts
3178
- var plugins = [];
3179
- function registerLoweringPlugin(plugin) {
3180
- const existing = plugins.findIndex((p) => p.name === plugin.name);
3181
- if (existing >= 0)
3182
- plugins[existing] = plugin;
3183
- else
3184
- plugins.push(plugin);
3185
- }
3186
- function prepareLoweringMatchers(metadata) {
3187
- const matchers = [];
3188
- for (const plugin of plugins) {
3189
- const matcher = plugin.prepare(metadata);
3190
- if (matcher)
3191
- matchers.push(matcher);
3192
- }
3193
- return matchers;
3194
- }
3195
- function isValidHelperId(helper) {
3196
- return /^[A-Za-z_][A-Za-z0-9_]*$/.test(helper);
3197
- }
3198
-
3199
- // ../jsx/src/relocate.ts
3200
3222
  var REGISTRY_SAFE_BINDING_KINDS = new Set([
3201
3223
  "global",
3202
3224
  "module-import",
@@ -4664,6 +4686,17 @@ function emitParsedExpr(expr, emitter) {
4664
4686
  case "literal":
4665
4687
  return emitter.literal(expr.value, expr.literalType);
4666
4688
  case "call": {
4689
+ if (emitter.lowering) {
4690
+ for (const matcher of emitter.lowering.matchers) {
4691
+ const node = matcher(expr.callee, expr.args);
4692
+ if (!node)
4693
+ continue;
4694
+ const rendered = emitter.lowering.render(node, emit);
4695
+ if (rendered !== null)
4696
+ return rendered;
4697
+ break;
4698
+ }
4699
+ }
4667
4700
  const cb = asCallbackMethodCall(expr);
4668
4701
  if (cb)
4669
4702
  return emitter.callbackMethod(cb.method, cb.object, cb.arrow, cb.args, emit);
@@ -5727,6 +5760,21 @@ class MojoTopLevelEmitter {
5727
5760
  constructor(ctx) {
5728
5761
  this.ctx = ctx;
5729
5762
  }
5763
+ get lowering() {
5764
+ return {
5765
+ matchers: this.ctx._loweringMatchers,
5766
+ render: (node, emit) => {
5767
+ if (node.kind === "guard-list" && node.helper === "query") {
5768
+ const qArgs = queryHrefArgs(node, emit);
5769
+ return `bf->query(${qArgs.join(", ")})`;
5770
+ }
5771
+ if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
5772
+ return `bf->${node.helper}(${node.args.map(emit).join(", ")})`;
5773
+ }
5774
+ return null;
5775
+ }
5776
+ };
5777
+ }
5730
5778
  identifier(name) {
5731
5779
  if (name === "undefined" || name === "null")
5732
5780
  return "undef";
@@ -6296,7 +6344,9 @@ class MojoAdapter extends BaseAdapter {
6296
6344
  return null;
6297
6345
  return {
6298
6346
  condition: exprToString(parsed.test),
6299
- consequent: exprToString(parsed.consequent)
6347
+ consequent: exprToString(parsed.consequent),
6348
+ testParsed: parsed.test,
6349
+ consequentParsed: parsed.consequent
6300
6350
  };
6301
6351
  }
6302
6352
  resolveLiteralConst(name) {
@@ -6824,8 +6874,8 @@ ${children}`;
6824
6874
  {
6825
6875
  const m = this.parseUndefinedAlternateTernary(value.expr);
6826
6876
  if (m) {
6827
- const cond = this.convertExpressionToPerl(m.condition);
6828
- const val = this.convertExpressionToPerl(m.consequent);
6877
+ const cond = this.convertExpressionToPerl("", m.testParsed);
6878
+ const val = this.convertExpressionToPerl("", m.consequentParsed);
6829
6879
  return `<% if (${cond}) { %>${name}="<%= ${val} %>"<% } %>`;
6830
6880
  }
6831
6881
  }
@@ -6954,7 +7004,7 @@ ${children}`;
6954
7004
  if (!startsAsObjectLiteral && !hasTaggedTemplate)
6955
7005
  return false;
6956
7006
  const parsed = parseExpression(expr.trim());
6957
- const support = isSupported(parsed);
7007
+ const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
6958
7008
  if (parsed.kind !== "unsupported" && support.supported)
6959
7009
  return false;
6960
7010
  const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
@@ -6974,6 +7024,7 @@ ${reason}` : "";
6974
7024
  get emitCtx() {
6975
7025
  return {
6976
7026
  _searchParamsLocals: this._searchParamsLocals,
7027
+ _loweringMatchers: this._loweringMatchers,
6977
7028
  resolveModuleStringConst: (name) => this.resolveModuleStringConst(name),
6978
7029
  resolveLiteralConst: (name) => this.resolveLiteralConst(name),
6979
7030
  resolveStaticRecordLiteral: (o, k) => this.resolveStaticRecordLiteral(o, k),
@@ -7004,20 +7055,8 @@ ${reason}` : "";
7004
7055
  return "''";
7005
7056
  parsed = parseExpression(trimmed);
7006
7057
  }
7007
- if (parsed.kind === "call") {
7008
- for (const matcher of this._loweringMatchers) {
7009
- const node = matcher(parsed.callee, parsed.args);
7010
- if (node?.kind === "guard-list" && node.helper === "query") {
7011
- const argsGo = queryHrefArgs(node, (n) => this.renderParsedExprToPerl(n));
7012
- return `bf->query(${argsGo.join(", ")})`;
7013
- }
7014
- if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
7015
- const argsX = node.args.map((a) => this.renderParsedExprToPerl(a));
7016
- return `bf->${node.helper}(${argsX.join(", ")})`;
7017
- }
7018
- }
7019
- }
7020
- const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
7058
+ const supportOpts = { loweringMatchers: this._loweringMatchers };
7059
+ const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
7021
7060
  if (!support.supported) {
7022
7061
  this.errors.push({
7023
7062
  code: "BF101",
@@ -1,5 +1,5 @@
1
1
  package BarefootJS::Backend::Mojo;
2
- our $VERSION = "0.33.4";
2
+ our $VERSION = "0.33.6";
3
3
  use Mojo::Base -base, -signatures;
4
4
 
5
5
  use Mojo::ByteStream qw(b);
@@ -1,5 +1,5 @@
1
1
  package Mojolicious::Plugin::BarefootJS::DevReload;
2
- our $VERSION = "0.33.4";
2
+ our $VERSION = "0.33.6";
3
3
  use Mojo::Base 'Mojolicious::Plugin', -signatures;
4
4
 
5
5
  =head1 NAME
@@ -1,5 +1,5 @@
1
1
  package Mojolicious::Plugin::BarefootJS;
2
- our $VERSION = "0.33.4";
2
+ our $VERSION = "0.33.6";
3
3
  use Mojo::Base 'Mojolicious::Plugin', -signatures;
4
4
 
5
5
  use Mojo::File qw(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barefootjs/mojolicious",
3
- "version": "0.33.6",
3
+ "version": "0.34.0",
4
4
  "description": "Mojolicious EP template adapter for BarefootJS - generates .html.ep files from IR",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -52,7 +52,7 @@
52
52
  "directory": "packages/adapter-mojolicious"
53
53
  },
54
54
  "dependencies": {
55
- "@barefootjs/shared": "0.33.6"
55
+ "@barefootjs/shared": "0.34.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "@barefootjs/jsx": ">=0.2.0",
@@ -70,9 +70,9 @@
70
70
  },
71
71
  "devDependencies": {
72
72
  "@barefootjs/adapter-tests": "0.1.0",
73
- "@barefootjs/jsx": "0.33.6",
74
- "@barefootjs/vite": "0.33.6",
75
- "@barefootjs/client": "0.33.6",
73
+ "@barefootjs/jsx": "0.34.0",
74
+ "@barefootjs/vite": "0.34.0",
75
+ "@barefootjs/client": "0.34.0",
76
76
  "vite": "^6.0.0"
77
77
  }
78
78
  }
@@ -18,7 +18,7 @@
18
18
  * rather than re-exposing the whole adapter.
19
19
  */
20
20
 
21
- import type { ParsedExpr, CompilerError, IRMetadata } from '@barefootjs/jsx'
21
+ import type { ParsedExpr, CompilerError, IRMetadata, LoweringMatcher } from '@barefootjs/jsx'
22
22
 
23
23
  export interface MojoEmitContext {
24
24
  /**
@@ -27,6 +27,17 @@ export interface MojoEmitContext {
27
27
  */
28
28
  readonly _searchParamsLocals: Set<string>
29
29
 
30
+ /**
31
+ * Registered lowering-plugin matchers (#2057), bound to this component's
32
+ * metadata at init. Read by `MojoTopLevelEmitter`'s `lowering` seam (#2843)
33
+ * so a registered call — the built-in `queryHref`, or any userland plugin —
34
+ * is recognised no matter where it sits in an expression tree (a ternary
35
+ * branch, a template-literal interpolation, …), not only when it's the call
36
+ * the adapter's own top-level conversion entry point
37
+ * (`convertExpressionToPerl`) is asked to lower directly.
38
+ */
39
+ readonly _loweringMatchers: readonly LoweringMatcher[]
40
+
30
41
  /**
31
42
  * Inline a module-scope pure string-literal const by name as the resolved
32
43
  * literal value, or null when the name is not such a const.
@@ -27,6 +27,10 @@ import { groupBinaryOperand,
27
27
  matchSearchParamsMethodCall,
28
28
  sortComparatorFromArrow,
29
29
  asCallbackMethodCall,
30
+ type LoweringEmitter,
31
+ type LoweringNode,
32
+ queryHrefArgs,
33
+ isValidHelperId,
30
34
  } from '@barefootjs/jsx'
31
35
 
32
36
  import type { MojoEmitContext } from '../emit-context.ts'
@@ -323,6 +327,35 @@ export class MojoTopLevelEmitter implements ParsedExprEmitter {
323
327
  this.ctx = ctx
324
328
  }
325
329
 
330
+ /**
331
+ * Registered-lowering seam (#2843): `emitParsedExpr`'s shared `call` case
332
+ * tries every matcher here BEFORE `call()` itself, so a registered call
333
+ * (the built-in `queryHref`, or any userland plugin) is recognised no
334
+ * matter where it sits in the tree. `render` is what used to live inline
335
+ * in `MojoAdapter.convertExpressionToPerl` before the object-literal
336
+ * support-gate refusal (`checkSupport`'s `call` arm, now itself
337
+ * registry-aware) made the pre-gate special case unnecessary.
338
+ */
339
+ get lowering(): LoweringEmitter {
340
+ return {
341
+ matchers: this.ctx._loweringMatchers,
342
+ render: (node: LoweringNode, emit: (e: ParsedExpr) => string): string | null => {
343
+ // `query` guard-list — `queryHref`-shaped.
344
+ if (node.kind === 'guard-list' && node.helper === 'query') {
345
+ const qArgs = queryHrefArgs(node, emit)
346
+ return `bf->query(${qArgs.join(', ')})`
347
+ }
348
+ // Generic `helper-call` (#2069) — a userland `LoweringPlugin`'s
349
+ // single runtime-helper invocation; `bf-><helper>(args…)` mirrors
350
+ // the `query` helper's own naming convention.
351
+ if (node.kind === 'helper-call' && isValidHelperId(node.helper)) {
352
+ return `bf->${node.helper}(${node.args.map(emit).join(', ')})`
353
+ }
354
+ return null
355
+ },
356
+ }
357
+ }
358
+
326
359
  identifier(name: string): string {
327
360
  // `undefined` / `null` nested inside a larger expression tree
328
361
  // (#1897, pagination's `props.isActive ? 'page' : undefined`) — the
@@ -56,8 +56,6 @@ import {
56
56
  lookupStaticRecordLiteral,
57
57
  searchParamsLocalNames,
58
58
  prepareLoweringMatchers,
59
- queryHrefArgs,
60
- isValidHelperId,
61
59
  sortComparatorFromArrow,
62
60
  isLowerableLoopDestructure,
63
61
  isDangerousInnerHtmlAttr,
@@ -404,7 +402,7 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
404
402
  */
405
403
  parseUndefinedAlternateTernary(
406
404
  expr: string,
407
- ): { condition: string; consequent: string } | null {
405
+ ): { condition: string; consequent: string; testParsed: ParsedExpr; consequentParsed: ParsedExpr } | null {
408
406
  const parsed = parseExpression(expr.trim())
409
407
  if (parsed?.kind !== 'conditional') return null
410
408
  const alt = parsed.alternate
@@ -412,13 +410,16 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
412
410
  (alt.kind === 'identifier' && (alt.name === 'undefined' || alt.name === 'null')) ||
413
411
  (alt.kind === 'literal' && (alt.value === null || alt.value === undefined))
414
412
  if (!isUndef) return null
415
- // Serialise the parsed sub-expressions back to JS source rather than
416
- // slicing `expr` text `indexOf('?')` / `lastIndexOf(':')` would
417
- // mis-split when the consequent itself contains `?` / `:` inside a
418
- // string or nested ternary (`cond ? 'a:b' : undefined`).
413
+ // `condition`/`consequent` are DEBUG text only (`exprToString` renders an
414
+ // unsupported nested shape like an object literal as non-reparseable
415
+ // `[UNSUPPORTED: …]` text) callers that need to re-lower the
416
+ // sub-expression must use `testParsed`/`consequentParsed` (the actual
417
+ // parsed trees) as `preParsed`, not re-parse these strings.
419
418
  return {
420
419
  condition: exprToString(parsed.test),
421
420
  consequent: exprToString(parsed.consequent),
421
+ testParsed: parsed.test,
422
+ consequentParsed: parsed.consequent,
422
423
  }
423
424
  }
424
425
 
@@ -1459,8 +1460,8 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
1459
1460
  {
1460
1461
  const m = this.parseUndefinedAlternateTernary(value.expr)
1461
1462
  if (m) {
1462
- const cond = this.convertExpressionToPerl(m.condition)
1463
- const val = this.convertExpressionToPerl(m.consequent)
1463
+ const cond = this.convertExpressionToPerl('', m.testParsed)
1464
+ const val = this.convertExpressionToPerl('', m.consequentParsed)
1464
1465
  return `<% if (${cond}) { %>${name}="<%= ${val} %>"<% } %>`
1465
1466
  }
1466
1467
  }
@@ -1782,7 +1783,7 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
1782
1783
  const hasTaggedTemplate = /[A-Za-z_$][\w$]*\s*`/.test(probe)
1783
1784
  if (!startsAsObjectLiteral && !hasTaggedTemplate) return false
1784
1785
  const parsed = parseExpression(expr.trim())
1785
- const support = isSupported(parsed)
1786
+ const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers })
1786
1787
  if (parsed.kind !== 'unsupported' && support.supported) return false
1787
1788
  // Surface the `isSupported` reason so the diagnostic is as
1788
1789
  // actionable as the Go adapter's BF101 — keeps cross-adapter
@@ -1812,6 +1813,7 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
1812
1813
  private get emitCtx(): MojoEmitContext {
1813
1814
  return {
1814
1815
  _searchParamsLocals: this._searchParamsLocals,
1816
+ _loweringMatchers: this._loweringMatchers,
1815
1817
  resolveModuleStringConst: (name) => this.resolveModuleStringConst(name),
1816
1818
  resolveLiteralConst: (name) => this.resolveLiteralConst(name),
1817
1819
  resolveStaticRecordLiteral: (o, k) => this.resolveStaticRecordLiteral(o, k),
@@ -1868,42 +1870,16 @@ export class MojoAdapter extends BaseAdapter implements IRNodeEmitter<MojoRender
1868
1870
  parsed = parseExpression(trimmed)
1869
1871
  }
1870
1872
 
1871
- // Registered call lowerings (#2057) — including the built-in `queryHref`
1872
- // plugin (#2042), which lowers `queryHref(base, { … })` to a neutral
1873
- // `guard-list` on the `query` helper → `bf->query(base, <triples>)`.
1874
- // Recognised before the support gate because the object-literal arg is
1875
- // otherwise `unsupported` (BF101). The `bf->query` helper includes a pair iff
1876
- // its guard is truthy AND its value is a non-empty string (the client's
1877
- // `if (value)`): a plain `key: v` passes guard `1`, a conditional
1878
- // `key: cond ? v : undefined` passes the lowered cond. Only the `query`
1879
- // helper renders to `bf->query`; another guard-list helper must not be
1880
- // silently mis-rendered as a query.
1881
- if (parsed.kind === 'call') {
1882
- for (const matcher of this._loweringMatchers) {
1883
- const node = matcher(parsed.callee, parsed.args)
1884
- if (node?.kind === 'guard-list' && node.helper === 'query') {
1885
- const argsGo = queryHrefArgs(node, n => this.renderParsedExprToPerl(n))
1886
- return `bf->query(${argsGo.join(', ')})`
1887
- }
1888
- // Generic `helper-call` (#2069) — the neutral vocabulary's escape
1889
- // hatch for a userland `LoweringPlugin` that lowers to a single
1890
- // runtime-helper invocation. `bf-><helper>(args…)` mirrors the
1891
- // `query` helper's own naming convention exactly: the framework
1892
- // renders the call, the plugin author registers `<helper>` as a
1893
- // method on their own Mojolicious `bf` helper object — same
1894
- // contract as `bf->query` itself, just not built in.
1895
- if (node?.kind === 'helper-call' && isValidHelperId(node.helper)) {
1896
- const argsX = node.args.map(a => this.renderParsedExprToPerl(a))
1897
- return `bf->${node.helper}(${argsX.join(', ')})`
1898
- }
1899
- }
1900
- }
1901
-
1902
1873
  // `pos` distinguishes a derived-seed RHS (an assignment, checked via
1903
1874
  // `isSupportedValue`) from every other, genuinely rendered call site —
1904
1875
  // the rendered gate would otherwise re-refuse a tree the seed plan
1905
1876
  // already classified `derived` at value position (#2696 review).
1906
- const support = pos === 'value' ? isSupportedValue(parsed) : isSupported(parsed)
1877
+ // Registered call lowerings (#2057) including the built-in `queryHref`
1878
+ // plugin — are consulted by this gate no matter where the call sits in
1879
+ // the tree (`MojoTopLevelEmitter`'s `lowering` seam does the actual
1880
+ // rendering below, via `emitParsedExpr`'s shared `call` case).
1881
+ const supportOpts = { loweringMatchers: this._loweringMatchers }
1882
+ const support = pos === 'value' ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts)
1907
1883
  if (!support.supported) {
1908
1884
  this.errors.push({
1909
1885
  code: 'BF101',
@@ -10,6 +10,10 @@
10
10
  import type { ConformancePins } from '@barefootjs/jsx'
11
11
 
12
12
  export const conformancePins: ConformancePins = {
13
+ // #2843: graduated — a registered lowering call inside a ternary
14
+ // attribute branch (or any nested value position) is now recognised via
15
+ // `MojoTopLevelEmitter`'s `lowering` seam + the registry-aware support
16
+ // gate, matching the direct-call attribute path exactly.
13
17
  'filter-typeof-predicate': [{ code: 'BF021', severity: 'error' }],
14
18
  'map-array-builder-body': [{ code: 'BF021', severity: 'error' }],
15
19
  'map-array-builder-escaping': [{ code: 'BF021', severity: 'error' }],