@barefootjs/rust 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.
- package/dist/adapter/emit-context.d.ts +11 -1
- package/dist/adapter/emit-context.d.ts.map +1 -1
- package/dist/adapter/expr/emitters.d.ts +11 -1
- package/dist/adapter/expr/emitters.d.ts.map +1 -1
- package/dist/adapter/index.js +27 -21
- package/dist/adapter/minijinja-adapter.d.ts +3 -0
- package/dist/adapter/minijinja-adapter.d.ts.map +1 -1
- package/dist/conformance-pins.d.ts.map +1 -1
- package/dist/index.js +27 -21
- package/dist/vite.js +109 -70
- package/package.json +5 -5
- package/src/adapter/emit-context.ts +12 -1
- package/src/adapter/expr/emitters.ts +33 -0
- package/src/adapter/minijinja-adapter.ts +18 -42
- package/src/conformance-pins.ts +4 -0
|
@@ -19,13 +19,23 @@
|
|
|
19
19
|
* genuinely needs it, so the seam documents the real cross-module coupling
|
|
20
20
|
* rather than re-exposing the whole adapter.
|
|
21
21
|
*/
|
|
22
|
-
import type { ParsedExpr, CompilerError, IRMetadata } from '@barefootjs/jsx';
|
|
22
|
+
import type { ParsedExpr, CompilerError, IRMetadata, LoweringMatcher } from '@barefootjs/jsx';
|
|
23
23
|
export interface JinjaEmitContext {
|
|
24
24
|
/**
|
|
25
25
|
* (#1922) Local binding names the request-scoped `searchParams()` env signal
|
|
26
26
|
* is imported under. Non-empty enables the env-signal method-call lowering.
|
|
27
27
|
*/
|
|
28
28
|
readonly _searchParamsLocals: Set<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Registered lowering-plugin matchers (#2057), bound to this component's
|
|
31
|
+
* metadata at init. Read by `JinjaTopLevelEmitter`'s `lowering` seam
|
|
32
|
+
* (#2843) so a registered call — the built-in `queryHref`, or any
|
|
33
|
+
* userland plugin — is recognised no matter where it sits in an
|
|
34
|
+
* expression tree (a ternary branch, a template-literal interpolation, …),
|
|
35
|
+
* not only when it's the call the adapter's own top-level conversion
|
|
36
|
+
* entry point (`convertExpressionToJinja`) is asked to lower directly.
|
|
37
|
+
*/
|
|
38
|
+
readonly _loweringMatchers: readonly LoweringMatcher[];
|
|
29
39
|
/**
|
|
30
40
|
* Inline a module-scope pure string-literal const by name as the resolved
|
|
31
41
|
* 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;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"emit-context.d.ts","sourceRoot":"","sources":["../../src/adapter/emit-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE7F,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAEzC;;;;;;;;OAQG;IACH,QAAQ,CAAC,iBAAiB,EAAE,SAAS,eAAe,EAAE,CAAA;IAEtD;;;OAGG;IACH,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAEtD,oFAAoF;IACpF,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAEjD;;;OAGG;IACH,2BAA2B,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAE3E,wDAAwD;IACxD,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAExD,yEAAyE;IACzE,4BAA4B,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAA;CACtE;AAED;;;;;GAKG;AACH,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAE9B,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAA;IAEhC,0EAA0E;IAC1E,QAAQ,CAAC,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAA;IAErD,sEAAsE;IACtE,QAAQ,CAAC,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;IAExC;;;;;;;;OAQG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,MAAM,CAAA;IAEtE;;;;;;OAMG;IACH,uBAAuB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,GAAG,MAAM,CAAA;CACtE;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;;;OAMG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,MAAM,CAAA;IAElG;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,CAAA;CACjC"}
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
* unaffected and still used for that path plus the filter-predicate
|
|
48
48
|
* entry point `_renderJinjaFilterExprPublic`.
|
|
49
49
|
*/
|
|
50
|
-
import { type ParsedExprEmitter, type ArrayMethod, type LiteralType, type ParsedExpr, type ObjectLiteralProperty, type FlatDepth, type TemplatePart } from '@barefootjs/jsx';
|
|
50
|
+
import { type ParsedExprEmitter, type ArrayMethod, type LiteralType, type ParsedExpr, type ObjectLiteralProperty, type FlatDepth, type TemplatePart, type LoweringEmitter } from '@barefootjs/jsx';
|
|
51
51
|
import type { JinjaEmitContext } from '../emit-context.ts';
|
|
52
52
|
/**
|
|
53
53
|
* Route a condition-TEST position through `bf.truthy(...)` unless the node
|
|
@@ -110,6 +110,16 @@ export declare class JinjaFilterEmitter implements ParsedExprEmitter {
|
|
|
110
110
|
export declare class JinjaTopLevelEmitter implements ParsedExprEmitter {
|
|
111
111
|
private readonly ctx;
|
|
112
112
|
constructor(ctx: JinjaEmitContext);
|
|
113
|
+
/**
|
|
114
|
+
* Registered-lowering seam (#2843): `emitParsedExpr`'s shared `call` case
|
|
115
|
+
* tries every matcher here BEFORE `call()` itself, so a registered call
|
|
116
|
+
* (the built-in `queryHref`, or any userland plugin) is recognised no
|
|
117
|
+
* matter where it sits in the tree. `render` is what used to live inline
|
|
118
|
+
* in `MinijinjaAdapter.convertExpressionToJinja` before the object-literal
|
|
119
|
+
* support-gate refusal (`checkSupport`'s `call` arm, now itself
|
|
120
|
+
* registry-aware) made the pre-gate special case unnecessary.
|
|
121
|
+
*/
|
|
122
|
+
get lowering(): LoweringEmitter;
|
|
113
123
|
identifier(name: string): string;
|
|
114
124
|
literal(value: string | number | boolean | null, literalType: LiteralType): string;
|
|
115
125
|
member(object: ParsedExpr, property: string, _computed: boolean, _optional: boolean, emit: (e: ParsedExpr) => string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"emitters.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/emitters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,OAAO,EACL,KAAK,iBAAiB,EAEtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,KAAK,YAAY,
|
|
1
|
+
{"version":3,"file":"emitters.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/emitters.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;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ACnB,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,UAAU,EAAE,EAClB,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,CAER;IAED,UAAU,CACR,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,SAAS,GAAG;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,EACvC,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,CAER;IAED,WAAW,CACT,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,UAAU,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,CAwB9E;IAED,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAMlD;IAED,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAG1B;IAED,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;IAED,aAAa,CAAC,UAAU,EAAE,qBAAqB,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAAG,MAAM,CAuCvG;CACF"}
|
package/dist/adapter/index.js
CHANGED
|
@@ -187307,8 +187307,6 @@ import {
|
|
|
187307
187307
|
lookupStaticRecordLiteral,
|
|
187308
187308
|
searchParamsLocalNames,
|
|
187309
187309
|
prepareLoweringMatchers,
|
|
187310
|
-
queryHrefArgs,
|
|
187311
|
-
isValidHelperId,
|
|
187312
187310
|
sortComparatorFromArrow as sortComparatorFromArrow2,
|
|
187313
187311
|
isDangerousInnerHtmlAttr,
|
|
187314
187312
|
resolveDangerousInnerHtml,
|
|
@@ -187677,7 +187675,9 @@ import {
|
|
|
187677
187675
|
groupBinaryOperand,
|
|
187678
187676
|
identifierPath,
|
|
187679
187677
|
matchSearchParamsMethodCall,
|
|
187680
|
-
sortComparatorFromArrow
|
|
187678
|
+
sortComparatorFromArrow,
|
|
187679
|
+
queryHrefArgs,
|
|
187680
|
+
isValidHelperId
|
|
187681
187681
|
} from "@barefootjs/jsx";
|
|
187682
187682
|
var PREDICATE_METHODS = new Set([
|
|
187683
187683
|
"filter",
|
|
@@ -187806,6 +187806,21 @@ class JinjaTopLevelEmitter {
|
|
|
187806
187806
|
constructor(ctx) {
|
|
187807
187807
|
this.ctx = ctx;
|
|
187808
187808
|
}
|
|
187809
|
+
get lowering() {
|
|
187810
|
+
return {
|
|
187811
|
+
matchers: this.ctx._loweringMatchers,
|
|
187812
|
+
render: (node, emit) => {
|
|
187813
|
+
if (node.kind === "guard-list" && node.helper === "query") {
|
|
187814
|
+
const qArgs = queryHrefArgs(node, emit);
|
|
187815
|
+
return `bf.query(${qArgs.join(", ")})`;
|
|
187816
|
+
}
|
|
187817
|
+
if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
187818
|
+
return `bf.${node.helper}(${node.args.map(emit).join(", ")})`;
|
|
187819
|
+
}
|
|
187820
|
+
return null;
|
|
187821
|
+
}
|
|
187822
|
+
};
|
|
187823
|
+
}
|
|
187809
187824
|
identifier(name) {
|
|
187810
187825
|
if (name === "undefined" || name === "null")
|
|
187811
187826
|
return "none";
|
|
@@ -188882,8 +188897,8 @@ ${body}
|
|
|
188882
188897
|
{
|
|
188883
188898
|
const m = this.parseUndefinedAlternateTernary(value.expr);
|
|
188884
188899
|
if (m) {
|
|
188885
|
-
const cond = this.convertConditionToJinja(m.
|
|
188886
|
-
const val = this.convertExpressionToJinja(m.
|
|
188900
|
+
const cond = this.convertConditionToJinja("", m.testParsed);
|
|
188901
|
+
const val = this.convertExpressionToJinja("", m.consequentParsed);
|
|
188887
188902
|
return `
|
|
188888
188903
|
{% if ${cond} %}
|
|
188889
188904
|
${name}="{{ bf.string(${val}) }}"
|
|
@@ -189016,7 +189031,7 @@ ${name}="{{ bf.string(${val}) }}"
|
|
|
189016
189031
|
if (!startsAsObjectLiteral && !hasTaggedTemplate)
|
|
189017
189032
|
return false;
|
|
189018
189033
|
const parsed = parseExpression2(expr.trim());
|
|
189019
|
-
const support = isSupported(parsed);
|
|
189034
|
+
const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
|
|
189020
189035
|
if (parsed.kind !== "unsupported" && support.supported)
|
|
189021
189036
|
return false;
|
|
189022
189037
|
const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
|
|
@@ -189036,6 +189051,7 @@ ${reason}` : "";
|
|
|
189036
189051
|
get emitCtx() {
|
|
189037
189052
|
return {
|
|
189038
189053
|
_searchParamsLocals: this._searchParamsLocals,
|
|
189054
|
+
_loweringMatchers: this._loweringMatchers,
|
|
189039
189055
|
_resolveModuleStringConst: (name) => this._resolveModuleStringConst(name),
|
|
189040
189056
|
_resolveLiteralConst: (name) => this._resolveLiteralConst(name),
|
|
189041
189057
|
_resolveStaticRecordLiteral: (o, k) => this._resolveStaticRecordLiteral(o, k),
|
|
@@ -189069,20 +189085,8 @@ ${reason}` : "";
|
|
|
189069
189085
|
return "''";
|
|
189070
189086
|
parsed = parseExpression2(trimmed);
|
|
189071
189087
|
}
|
|
189072
|
-
|
|
189073
|
-
|
|
189074
|
-
const node = matcher(parsed.callee, parsed.args);
|
|
189075
|
-
if (node?.kind === "guard-list" && node.helper === "query") {
|
|
189076
|
-
const qArgs = queryHrefArgs(node, (n) => this.renderParsedExprToJinja(n));
|
|
189077
|
-
return `bf.query(${qArgs.join(", ")})`;
|
|
189078
|
-
}
|
|
189079
|
-
if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
189080
|
-
const argsX = node.args.map((a) => this.renderParsedExprToJinja(a));
|
|
189081
|
-
return `bf.${node.helper}(${argsX.join(", ")})`;
|
|
189082
|
-
}
|
|
189083
|
-
}
|
|
189084
|
-
}
|
|
189085
|
-
const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
|
|
189088
|
+
const supportOpts = { loweringMatchers: this._loweringMatchers };
|
|
189089
|
+
const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
|
|
189086
189090
|
if (!support.supported) {
|
|
189087
189091
|
this.errors.push({
|
|
189088
189092
|
code: "BF101",
|
|
@@ -189127,7 +189131,9 @@ Options:
|
|
|
189127
189131
|
return null;
|
|
189128
189132
|
return {
|
|
189129
189133
|
condition: exprToString(parsed.test),
|
|
189130
|
-
consequent: exprToString(parsed.consequent)
|
|
189134
|
+
consequent: exprToString(parsed.consequent),
|
|
189135
|
+
testParsed: parsed.test,
|
|
189136
|
+
consequentParsed: parsed.consequent
|
|
189131
189137
|
};
|
|
189132
189138
|
}
|
|
189133
189139
|
isBooleanTypedPropRef(expr) {
|
|
@@ -114,6 +114,7 @@
|
|
|
114
114
|
*/
|
|
115
115
|
import type { ComponentIR, IRNode, IRElement, IRText, IRExpression, IRConditional, IRLoop, IRComponent, IRFragment, IRSlot, IRIfStatement, IRProvider, IRAsync, TemplatePrimitiveRegistry } from '@barefootjs/jsx';
|
|
116
116
|
import { BaseAdapter, type AdapterOutput, type AdapterGenerateOptions, type IRNodeEmitter, type EmitIRNode } from '@barefootjs/jsx';
|
|
117
|
+
import type { ParsedExpr } from '@barefootjs/jsx';
|
|
117
118
|
import type { JinjaRenderCtx } from './lib/types.ts';
|
|
118
119
|
export type { MinijinjaAdapterOptions } from './lib/types.ts';
|
|
119
120
|
import type { MinijinjaAdapterOptions } from './lib/types.ts';
|
|
@@ -421,6 +422,8 @@ export declare class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitt
|
|
|
421
422
|
parseUndefinedAlternateTernary(expr: string): {
|
|
422
423
|
condition: string;
|
|
423
424
|
consequent: string;
|
|
425
|
+
testParsed: ParsedExpr;
|
|
426
|
+
consequentParsed: ParsedExpr;
|
|
424
427
|
} | null;
|
|
425
428
|
isBooleanTypedPropRef(expr: string): boolean;
|
|
426
429
|
/** Position-accurate loop-bound-name check — see `this.scope`'s docstring. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"minijinja-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/minijinja-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;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,EAE1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAClB,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"minijinja-adapter.d.ts","sourceRoot":"","sources":["../../src/adapter/minijinja-adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiHG;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,EAE1B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAE3B,KAAK,aAAa,EAClB,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AEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,eAAO,MAAM,eAAe,EAAE,
|
|
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,eAkE7B,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -187307,8 +187307,6 @@ import {
|
|
|
187307
187307
|
lookupStaticRecordLiteral,
|
|
187308
187308
|
searchParamsLocalNames,
|
|
187309
187309
|
prepareLoweringMatchers,
|
|
187310
|
-
queryHrefArgs,
|
|
187311
|
-
isValidHelperId,
|
|
187312
187310
|
sortComparatorFromArrow as sortComparatorFromArrow2,
|
|
187313
187311
|
isDangerousInnerHtmlAttr,
|
|
187314
187312
|
resolveDangerousInnerHtml,
|
|
@@ -187677,7 +187675,9 @@ import {
|
|
|
187677
187675
|
groupBinaryOperand,
|
|
187678
187676
|
identifierPath,
|
|
187679
187677
|
matchSearchParamsMethodCall,
|
|
187680
|
-
sortComparatorFromArrow
|
|
187678
|
+
sortComparatorFromArrow,
|
|
187679
|
+
queryHrefArgs,
|
|
187680
|
+
isValidHelperId
|
|
187681
187681
|
} from "@barefootjs/jsx";
|
|
187682
187682
|
var PREDICATE_METHODS = new Set([
|
|
187683
187683
|
"filter",
|
|
@@ -187806,6 +187806,21 @@ class JinjaTopLevelEmitter {
|
|
|
187806
187806
|
constructor(ctx) {
|
|
187807
187807
|
this.ctx = ctx;
|
|
187808
187808
|
}
|
|
187809
|
+
get lowering() {
|
|
187810
|
+
return {
|
|
187811
|
+
matchers: this.ctx._loweringMatchers,
|
|
187812
|
+
render: (node, emit) => {
|
|
187813
|
+
if (node.kind === "guard-list" && node.helper === "query") {
|
|
187814
|
+
const qArgs = queryHrefArgs(node, emit);
|
|
187815
|
+
return `bf.query(${qArgs.join(", ")})`;
|
|
187816
|
+
}
|
|
187817
|
+
if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
187818
|
+
return `bf.${node.helper}(${node.args.map(emit).join(", ")})`;
|
|
187819
|
+
}
|
|
187820
|
+
return null;
|
|
187821
|
+
}
|
|
187822
|
+
};
|
|
187823
|
+
}
|
|
187809
187824
|
identifier(name) {
|
|
187810
187825
|
if (name === "undefined" || name === "null")
|
|
187811
187826
|
return "none";
|
|
@@ -188882,8 +188897,8 @@ ${body}
|
|
|
188882
188897
|
{
|
|
188883
188898
|
const m = this.parseUndefinedAlternateTernary(value.expr);
|
|
188884
188899
|
if (m) {
|
|
188885
|
-
const cond = this.convertConditionToJinja(m.
|
|
188886
|
-
const val = this.convertExpressionToJinja(m.
|
|
188900
|
+
const cond = this.convertConditionToJinja("", m.testParsed);
|
|
188901
|
+
const val = this.convertExpressionToJinja("", m.consequentParsed);
|
|
188887
188902
|
return `
|
|
188888
188903
|
{% if ${cond} %}
|
|
188889
188904
|
${name}="{{ bf.string(${val}) }}"
|
|
@@ -189016,7 +189031,7 @@ ${name}="{{ bf.string(${val}) }}"
|
|
|
189016
189031
|
if (!startsAsObjectLiteral && !hasTaggedTemplate)
|
|
189017
189032
|
return false;
|
|
189018
189033
|
const parsed = parseExpression2(expr.trim());
|
|
189019
|
-
const support = isSupported(parsed);
|
|
189034
|
+
const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
|
|
189020
189035
|
if (parsed.kind !== "unsupported" && support.supported)
|
|
189021
189036
|
return false;
|
|
189022
189037
|
const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
|
|
@@ -189036,6 +189051,7 @@ ${reason}` : "";
|
|
|
189036
189051
|
get emitCtx() {
|
|
189037
189052
|
return {
|
|
189038
189053
|
_searchParamsLocals: this._searchParamsLocals,
|
|
189054
|
+
_loweringMatchers: this._loweringMatchers,
|
|
189039
189055
|
_resolveModuleStringConst: (name) => this._resolveModuleStringConst(name),
|
|
189040
189056
|
_resolveLiteralConst: (name) => this._resolveLiteralConst(name),
|
|
189041
189057
|
_resolveStaticRecordLiteral: (o, k) => this._resolveStaticRecordLiteral(o, k),
|
|
@@ -189069,20 +189085,8 @@ ${reason}` : "";
|
|
|
189069
189085
|
return "''";
|
|
189070
189086
|
parsed = parseExpression2(trimmed);
|
|
189071
189087
|
}
|
|
189072
|
-
|
|
189073
|
-
|
|
189074
|
-
const node = matcher(parsed.callee, parsed.args);
|
|
189075
|
-
if (node?.kind === "guard-list" && node.helper === "query") {
|
|
189076
|
-
const qArgs = queryHrefArgs(node, (n) => this.renderParsedExprToJinja(n));
|
|
189077
|
-
return `bf.query(${qArgs.join(", ")})`;
|
|
189078
|
-
}
|
|
189079
|
-
if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
189080
|
-
const argsX = node.args.map((a) => this.renderParsedExprToJinja(a));
|
|
189081
|
-
return `bf.${node.helper}(${argsX.join(", ")})`;
|
|
189082
|
-
}
|
|
189083
|
-
}
|
|
189084
|
-
}
|
|
189085
|
-
const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
|
|
189088
|
+
const supportOpts = { loweringMatchers: this._loweringMatchers };
|
|
189089
|
+
const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
|
|
189086
189090
|
if (!support.supported) {
|
|
189087
189091
|
this.errors.push({
|
|
189088
189092
|
code: "BF101",
|
|
@@ -189127,7 +189131,9 @@ Options:
|
|
|
189127
189131
|
return null;
|
|
189128
189132
|
return {
|
|
189129
189133
|
condition: exprToString(parsed.test),
|
|
189130
|
-
consequent: exprToString(parsed.consequent)
|
|
189134
|
+
consequent: exprToString(parsed.consequent),
|
|
189135
|
+
testParsed: parsed.test,
|
|
189136
|
+
consequentParsed: parsed.consequent
|
|
189131
189137
|
};
|
|
189132
189138
|
}
|
|
189133
189139
|
isBooleanTypedPropRef(expr) {
|
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
|
}
|
|
@@ -3225,30 +3271,6 @@ import ts16 from "typescript";
|
|
|
3225
3271
|
|
|
3226
3272
|
// ../jsx/src/relocate.ts
|
|
3227
3273
|
import ts18 from "typescript";
|
|
3228
|
-
|
|
3229
|
-
// ../jsx/src/lowering-registry.ts
|
|
3230
|
-
var plugins = [];
|
|
3231
|
-
function registerLoweringPlugin(plugin) {
|
|
3232
|
-
const existing = plugins.findIndex((p) => p.name === plugin.name);
|
|
3233
|
-
if (existing >= 0)
|
|
3234
|
-
plugins[existing] = plugin;
|
|
3235
|
-
else
|
|
3236
|
-
plugins.push(plugin);
|
|
3237
|
-
}
|
|
3238
|
-
function prepareLoweringMatchers(metadata) {
|
|
3239
|
-
const matchers = [];
|
|
3240
|
-
for (const plugin of plugins) {
|
|
3241
|
-
const matcher = plugin.prepare(metadata);
|
|
3242
|
-
if (matcher)
|
|
3243
|
-
matchers.push(matcher);
|
|
3244
|
-
}
|
|
3245
|
-
return matchers;
|
|
3246
|
-
}
|
|
3247
|
-
function isValidHelperId(helper) {
|
|
3248
|
-
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(helper);
|
|
3249
|
-
}
|
|
3250
|
-
|
|
3251
|
-
// ../jsx/src/relocate.ts
|
|
3252
3274
|
var REGISTRY_SAFE_BINDING_KINDS = new Set([
|
|
3253
3275
|
"global",
|
|
3254
3276
|
"module-import",
|
|
@@ -4695,6 +4717,17 @@ function emitParsedExpr(expr, emitter) {
|
|
|
4695
4717
|
case "literal":
|
|
4696
4718
|
return emitter.literal(expr.value, expr.literalType);
|
|
4697
4719
|
case "call": {
|
|
4720
|
+
if (emitter.lowering) {
|
|
4721
|
+
for (const matcher of emitter.lowering.matchers) {
|
|
4722
|
+
const node = matcher(expr.callee, expr.args);
|
|
4723
|
+
if (!node)
|
|
4724
|
+
continue;
|
|
4725
|
+
const rendered = emitter.lowering.render(node, emit);
|
|
4726
|
+
if (rendered !== null)
|
|
4727
|
+
return rendered;
|
|
4728
|
+
break;
|
|
4729
|
+
}
|
|
4730
|
+
}
|
|
4698
4731
|
const cb = asCallbackMethodCall(expr);
|
|
4699
4732
|
if (cb)
|
|
4700
4733
|
return emitter.callbackMethod(cb.method, cb.object, cb.arrow, cb.args, emit);
|
|
@@ -5690,6 +5723,21 @@ class JinjaTopLevelEmitter {
|
|
|
5690
5723
|
constructor(ctx) {
|
|
5691
5724
|
this.ctx = ctx;
|
|
5692
5725
|
}
|
|
5726
|
+
get lowering() {
|
|
5727
|
+
return {
|
|
5728
|
+
matchers: this.ctx._loweringMatchers,
|
|
5729
|
+
render: (node, emit) => {
|
|
5730
|
+
if (node.kind === "guard-list" && node.helper === "query") {
|
|
5731
|
+
const qArgs = queryHrefArgs(node, emit);
|
|
5732
|
+
return `bf.query(${qArgs.join(", ")})`;
|
|
5733
|
+
}
|
|
5734
|
+
if (node.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
5735
|
+
return `bf.${node.helper}(${node.args.map(emit).join(", ")})`;
|
|
5736
|
+
}
|
|
5737
|
+
return null;
|
|
5738
|
+
}
|
|
5739
|
+
};
|
|
5740
|
+
}
|
|
5693
5741
|
identifier(name) {
|
|
5694
5742
|
if (name === "undefined" || name === "null")
|
|
5695
5743
|
return "none";
|
|
@@ -6757,8 +6805,8 @@ ${body}
|
|
|
6757
6805
|
{
|
|
6758
6806
|
const m = this.parseUndefinedAlternateTernary(value.expr);
|
|
6759
6807
|
if (m) {
|
|
6760
|
-
const cond = this.convertConditionToJinja(m.
|
|
6761
|
-
const val = this.convertExpressionToJinja(m.
|
|
6808
|
+
const cond = this.convertConditionToJinja("", m.testParsed);
|
|
6809
|
+
const val = this.convertExpressionToJinja("", m.consequentParsed);
|
|
6762
6810
|
return `
|
|
6763
6811
|
{% if ${cond} %}
|
|
6764
6812
|
${name}="{{ bf.string(${val}) }}"
|
|
@@ -6891,7 +6939,7 @@ ${name}="{{ bf.string(${val}) }}"
|
|
|
6891
6939
|
if (!startsAsObjectLiteral && !hasTaggedTemplate)
|
|
6892
6940
|
return false;
|
|
6893
6941
|
const parsed = parseExpression(expr.trim());
|
|
6894
|
-
const support = isSupported(parsed);
|
|
6942
|
+
const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers });
|
|
6895
6943
|
if (parsed.kind !== "unsupported" && support.supported)
|
|
6896
6944
|
return false;
|
|
6897
6945
|
const reason = support.reason ?? (parsed.kind === "unsupported" ? parsed.reason : undefined);
|
|
@@ -6911,6 +6959,7 @@ ${reason}` : "";
|
|
|
6911
6959
|
get emitCtx() {
|
|
6912
6960
|
return {
|
|
6913
6961
|
_searchParamsLocals: this._searchParamsLocals,
|
|
6962
|
+
_loweringMatchers: this._loweringMatchers,
|
|
6914
6963
|
_resolveModuleStringConst: (name) => this._resolveModuleStringConst(name),
|
|
6915
6964
|
_resolveLiteralConst: (name) => this._resolveLiteralConst(name),
|
|
6916
6965
|
_resolveStaticRecordLiteral: (o, k) => this._resolveStaticRecordLiteral(o, k),
|
|
@@ -6944,20 +6993,8 @@ ${reason}` : "";
|
|
|
6944
6993
|
return "''";
|
|
6945
6994
|
parsed = parseExpression(trimmed);
|
|
6946
6995
|
}
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
const node = matcher(parsed.callee, parsed.args);
|
|
6950
|
-
if (node?.kind === "guard-list" && node.helper === "query") {
|
|
6951
|
-
const qArgs = queryHrefArgs(node, (n) => this.renderParsedExprToJinja(n));
|
|
6952
|
-
return `bf.query(${qArgs.join(", ")})`;
|
|
6953
|
-
}
|
|
6954
|
-
if (node?.kind === "helper-call" && isValidHelperId(node.helper)) {
|
|
6955
|
-
const argsX = node.args.map((a) => this.renderParsedExprToJinja(a));
|
|
6956
|
-
return `bf.${node.helper}(${argsX.join(", ")})`;
|
|
6957
|
-
}
|
|
6958
|
-
}
|
|
6959
|
-
}
|
|
6960
|
-
const support = pos === "value" ? isSupportedValue(parsed) : isSupported(parsed);
|
|
6996
|
+
const supportOpts = { loweringMatchers: this._loweringMatchers };
|
|
6997
|
+
const support = pos === "value" ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts);
|
|
6961
6998
|
if (!support.supported) {
|
|
6962
6999
|
this.errors.push({
|
|
6963
7000
|
code: "BF101",
|
|
@@ -7002,7 +7039,9 @@ Options:
|
|
|
7002
7039
|
return null;
|
|
7003
7040
|
return {
|
|
7004
7041
|
condition: exprToString(parsed.test),
|
|
7005
|
-
consequent: exprToString(parsed.consequent)
|
|
7042
|
+
consequent: exprToString(parsed.consequent),
|
|
7043
|
+
testParsed: parsed.test,
|
|
7044
|
+
consequentParsed: parsed.consequent
|
|
7006
7045
|
};
|
|
7007
7046
|
}
|
|
7008
7047
|
isBooleanTypedPropRef(expr) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/rust",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.34.0",
|
|
4
4
|
"description": "minijinja (Rust) adapter for BarefootJS — compiles IR to .j2 templates and ships a Rust rendering runtime (packages/adapter-rust/runtime/); runs under any Rust web framework (axum, etc.)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"directory": "packages/adapter-rust"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@barefootjs/shared": "0.
|
|
57
|
+
"@barefootjs/shared": "0.34.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
60
60
|
"@barefootjs/jsx": ">=0.2.0",
|
|
@@ -71,9 +71,9 @@
|
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@barefootjs/adapter-tests": "0.1.0",
|
|
74
|
-
"@barefootjs/jsx": "0.
|
|
75
|
-
"@barefootjs/vite": "0.
|
|
76
|
-
"@barefootjs/client": "0.
|
|
74
|
+
"@barefootjs/jsx": "0.34.0",
|
|
75
|
+
"@barefootjs/vite": "0.34.0",
|
|
76
|
+
"@barefootjs/client": "0.34.0",
|
|
77
77
|
"typescript": "^5.0.0",
|
|
78
78
|
"vite": "^6.0.0"
|
|
79
79
|
}
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* rather than re-exposing the whole adapter.
|
|
21
21
|
*/
|
|
22
22
|
|
|
23
|
-
import type { ParsedExpr, CompilerError, IRMetadata } from '@barefootjs/jsx'
|
|
23
|
+
import type { ParsedExpr, CompilerError, IRMetadata, LoweringMatcher } from '@barefootjs/jsx'
|
|
24
24
|
|
|
25
25
|
export interface JinjaEmitContext {
|
|
26
26
|
/**
|
|
@@ -29,6 +29,17 @@ export interface JinjaEmitContext {
|
|
|
29
29
|
*/
|
|
30
30
|
readonly _searchParamsLocals: Set<string>
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Registered lowering-plugin matchers (#2057), bound to this component's
|
|
34
|
+
* metadata at init. Read by `JinjaTopLevelEmitter`'s `lowering` seam
|
|
35
|
+
* (#2843) so a registered call — the built-in `queryHref`, or any
|
|
36
|
+
* userland plugin — is recognised no matter where it sits in an
|
|
37
|
+
* expression tree (a ternary branch, a template-literal interpolation, …),
|
|
38
|
+
* not only when it's the call the adapter's own top-level conversion
|
|
39
|
+
* entry point (`convertExpressionToJinja`) is asked to lower directly.
|
|
40
|
+
*/
|
|
41
|
+
readonly _loweringMatchers: readonly LoweringMatcher[]
|
|
42
|
+
|
|
32
43
|
/**
|
|
33
44
|
* Inline a module-scope pure string-literal const by name as the resolved
|
|
34
45
|
* literal value, or null when the name is not such a const.
|
|
@@ -60,6 +60,10 @@ import { groupBinaryOperand,
|
|
|
60
60
|
identifierPath,
|
|
61
61
|
matchSearchParamsMethodCall,
|
|
62
62
|
sortComparatorFromArrow,
|
|
63
|
+
type LoweringEmitter,
|
|
64
|
+
type LoweringNode,
|
|
65
|
+
queryHrefArgs,
|
|
66
|
+
isValidHelperId,
|
|
63
67
|
} from '@barefootjs/jsx'
|
|
64
68
|
|
|
65
69
|
import type { JinjaEmitContext } from '../emit-context.ts'
|
|
@@ -314,6 +318,35 @@ export class JinjaTopLevelEmitter implements ParsedExprEmitter {
|
|
|
314
318
|
this.ctx = ctx
|
|
315
319
|
}
|
|
316
320
|
|
|
321
|
+
/**
|
|
322
|
+
* Registered-lowering seam (#2843): `emitParsedExpr`'s shared `call` case
|
|
323
|
+
* tries every matcher here BEFORE `call()` itself, so a registered call
|
|
324
|
+
* (the built-in `queryHref`, or any userland plugin) is recognised no
|
|
325
|
+
* matter where it sits in the tree. `render` is what used to live inline
|
|
326
|
+
* in `MinijinjaAdapter.convertExpressionToJinja` before the object-literal
|
|
327
|
+
* support-gate refusal (`checkSupport`'s `call` arm, now itself
|
|
328
|
+
* registry-aware) made the pre-gate special case unnecessary.
|
|
329
|
+
*/
|
|
330
|
+
get lowering(): LoweringEmitter {
|
|
331
|
+
return {
|
|
332
|
+
matchers: this.ctx._loweringMatchers,
|
|
333
|
+
render: (node: LoweringNode, emit: (e: ParsedExpr) => string): string | null => {
|
|
334
|
+
// `query` guard-list — `queryHref`-shaped.
|
|
335
|
+
if (node.kind === 'guard-list' && node.helper === 'query') {
|
|
336
|
+
const qArgs = queryHrefArgs(node, emit)
|
|
337
|
+
return `bf.query(${qArgs.join(', ')})`
|
|
338
|
+
}
|
|
339
|
+
// Generic `helper-call` (#2069) — a userland `LoweringPlugin`'s
|
|
340
|
+
// single runtime-helper invocation; `bf.<helper>(args…)` mirrors
|
|
341
|
+
// the `query` helper's own naming convention.
|
|
342
|
+
if (node.kind === 'helper-call' && isValidHelperId(node.helper)) {
|
|
343
|
+
return `bf.${node.helper}(${node.args.map(emit).join(', ')})`
|
|
344
|
+
}
|
|
345
|
+
return null
|
|
346
|
+
},
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
317
350
|
identifier(name: string): string {
|
|
318
351
|
// `undefined` / `null` nested inside a larger expression tree — Jinja
|
|
319
352
|
// `none` (#1897).
|
|
@@ -163,8 +163,6 @@ import {
|
|
|
163
163
|
lookupStaticRecordLiteral,
|
|
164
164
|
searchParamsLocalNames,
|
|
165
165
|
prepareLoweringMatchers,
|
|
166
|
-
queryHrefArgs,
|
|
167
|
-
isValidHelperId,
|
|
168
166
|
sortComparatorFromArrow,
|
|
169
167
|
isDangerousInnerHtmlAttr,
|
|
170
168
|
resolveDangerousInnerHtml,
|
|
@@ -1482,8 +1480,8 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1482
1480
|
{
|
|
1483
1481
|
const m = this.parseUndefinedAlternateTernary(value.expr)
|
|
1484
1482
|
if (m) {
|
|
1485
|
-
const cond = this.convertConditionToJinja(m.
|
|
1486
|
-
const val = this.convertExpressionToJinja(m.
|
|
1483
|
+
const cond = this.convertConditionToJinja('', m.testParsed)
|
|
1484
|
+
const val = this.convertExpressionToJinja('', m.consequentParsed)
|
|
1487
1485
|
return `\n{% if ${cond} %}\n${name}="{{ bf.string(${val}) }}"\n{% endif %}\n`
|
|
1488
1486
|
}
|
|
1489
1487
|
}
|
|
@@ -1751,7 +1749,7 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1751
1749
|
const hasTaggedTemplate = /[A-Za-z_$][\w$]*\s*`/.test(probe)
|
|
1752
1750
|
if (!startsAsObjectLiteral && !hasTaggedTemplate) return false
|
|
1753
1751
|
const parsed = parseExpression(expr.trim())
|
|
1754
|
-
const support = isSupported(parsed)
|
|
1752
|
+
const support = isSupported(parsed, { loweringMatchers: this._loweringMatchers })
|
|
1755
1753
|
if (parsed.kind !== 'unsupported' && support.supported) return false
|
|
1756
1754
|
const reason = support.reason ?? (parsed.kind === 'unsupported' ? parsed.reason : undefined)
|
|
1757
1755
|
const reasonLine = reason ? `\n${reason}` : ''
|
|
@@ -1778,6 +1776,7 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1778
1776
|
private get emitCtx(): JinjaEmitContext {
|
|
1779
1777
|
return {
|
|
1780
1778
|
_searchParamsLocals: this._searchParamsLocals,
|
|
1779
|
+
_loweringMatchers: this._loweringMatchers,
|
|
1781
1780
|
_resolveModuleStringConst: (name) => this._resolveModuleStringConst(name),
|
|
1782
1781
|
_resolveLiteralConst: (name) => this._resolveLiteralConst(name),
|
|
1783
1782
|
_resolveStaticRecordLiteral: (o, k) => this._resolveStaticRecordLiteral(o, k),
|
|
@@ -1832,42 +1831,16 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1832
1831
|
parsed = parseExpression(trimmed)
|
|
1833
1832
|
}
|
|
1834
1833
|
|
|
1835
|
-
// Registered call lowerings (#2057) — including the built-in `queryHref`
|
|
1836
|
-
// plugin (#2042), which lowers `queryHref(base, { … })` to a neutral
|
|
1837
|
-
// `guard-list` on the `query` helper → `bf.query(base, <triples>)`.
|
|
1838
|
-
// Recognised before the support gate because the object-literal arg is
|
|
1839
|
-
// otherwise `unsupported` (BF101). The `query` helper includes a pair iff its
|
|
1840
|
-
// guard is truthy AND its value is a non-empty string (the client's
|
|
1841
|
-
// `if (value)`): a plain `key: v` passes guard `true`, a conditional
|
|
1842
|
-
// `key: cond ? v : undefined` passes the lowered cond. Only the `query`
|
|
1843
|
-
// helper renders to `bf.query`; another guard-list helper must not be
|
|
1844
|
-
// silently mis-rendered as a query.
|
|
1845
|
-
if (parsed.kind === 'call') {
|
|
1846
|
-
for (const matcher of this._loweringMatchers) {
|
|
1847
|
-
const node = matcher(parsed.callee, parsed.args)
|
|
1848
|
-
if (node?.kind === 'guard-list' && node.helper === 'query') {
|
|
1849
|
-
const qArgs = queryHrefArgs(node, n => this.renderParsedExprToJinja(n))
|
|
1850
|
-
return `bf.query(${qArgs.join(', ')})`
|
|
1851
|
-
}
|
|
1852
|
-
// Generic `helper-call` (#2069) — the neutral vocabulary's escape
|
|
1853
|
-
// hatch for a userland `LoweringPlugin` that lowers to a single
|
|
1854
|
-
// runtime-helper invocation. `bf.<helper>(args…)` mirrors the
|
|
1855
|
-
// `query` helper's own naming convention exactly: the framework
|
|
1856
|
-
// renders the call, the plugin author registers `<helper>` as a
|
|
1857
|
-
// MiniJinja-callable function in their own runtime — same contract
|
|
1858
|
-
// as `bf.query` itself, just not built in.
|
|
1859
|
-
if (node?.kind === 'helper-call' && isValidHelperId(node.helper)) {
|
|
1860
|
-
const argsX = node.args.map(a => this.renderParsedExprToJinja(a))
|
|
1861
|
-
return `bf.${node.helper}(${argsX.join(', ')})`
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}
|
|
1865
|
-
|
|
1866
1834
|
// `pos` distinguishes a derived-seed RHS (an assignment, checked via
|
|
1867
1835
|
// `isSupportedValue`) from every other, genuinely rendered call site —
|
|
1868
1836
|
// the rendered gate would otherwise re-refuse a tree the seed plan
|
|
1869
1837
|
// already classified `derived` at value position (#2696 review).
|
|
1870
|
-
|
|
1838
|
+
// Registered call lowerings (#2057) — including the built-in `queryHref`
|
|
1839
|
+
// plugin — are consulted by this gate no matter where the call sits in
|
|
1840
|
+
// the tree (`JinjaTopLevelEmitter`'s `lowering` seam does the actual
|
|
1841
|
+
// rendering below, via `emitParsedExpr`'s shared `call` case).
|
|
1842
|
+
const supportOpts = { loweringMatchers: this._loweringMatchers }
|
|
1843
|
+
const support = pos === 'value' ? isSupportedValue(parsed, supportOpts) : isSupported(parsed, supportOpts)
|
|
1871
1844
|
if (!support.supported) {
|
|
1872
1845
|
this.errors.push({
|
|
1873
1846
|
code: 'BF101',
|
|
@@ -1936,7 +1909,7 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1936
1909
|
*/
|
|
1937
1910
|
parseUndefinedAlternateTernary(
|
|
1938
1911
|
expr: string,
|
|
1939
|
-
): { condition: string; consequent: string } | null {
|
|
1912
|
+
): { condition: string; consequent: string; testParsed: ParsedExpr; consequentParsed: ParsedExpr } | null {
|
|
1940
1913
|
const parsed = parseExpression(expr.trim())
|
|
1941
1914
|
if (parsed?.kind !== 'conditional') return null
|
|
1942
1915
|
const alt = parsed.alternate
|
|
@@ -1944,13 +1917,16 @@ export class MinijinjaAdapter extends BaseAdapter implements IRNodeEmitter<Jinja
|
|
|
1944
1917
|
(alt.kind === 'identifier' && (alt.name === 'undefined' || alt.name === 'null')) ||
|
|
1945
1918
|
(alt.kind === 'literal' && (alt.value === null || alt.value === undefined))
|
|
1946
1919
|
if (!isUndef) return null
|
|
1947
|
-
//
|
|
1948
|
-
//
|
|
1949
|
-
//
|
|
1950
|
-
//
|
|
1920
|
+
// `condition`/`consequent` are DEBUG text only (`exprToString` renders an
|
|
1921
|
+
// unsupported nested shape like an object literal as non-reparseable
|
|
1922
|
+
// `[UNSUPPORTED: …]` text) — callers that need to re-lower the
|
|
1923
|
+
// sub-expression must use `testParsed`/`consequentParsed` (the actual
|
|
1924
|
+
// parsed trees) as `preParsed`, not re-parse these strings.
|
|
1951
1925
|
return {
|
|
1952
1926
|
condition: exprToString(parsed.test),
|
|
1953
1927
|
consequent: exprToString(parsed.consequent),
|
|
1928
|
+
testParsed: parsed.test,
|
|
1929
|
+
consequentParsed: parsed.consequent,
|
|
1954
1930
|
}
|
|
1955
1931
|
}
|
|
1956
1932
|
|
package/src/conformance-pins.ts
CHANGED
|
@@ -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
|
+
// `JinjaTopLevelEmitter`'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' }],
|