@barefootjs/go-template 0.15.2 → 0.17.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/analysis/component-tree.d.ts +23 -0
- package/dist/adapter/analysis/component-tree.d.ts.map +1 -0
- package/dist/adapter/emit-context.d.ts +53 -0
- package/dist/adapter/emit-context.d.ts.map +1 -0
- package/dist/adapter/expr/helper-inline.d.ts +31 -0
- package/dist/adapter/expr/helper-inline.d.ts.map +1 -0
- package/dist/adapter/expr/url-builder.d.ts +23 -0
- package/dist/adapter/expr/url-builder.d.ts.map +1 -0
- package/dist/adapter/go-template-adapter.d.ts +291 -1070
- package/dist/adapter/go-template-adapter.d.ts.map +1 -1
- package/dist/adapter/index.js +2859 -2618
- package/dist/adapter/lib/compile-state.d.ts +116 -0
- package/dist/adapter/lib/compile-state.d.ts.map +1 -0
- package/dist/adapter/lib/constants.d.ts +11 -0
- package/dist/adapter/lib/constants.d.ts.map +1 -0
- package/dist/adapter/lib/go-emit.d.ts +117 -0
- package/dist/adapter/lib/go-emit.d.ts.map +1 -0
- package/dist/adapter/lib/go-naming.d.ts +39 -0
- package/dist/adapter/lib/go-naming.d.ts.map +1 -0
- package/dist/adapter/lib/ir-scope.d.ts +13 -0
- package/dist/adapter/lib/ir-scope.d.ts.map +1 -0
- package/dist/adapter/lib/types.d.ts +165 -0
- package/dist/adapter/lib/types.d.ts.map +1 -0
- package/dist/adapter/memo/ctor-lowering.d.ts +39 -0
- package/dist/adapter/memo/ctor-lowering.d.ts.map +1 -0
- package/dist/adapter/memo/memo-compute.d.ts +124 -0
- package/dist/adapter/memo/memo-compute.d.ts.map +1 -0
- package/dist/adapter/memo/memo-type.d.ts +38 -0
- package/dist/adapter/memo/memo-type.d.ts.map +1 -0
- package/dist/adapter/memo/memo-value.d.ts +64 -0
- package/dist/adapter/memo/memo-value.d.ts.map +1 -0
- package/dist/adapter/memo/template-interp.d.ts +43 -0
- package/dist/adapter/memo/template-interp.d.ts.map +1 -0
- package/dist/adapter/props/prop-types.d.ts +31 -0
- package/dist/adapter/props/prop-types.d.ts.map +1 -0
- package/dist/adapter/spread/spread-codegen.d.ts +40 -0
- package/dist/adapter/spread/spread-codegen.d.ts.map +1 -0
- package/dist/adapter/type/type-codegen.d.ts +25 -0
- package/dist/adapter/type/type-codegen.d.ts.map +1 -0
- package/dist/adapter/value/parsed-literal-to-go.d.ts +17 -0
- package/dist/adapter/value/parsed-literal-to-go.d.ts.map +1 -0
- package/dist/adapter/value/value-lowering.d.ts +46 -0
- package/dist/adapter/value/value-lowering.d.ts.map +1 -0
- package/dist/build.js +2857 -2616
- package/dist/index.js +2859 -2618
- package/dist/test-render.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/derived-state-memo.test.ts +155 -84
- package/src/__tests__/go-template-adapter.test.ts +211 -60
- package/src/__tests__/lowering-plugin.test.ts +109 -0
- package/src/__tests__/query-href.test.ts +179 -0
- package/src/adapter/analysis/component-tree.ts +174 -0
- package/src/adapter/emit-context.ts +59 -0
- package/src/adapter/expr/helper-inline.ts +274 -0
- package/src/adapter/expr/url-builder.ts +123 -0
- package/src/adapter/go-template-adapter.ts +2100 -5316
- package/src/adapter/lib/compile-state.ts +150 -0
- package/src/adapter/lib/constants.ts +24 -0
- package/src/adapter/lib/go-emit.ts +289 -0
- package/src/adapter/lib/go-naming.ts +84 -0
- package/src/adapter/lib/ir-scope.ts +31 -0
- package/src/adapter/lib/types.ts +182 -0
- package/src/adapter/memo/ctor-lowering.ts +267 -0
- package/src/adapter/memo/memo-compute.ts +451 -0
- package/src/adapter/memo/memo-type.ts +74 -0
- package/src/adapter/memo/memo-value.ts +197 -0
- package/src/adapter/memo/template-interp.ts +246 -0
- package/src/adapter/props/prop-types.ts +84 -0
- package/src/adapter/spread/spread-codegen.ts +458 -0
- package/src/adapter/type/type-codegen.ts +95 -0
- package/src/adapter/value/parsed-literal-to-go.ts +94 -0
- package/src/adapter/value/value-lowering.ts +162 -0
- package/src/test-render.ts +2 -14
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IR component-tree analysis for the Go html/template adapter.
|
|
3
|
+
*
|
|
4
|
+
* Pure structural walks over the IR — no adapter instance state, no rendering.
|
|
5
|
+
* Only the two entry points (`hasClientInteractivity`,
|
|
6
|
+
* `findNestedComponents`) are exported; the recursive collectors stay
|
|
7
|
+
* module-internal.
|
|
8
|
+
*/
|
|
9
|
+
import type { ComponentIR, IRNode } from '@barefootjs/jsx';
|
|
10
|
+
import type { NestedComponentInfo } from '../lib/types.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Does the component need client JS? True when it has reactive state
|
|
13
|
+
* (signals), effects, onMounts, any event handler in the tree, or any
|
|
14
|
+
* child component (which needs the parent's hydration).
|
|
15
|
+
*/
|
|
16
|
+
export declare function hasClientInteractivity(ir: ComponentIR): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Find all nested components (loops with `childComponent`). Returns extended
|
|
19
|
+
* info that includes whether the component comes from a dynamic (signal) array
|
|
20
|
+
* loop vs a static one.
|
|
21
|
+
*/
|
|
22
|
+
export declare function findNestedComponents(node: IRNode): NestedComponentInfo[];
|
|
23
|
+
//# sourceMappingURL=component-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-tree.d.ts","sourceRoot":"","sources":["../../../src/adapter/analysis/component-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EAOP,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAE1D;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,WAAW,GAAG,OAAO,CAQ/D;AAyED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,EAAE,CAIxE"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract extracted emit modules depend on instead of the concrete
|
|
3
|
+
* `GoTemplateAdapter`.
|
|
4
|
+
*
|
|
5
|
+
* The Go adapter's lowering is deeply mutually recursive (expression ↔
|
|
6
|
+
* condition ↔ rendering), so a module pulled out still needs to call back into
|
|
7
|
+
* the shared per-compile state and the recursive entry points. `GoEmitContext`
|
|
8
|
+
* is that seam: extracted free functions take it as their first argument, and
|
|
9
|
+
* the adapter — which owns the state and implements the entry points — passes
|
|
10
|
+
* `this`. Modules depend on this narrow interface, so they stay unit-testable
|
|
11
|
+
* against a stub.
|
|
12
|
+
*
|
|
13
|
+
* Keep this surface minimal: add a member only when an extracted module
|
|
14
|
+
* genuinely needs it, so the seam documents the real cross-module coupling.
|
|
15
|
+
*/
|
|
16
|
+
import type { ParsedExpr } from '@barefootjs/jsx';
|
|
17
|
+
import type { CompileState } from './lib/compile-state.ts';
|
|
18
|
+
export interface GoEmitContext {
|
|
19
|
+
/** Per-compile mutable state (signals, consts, type tables, errors, …). */
|
|
20
|
+
readonly state: CompileState;
|
|
21
|
+
/**
|
|
22
|
+
* Lower a JS expression to its Go-template form (the core recursive entry).
|
|
23
|
+
* `preParsed` reuses an already-built tree instead of re-parsing `jsExpr`.
|
|
24
|
+
*/
|
|
25
|
+
convertExpressionToGo(jsExpr: string, out?: {
|
|
26
|
+
parsed?: ParsedExpr;
|
|
27
|
+
}, preParsed?: ParsedExpr): string;
|
|
28
|
+
/**
|
|
29
|
+
* Lower a JS condition to a Go-template bool + any hoisted preamble.
|
|
30
|
+
* `preParsed` reuses an already-built tree instead of re-parsing `jsCondition`.
|
|
31
|
+
*/
|
|
32
|
+
convertConditionToGo(jsCondition: string, preParsed?: ParsedExpr): {
|
|
33
|
+
condition: string;
|
|
34
|
+
preamble: string;
|
|
35
|
+
};
|
|
36
|
+
/** Extract the prop name from a `props.X ?? …` initial value, or null. */
|
|
37
|
+
extractPropNameFromInitialValue(initialValue: string): string | null;
|
|
38
|
+
/**
|
|
39
|
+
* Parse a signal-time initial value `props.X ?? <literal>` into the source
|
|
40
|
+
* prop name and the Go-formatted fallback, or null when it isn't that shape.
|
|
41
|
+
*/
|
|
42
|
+
extractPropFallback(initialValue: string): {
|
|
43
|
+
propName: string;
|
|
44
|
+
goFallback: string;
|
|
45
|
+
} | null;
|
|
46
|
+
/**
|
|
47
|
+
* Inline a module string const by name as a Go double-quoted literal
|
|
48
|
+
* (`"<escaped>"`), or null when the name is not such a const (loop vars and
|
|
49
|
+
* outer-loop params are excluded).
|
|
50
|
+
*/
|
|
51
|
+
resolveModuleStringConst(name: string): string | null;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=emit-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emit-context.d.ts","sourceRoot":"","sources":["../../src/adapter/emit-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AAE1D,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAA;IAE5B;;;OAGG;IACH,qBAAqB,CACnB,MAAM,EAAE,MAAM,EACd,GAAG,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,UAAU,CAAA;KAAE,EAC7B,SAAS,CAAC,EAAE,UAAU,GACrB,MAAM,CAAA;IAET;;;OAGG;IACH,oBAAoB,CAClB,WAAW,EAAE,MAAM,EACnB,SAAS,CAAC,EAAE,UAAU,GACrB;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;IAE1C,0EAA0E;IAC1E,+BAA+B,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;IAEpE;;;OAGG;IACH,mBAAmB,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IAE1F;;;;OAIG;IACH,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAA;CACtD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inlining of component-scope arrow-const helpers at a call site.
|
|
3
|
+
*
|
|
4
|
+
* When a JSX expression calls a local `const f = (a) => …` helper, the Go
|
|
5
|
+
* adapter has no function to emit — it inlines the helper body with the call
|
|
6
|
+
* args substituted for the params, so the result lowers like any inline
|
|
7
|
+
* expression. The substitution is scope-blind, so the guards here reject bodies
|
|
8
|
+
* where a param replacement could be wrong.
|
|
9
|
+
*/
|
|
10
|
+
import { type ParsedExpr } from '@barefootjs/jsx';
|
|
11
|
+
import type { GoEmitContext } from '../emit-context.ts';
|
|
12
|
+
/**
|
|
13
|
+
* Inline a call to a local arrow-const helper.
|
|
14
|
+
*
|
|
15
|
+
* @param callParsed the call's already-built `ParsedExpr`. Must be a `call`
|
|
16
|
+
* node; inlining is declined without it.
|
|
17
|
+
* @returns the substituted body tree, or null when the expression isn't such a
|
|
18
|
+
* call or the body isn't substitution-safe (nested functions, helper-calling
|
|
19
|
+
* helpers, spread args, …)
|
|
20
|
+
*/
|
|
21
|
+
export declare function inlineLocalHelperCall(ctx: GoEmitContext, jsExpr: string, callParsed?: ParsedExpr): ParsedExpr | null;
|
|
22
|
+
/**
|
|
23
|
+
* Re-build `body` with each identifier named in `subs` replaced by the
|
|
24
|
+
* substitution's `ParsedExpr` subtree. The substitution is the arg subtree
|
|
25
|
+
* itself, so operator precedence survives without parenthesisation (the tree
|
|
26
|
+
* *is* the precedence). Non-value identifier positions — the property NAME in
|
|
27
|
+
* `a.b`, a plain `{ k: … }` key — are not visited, so a param sharing a name
|
|
28
|
+
* with a member or key is left untouched.
|
|
29
|
+
*/
|
|
30
|
+
export declare function substituteHelperParams(body: ParsedExpr, subs: ReadonlyMap<string, ParsedExpr>): ParsedExpr;
|
|
31
|
+
//# sourceMappingURL=helper-inline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper-inline.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/helper-inline.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEvD;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACnC,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,UAAU,GACtB,UAAU,GAAG,IAAI,CA6CnB;AAmFD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,GACpC,UAAU,CAqDZ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go lowering of helper calls to template expressions. Renders backend-neutral
|
|
3
|
+
* `LoweringNode`s produced by registered lowering plugins (#2057) — one uniform
|
|
4
|
+
* path for both userland plugins and built-ins like `queryHref` (a default plugin
|
|
5
|
+
* that lowers to `bf_query`, #2042). Every node funnels through
|
|
6
|
+
* `renderLoweringNode`, which maps a logical helper id to its Go helper; the
|
|
7
|
+
* adapter carries no per-API recognition branch of its own.
|
|
8
|
+
*/
|
|
9
|
+
import { type ParsedExpr } from '@barefootjs/jsx';
|
|
10
|
+
import type { GoEmitContext } from '../emit-context.ts';
|
|
11
|
+
/**
|
|
12
|
+
* Lower a helper call to a Go template expression, or null when no registered
|
|
13
|
+
* plugin recognises it (→ the generic lowering). Matchers — including the
|
|
14
|
+
* built-in `queryHref` plugin (#2042) — are bound to the component metadata at
|
|
15
|
+
* init (`ctx.state.loweringMatchers`), so this is one uniform loop with no
|
|
16
|
+
* per-API branch.
|
|
17
|
+
*
|
|
18
|
+
* Cheap-out: no active matchers → null; else reuse `preParsed` when it's already
|
|
19
|
+
* a call, otherwise a regex pre-filter gates the parse so non-call expressions
|
|
20
|
+
* never pay for `parseExpression`.
|
|
21
|
+
*/
|
|
22
|
+
export declare function lowerRegisteredCall(ctx: GoEmitContext, jsExpr: string, preParsed?: ParsedExpr): string | null;
|
|
23
|
+
//# sourceMappingURL=url-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"url-builder.d.ts","sourceRoot":"","sources":["../../../src/adapter/expr/url-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAEL,KAAK,UAAU,EAGhB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAwCvD;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,UAAU,GACrB,MAAM,GAAG,IAAI,CAmBf"}
|