@barefootjs/go-template 0.16.0 → 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 +2857 -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 +2856 -2617
- package/dist/index.js +2857 -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 +118 -54
- 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 +2099 -5325
- 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,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-compile mutable state for the Go html/template adapter. The adapter is a
|
|
3
|
+
* reused singleton; everything established (and reset) per `generate()` /
|
|
4
|
+
* `generateTypes()` run lives here. The adapter holds a single `CompileState`
|
|
5
|
+
* and resets its members at the start of each compile.
|
|
6
|
+
*
|
|
7
|
+
* NOT included (deliberately): cross-compile child-shape registries
|
|
8
|
+
* (`childComponentShapes`, `childContextConsumers`, populated before a parent
|
|
9
|
+
* compiles), the render-recursion cursor stacks (`loopParamStack`,
|
|
10
|
+
* `filterExprDepth`, …), and constant config (`options`, `templatePrimitives`).
|
|
11
|
+
*/
|
|
12
|
+
import type { CompilerError, ContextConsumer, IRMetadata, IRNode, LoweringMatcher, MemoInfo, TypeDefinition, TypeInfo } from '@barefootjs/jsx';
|
|
13
|
+
export declare class CompileState {
|
|
14
|
+
componentName: string;
|
|
15
|
+
errors: CompilerError[];
|
|
16
|
+
/** Component-scope derived consts referenced by the template during rendering
|
|
17
|
+
* (e.g. `root` → `.Root`). `generateTypes` emits a computed field for each
|
|
18
|
+
* that's resolvable and non-colliding. */
|
|
19
|
+
referencedDerivedConsts: Set<string>;
|
|
20
|
+
templateVarCounter: number;
|
|
21
|
+
/**
|
|
22
|
+
* Companion `{{define "<Component>__children_<slot>"}}` blocks queued while
|
|
23
|
+
* rendering the template body. Flushed after the main define in `generate()`.
|
|
24
|
+
*/
|
|
25
|
+
pendingChildrenDefines: Array<{
|
|
26
|
+
name: string;
|
|
27
|
+
content: string;
|
|
28
|
+
}>;
|
|
29
|
+
propsObjectName: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Component-scoped rest binding identifier (`function({ a, ...rest }: P)`
|
|
32
|
+
* → `'rest'`). Stashed at `generate()` entry so per-attribute emitter
|
|
33
|
+
* callbacks can classify a spread expression against it.
|
|
34
|
+
*/
|
|
35
|
+
restPropsName: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* Module-scope pure string-literal constants (`const X = 'literal'` at
|
|
38
|
+
* file top-level), keyed by name → resolved literal value. When an identifier
|
|
39
|
+
* resolves to one of these, the adapter inlines the literal value instead of
|
|
40
|
+
* emitting a struct-field reference.
|
|
41
|
+
*/
|
|
42
|
+
moduleStringConsts: Map<string, string>;
|
|
43
|
+
/**
|
|
44
|
+
* All local constants (module + function-scope) from the IR, retained for
|
|
45
|
+
* the lifetime of `generate()` so the memo-computation path can resolve
|
|
46
|
+
* `Record`-index lookups without re-threading the full `ir` through helpers.
|
|
47
|
+
*/
|
|
48
|
+
localConstants: IRMetadata['localConstants'];
|
|
49
|
+
/**
|
|
50
|
+
* Names of component-scope arrow-const helpers (`const sortClass = …`),
|
|
51
|
+
* eligible for call-site inlining.
|
|
52
|
+
*/
|
|
53
|
+
localHelperNames: Set<string>;
|
|
54
|
+
/** The current IR's memos, stashed like `localConstants` so nested memo
|
|
55
|
+
* resolution can recurse without threading the list through every signature.
|
|
56
|
+
* Full `MemoInfo` so consumers can read the analyzer-attached `parsed` tree. */
|
|
57
|
+
currentMemos: MemoInfo[];
|
|
58
|
+
/** Full type definitions from the current IR, stashed for loop-datum field resolution. */
|
|
59
|
+
currentTypeDefinitions: TypeDefinition[];
|
|
60
|
+
/**
|
|
61
|
+
* `useContext(...)` consumers in the component being generated. Each becomes
|
|
62
|
+
* a struct field defaulted to the `createContext` default.
|
|
63
|
+
*/
|
|
64
|
+
contextConsumers: ContextConsumer[];
|
|
65
|
+
/**
|
|
66
|
+
* Local binding names the request-scoped `searchParams()` env signal is
|
|
67
|
+
* imported under (handles `import { searchParams as sp }`).
|
|
68
|
+
*/
|
|
69
|
+
searchParamsLocals: Set<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Call-lowering matchers active for this component (#2057), bound to its
|
|
72
|
+
* metadata at init via `prepareLoweringMatchers`. Each maps a recognised call
|
|
73
|
+
* to a backend-neutral `LoweringNode` the adapter renders. Covers both userland
|
|
74
|
+
* plugins and the compiler's built-in plugins (e.g. `queryHref` → `bf_query`,
|
|
75
|
+
* #2042), so there is no separate per-API recognition path.
|
|
76
|
+
*/
|
|
77
|
+
loweringMatchers: LoweringMatcher[];
|
|
78
|
+
/**
|
|
79
|
+
* Prop NAMES whose resolved Go struct-field type is exactly `interface{}`
|
|
80
|
+
* — i.e. nillable. Used by the attribute emitter to omit a dynamic attribute
|
|
81
|
+
* whose value is a bare reference to such a prop when it's nil.
|
|
82
|
+
*/
|
|
83
|
+
nillablePropNames: Set<string>;
|
|
84
|
+
/** Component root scope element(s) — each carries `data-key` for a keyed loop
|
|
85
|
+
* item. */
|
|
86
|
+
rootScopeNodes: Set<IRNode>;
|
|
87
|
+
/** Array-memo name → the handler-filled loop slice field its `.map()` feeds
|
|
88
|
+
* (e.g. `visible` → `PostListItems`). Lets `<memo>().length` lower to the
|
|
89
|
+
* slice's length instead of a nil/unset memo field. */
|
|
90
|
+
memoBackedLoopSlice: Map<string, string>;
|
|
91
|
+
/** Set during type generation when any emit references
|
|
92
|
+
* `template.HTML(...)`; toggles the `"html/template"` import. */
|
|
93
|
+
usesHtmlTemplate: boolean;
|
|
94
|
+
/** Set during type generation when any emit references `fmt.Sprint(...)`;
|
|
95
|
+
* toggles the `"fmt"` import. */
|
|
96
|
+
usesFmt: boolean;
|
|
97
|
+
/** Local type names resolved from typeDefinitions (populated during generateTypes). */
|
|
98
|
+
localTypeNames: Set<string>;
|
|
99
|
+
/** Local type aliases mapping type name to base type (e.g., Filter → 'string'). */
|
|
100
|
+
localTypeAliases: Map<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* Per-struct field map (type name → source TS key → Go field name), populated
|
|
103
|
+
* during generateTypes. The object-literal baker consults this so a baked
|
|
104
|
+
* struct literal only names fields the generated struct actually declares.
|
|
105
|
+
*/
|
|
106
|
+
localStructFields: Map<string, Map<string, string>>;
|
|
107
|
+
/**
|
|
108
|
+
* Synthesised array types for untyped object-array signals (signal getter →
|
|
109
|
+
* `[]SynthStruct` TypeInfo), populated during generateTypes.
|
|
110
|
+
*/
|
|
111
|
+
synthStructTypes: Map<string, TypeInfo>;
|
|
112
|
+
/** Set when a constructor-context lowering emits a `strings.` call, so
|
|
113
|
+
* `strings` is added to the generated types file's import block. */
|
|
114
|
+
needsStringsImport: boolean;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=compile-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compile-state.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/compile-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,UAAU,EACV,MAAM,EACN,eAAe,EACf,QAAQ,EACR,cAAc,EACd,QAAQ,EACT,MAAM,iBAAiB,CAAA;AAExB,qBAAa,YAAY;IAGvB,aAAa,EAAE,MAAM,CAAK;IAC1B,MAAM,EAAE,aAAa,EAAE,CAAK;IAE5B;;+CAE2C;IAC3C,uBAAuB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEhD,kBAAkB,EAAE,MAAM,CAAI;IAE9B;;;OAGG;IACH,sBAAsB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAK;IAErE,eAAe,EAAE,MAAM,GAAG,IAAI,CAAO;IAErC;;;;OAIG;IACH,aAAa,EAAE,MAAM,GAAG,IAAI,CAAO;IAEnC;;;;;OAKG;IACH,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAEnD;;;;OAIG;IACH,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC,CAAK;IAEjD;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEzC;;qFAEiF;IACjF,YAAY,EAAE,QAAQ,EAAE,CAAK;IAE7B,0FAA0F;IAC1F,sBAAsB,EAAE,cAAc,EAAE,CAAK;IAE7C;;;OAGG;IACH,gBAAgB,EAAE,eAAe,EAAE,CAAK;IAExC;;;OAGG;IACH,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAE3C;;;;;;OAMG;IACH,gBAAgB,EAAE,eAAe,EAAE,CAAK;IAExC;;;;OAIG;IACH,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAE1C;gBACY;IACZ,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEvC;;4DAEwD;IACxD,mBAAmB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAIpD;sEACkE;IAClE,gBAAgB,EAAE,OAAO,CAAQ;IAEjC;sCACkC;IAClC,OAAO,EAAE,OAAO,CAAQ;IAExB,uFAAuF;IACvF,cAAc,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAEvC,mFAAmF;IACnF,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAY;IAEjD;;;;OAIG;IACH,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAY;IAE/D;;;OAGG;IACH,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAY;IAEnD;yEACqE;IACrE,kBAAkB,UAAQ;CAC3B"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time constant tables for the Go html/template adapter.
|
|
3
|
+
*/
|
|
4
|
+
import type { PrimitiveSpec } from "./types.ts";
|
|
5
|
+
/**
|
|
6
|
+
* Single source of truth for the Go adapter's template-primitive surface. Each
|
|
7
|
+
* entry pairs the expected arity with the emit function so the two derived maps
|
|
8
|
+
* (`templatePrimitives` and `templatePrimitiveArities`) can't drift out of sync.
|
|
9
|
+
*/
|
|
10
|
+
export declare const GO_TEMPLATE_PRIMITIVES: Record<string, PrimitiveSpec>;
|
|
11
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAG/C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAWhE,CAAA"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go html/template emit helpers: string escaping, argument wrapping, `bf_*`
|
|
3
|
+
* runtime-helper call construction, and JSX-literal → Go-literal lowering.
|
|
4
|
+
* Pure free functions — none read adapter instance state.
|
|
5
|
+
*/
|
|
6
|
+
import type { SortComparator, SupportResult, ParsedExpr } from '@barefootjs/jsx';
|
|
7
|
+
/** Escape a value for embedding in a Go-template double-quoted string. */
|
|
8
|
+
export declare function escapeGoString(s: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Wrap a rendered Go template fragment in parens when it would otherwise parse
|
|
11
|
+
* as multiple sibling args of an enclosing prefix call. A bare identifier /
|
|
12
|
+
* dotted path / quoted literal stays uncluttered; anything containing
|
|
13
|
+
* whitespace (a call, `len ...`) gets `(...)` so `bf_join (...) bf_trim .Raw`
|
|
14
|
+
* doesn't degrade to four args of `bf_join`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function wrapIfMultiToken(rendered: string): string;
|
|
17
|
+
/**
|
|
18
|
+
* Parenthesize a compound Go template argument (`or .Checked false`) so a
|
|
19
|
+
* primitive call reads it as ONE argument — unwrapped, the parser splits it
|
|
20
|
+
* into three and `bf_string` fails with "want 1 got 3".
|
|
21
|
+
*/
|
|
22
|
+
export declare function wrapGoArg(arg: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Emit the `bf_sort` call:
|
|
25
|
+
*
|
|
26
|
+
* bf_sort <recv> (<keyKind> <keyName> <compareType> <direction>)+
|
|
27
|
+
*
|
|
28
|
+
* keyKind: "self" | "field"
|
|
29
|
+
* keyName: "" when keyKind=self; capitalised field name otherwise
|
|
30
|
+
* compareType: "numeric" | "string" | "auto"
|
|
31
|
+
* direction: "asc" | "desc"
|
|
32
|
+
*
|
|
33
|
+
* The 4-string group repeats once per comparison key: a simple comparator emits
|
|
34
|
+
* one group; a `||`-chained multi-key comparator emits one per operand, applied
|
|
35
|
+
* in order as tie-breakers by the variadic `bf_sort` runtime. Capitalisation
|
|
36
|
+
* mirrors the Go struct-field convention so the runtime's reflect lookup
|
|
37
|
+
* matches without a recapitalise step.
|
|
38
|
+
*/
|
|
39
|
+
export declare function emitBfSort(recv: string, c: SortComparator): string;
|
|
40
|
+
/**
|
|
41
|
+
* Emit a `.sort(cmp)` via the evaluator (#2018): the comparator body travels as
|
|
42
|
+
* serialized-ParsedExpr JSON, evaluated per comparison against `{paramA, paramB,
|
|
43
|
+
* …captured}`. Returns null when the comparator can't be evaluated (e.g. a
|
|
44
|
+
* `localeCompare` body — `serializeParsedExpr` refuses it), so the caller falls
|
|
45
|
+
* back to the structured `bf_sort`. A `||`-chained multi-key comparator needs no
|
|
46
|
+
* special handling — JS `0 || next` is exactly the tie-break semantics.
|
|
47
|
+
*/
|
|
48
|
+
export declare function emitSortEval(recv: string, body: ParsedExpr, params: string[], emit: (e: ParsedExpr) => string): string | null;
|
|
49
|
+
/**
|
|
50
|
+
* Emit a `.reduce(fn, init)` via the evaluator (#2018): the reducer body travels
|
|
51
|
+
* as serialized-ParsedExpr JSON, folded over the receiver from `init`. Returns
|
|
52
|
+
* null when the body can't be evaluated, or when `init` isn't a string/number
|
|
53
|
+
* literal (a non-literal seed has no template-time value). A numeric seed is
|
|
54
|
+
* passed through `bf_number` (handles any decimal incl. negative / float); a
|
|
55
|
+
* string seed as a quoted string.
|
|
56
|
+
*/
|
|
57
|
+
export declare function emitReduceEval(recv: string, body: ParsedExpr, params: string[], init: ParsedExpr, direction: 'left' | 'right', emit: (e: ParsedExpr) => string): string | null;
|
|
58
|
+
/**
|
|
59
|
+
* Emit a higher-order predicate call via the evaluator (#2018, P2): the
|
|
60
|
+
* predicate body (already a `ParsedExpr` on the `higher-order` IR node) travels
|
|
61
|
+
* as serialized-ParsedExpr JSON, evaluated per element against `{param,
|
|
62
|
+
* …captured}`. Generalizes the field-equality / truthiness catalogues of
|
|
63
|
+
* `bf_filter` / `bf_find` / `bf_every` / `bf_some` to any pure predicate body.
|
|
64
|
+
* Returns null when the predicate is outside the evaluator surface (e.g. a
|
|
65
|
+
* method-call predicate — `serializeParsedExpr` refuses it), so the caller
|
|
66
|
+
* falls back to the structured helper / template-block path.
|
|
67
|
+
*
|
|
68
|
+
* <func> <recv> "<json>" "<param>" [<extraArgs>…] <env>
|
|
69
|
+
*
|
|
70
|
+
* `extraArgs` are inserted between the param name and the env — used for the
|
|
71
|
+
* find / findIndex `forward` bool (`true` = find / findIndex, `false` =
|
|
72
|
+
* findLast / findLastIndex).
|
|
73
|
+
*/
|
|
74
|
+
export declare function emitPredicateEval(funcName: string, recv: string, predicate: ParsedExpr, param: string, emit: (e: ParsedExpr) => string, extraArgs?: string[]): string | null;
|
|
75
|
+
/**
|
|
76
|
+
* Emit a `.flatMap(proj)` via the evaluator (#2018, P3): the projection body
|
|
77
|
+
* (e.g. `i.tags` / `[i.a, i.b]`) is serialized and evaluated per element by
|
|
78
|
+
* `bf_flat_map_eval`, which flattens the results one level. Returns null when
|
|
79
|
+
* the projection is outside the evaluator surface (→ caller pushes BF101).
|
|
80
|
+
*/
|
|
81
|
+
export declare function emitFlatMapEval(recv: string, body: ParsedExpr, param: string, emit: (e: ParsedExpr) => string): string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Make an equality comparison string-tolerant when exactly one side is a Go
|
|
84
|
+
* string literal: JS `sorted === 'asc'` is loosely false for `sorted = false`,
|
|
85
|
+
* but Go's template `eq` ERRORS on bool-vs-string (`incompatible types for
|
|
86
|
+
* comparison`). Routing the non-literal side through `bf_string` preserves JS
|
|
87
|
+
* comparison semantics for every concrete type while leaving same-kind
|
|
88
|
+
* comparisons untouched.
|
|
89
|
+
*/
|
|
90
|
+
export declare function stringTolerantEqOperands(l: string, r: string): [string, string];
|
|
91
|
+
export declare const GO_REMEDIATION_OPTIONS = "Options:\n1. Use @client directive for client-side evaluation\n2. Pre-compute the value in Go code";
|
|
92
|
+
export declare function buildUnsupportedSuggestion(support: SupportResult): string;
|
|
93
|
+
/**
|
|
94
|
+
* Translate a JSX param default (e.g. `'default'`, `0`, `false`) into the
|
|
95
|
+
* corresponding Go literal.
|
|
96
|
+
*
|
|
97
|
+
* @returns the Go literal, or `null` when the default is absent or non-trivial
|
|
98
|
+
* (objects, arrow functions, …) — caller then lets Go's zero value win.
|
|
99
|
+
*/
|
|
100
|
+
export declare function goPropDefault(defaultValue: string | undefined): string | null;
|
|
101
|
+
/**
|
|
102
|
+
* Wrap an `in.X` reference in a Go expression that substitutes `fallback` when
|
|
103
|
+
* the input is the zero value for its type; the comparison is picked from the
|
|
104
|
+
* fallback literal's shape.
|
|
105
|
+
*
|
|
106
|
+
* Asymmetry on bool/zero defaults is intentional (Go has no
|
|
107
|
+
* unset-vs-explicit-false distinction at the struct-field level):
|
|
108
|
+
* - `true` default → `(in.X || true)`, which is ALWAYS `true`; a caller
|
|
109
|
+
* wanting `false` must set it after `NewXxxProps`, not via the input struct.
|
|
110
|
+
* - `false` / `0` default → matches the Go zero value, so this is a no-op
|
|
111
|
+
* (returns `ref` unchanged).
|
|
112
|
+
* Non-zero numeric defaults substitute, matching JSX `(initial = 5) => …`.
|
|
113
|
+
*/
|
|
114
|
+
export declare function applyGoFallback(ref: string, fallback: string): string;
|
|
115
|
+
/** Convert a JavaScript literal value to Go literal syntax. */
|
|
116
|
+
export declare function goLiteral(value: string): string;
|
|
117
|
+
//# sourceMappingURL=go-emit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"go-emit.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/go-emit.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAKhF,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAMzD;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAI7C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,cAAc,GAAG,MAAM,CAMlE;AAiBD;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,GAAG,IAAI,CAWf;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,MAAM,EAAE,MAAM,EAAE,EAChB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,MAAM,GAAG,OAAO,EAC3B,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,GAAG,IAAI,CAqBf;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,UAAU,EACrB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,EAC/B,SAAS,GAAE,MAAM,EAAO,GACvB,MAAM,GAAG,IAAI,CAMf;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,CAAC,EAAE,UAAU,KAAK,MAAM,GAC9B,MAAM,GAAG,IAAI,CAKf;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAO/E;AAID,eAAO,MAAM,sBAAsB,uGACmE,CAAA;AAOtG,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAIzE;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAe7E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAUrE;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAW/C"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go identifier / field-name conventions: the single source of truth for
|
|
3
|
+
* capitalisation, initialism handling, and slot/loop-key → Go field-path
|
|
4
|
+
* lowering. Pure helpers — none read adapter instance state.
|
|
5
|
+
*/
|
|
6
|
+
/** Matches a bare Go identifier (no dots, no brackets). */
|
|
7
|
+
export declare const GO_IDENTIFIER: RegExp;
|
|
8
|
+
/** Go common initialisms that should be fully uppercased (https://go.dev/wiki/CodeReviewComments#initialisms) */
|
|
9
|
+
export declare const GO_INITIALISMS: Set<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Go reserved keywords. When hoisting a local var named after a JSX prop, a
|
|
12
|
+
* collision with one of these is resolved by appending `_` until free.
|
|
13
|
+
*/
|
|
14
|
+
export declare const GO_KEYWORDS: Set<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Capitalise a name for use as a Go template field projection. A whole-word
|
|
17
|
+
* Go initialism uppercases entirely (`id` → `ID`, `url` → `URL`) so the
|
|
18
|
+
* `bf_sort` / `bf_reduce` reflect lookup resolves the generated exported
|
|
19
|
+
* field instead of silently folding a zero value.
|
|
20
|
+
*/
|
|
21
|
+
export declare function capitalize(s: string): string;
|
|
22
|
+
/** Capitalise a JSX prop / field name to its exported Go struct field name. */
|
|
23
|
+
export declare function capitalizeFieldName(name: string): string;
|
|
24
|
+
/**
|
|
25
|
+
* Convert a slot ID (e.g., 's6') to a Go struct field suffix (e.g., 'Slot6').
|
|
26
|
+
* Keeps field names human-readable regardless of the internal slot ID format.
|
|
27
|
+
*/
|
|
28
|
+
export declare function slotIdToFieldSuffix(slotId: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Lower a keyed-loop `key` expression to the Go field path on the loop's range
|
|
31
|
+
* variable (always `item` in the generated `for i, item := range …`), e.g.
|
|
32
|
+
* `item.label` → `item.Label`.
|
|
33
|
+
*
|
|
34
|
+
* @returns `null` for a non-simple key (computed expression, whole-element key,
|
|
35
|
+
* mismatched param) — caller then skips `data-key` rather than emit
|
|
36
|
+
* something that won't compile.
|
|
37
|
+
*/
|
|
38
|
+
export declare function loopKeyToGoFieldPath(key: string | undefined, param: string | undefined): string | null;
|
|
39
|
+
//# sourceMappingURL=go-naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"go-naming.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/go-naming.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,2DAA2D;AAC3D,eAAO,MAAM,aAAa,QAA6B,CAAA;AAEvD,iHAAiH;AACjH,eAAO,MAAM,cAAc,aAIzB,CAAA;AAEF;;;GAGG;AACH,eAAO,MAAM,WAAW,aAKtB,CAAA;AAEF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAM5C;AAED,+EAA+E;AAC/E,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAS1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAQtG"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* IR traversal helpers for the Go html/template adapter. Pure functions over
|
|
3
|
+
* the IR tree — no adapter instance state.
|
|
4
|
+
*/
|
|
5
|
+
import type { IRNode } from '@barefootjs/jsx';
|
|
6
|
+
/**
|
|
7
|
+
* Collect the component's root scope element node(s) — the elements that become
|
|
8
|
+
* the rendered root and so carry `data-key` for a keyed loop item. A plain
|
|
9
|
+
* element root is itself; an `if-statement` (early-return) root contributes the
|
|
10
|
+
* top element of each branch, since exactly one renders at runtime.
|
|
11
|
+
*/
|
|
12
|
+
export declare function collectRootScopeNodes(node: IRNode): Set<IRNode>;
|
|
13
|
+
//# sourceMappingURL=ir-scope.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ir-scope.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/ir-scope.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,MAAM,EAA6B,MAAM,iBAAiB,CAAA;AAExE;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAiB/D"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal type definitions for the Go html/template adapter: the adapter's
|
|
3
|
+
* intermediate bookkeeping shapes (nested-component info, static child
|
|
4
|
+
* instances, spread slots, ctor-lowering scope, …) plus the public
|
|
5
|
+
* `GoTemplateAdapterOptions`. Pure type surface — no behaviour.
|
|
6
|
+
*/
|
|
7
|
+
import type { IRLoopChildComponent, IRNode, IRProp, ParsedExpr, TypeInfo } from '@barefootjs/jsx';
|
|
8
|
+
/**
|
|
9
|
+
* Go-template adapter's IRNode render context. Only `isRootOfClientComponent`
|
|
10
|
+
* is consumed today (forwarded into `renderComponent` / `renderIfStatement`);
|
|
11
|
+
* the type stays open so future render-position flags can be added without
|
|
12
|
+
* widening the `IRNodeEmitter` contract.
|
|
13
|
+
*/
|
|
14
|
+
export type GoRenderCtx = {
|
|
15
|
+
isRootOfClientComponent?: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Extended nested component info that tracks whether the component
|
|
19
|
+
* comes from a dynamic (signal) array loop vs a static array loop.
|
|
20
|
+
*/
|
|
21
|
+
export interface NestedComponentInfo extends IRLoopChildComponent {
|
|
22
|
+
isDynamic: boolean;
|
|
23
|
+
isPropDerived: boolean;
|
|
24
|
+
/** The enclosing loop's `key` expression (e.g. `item.label`) and map param
|
|
25
|
+
* name (`item`), so the loop-child init can stamp `data-key` per item. */
|
|
26
|
+
loopKey?: string;
|
|
27
|
+
loopParam?: string;
|
|
28
|
+
/** The loop body component's JSX children. Non-empty when those children need
|
|
29
|
+
* a companion define rendered via `bf_with_children` + `bf_tmpl`. */
|
|
30
|
+
bodyChildren?: IRNode[];
|
|
31
|
+
/** The loop's array expression for baking (e.g. `sortedData()`) */
|
|
32
|
+
loopArray?: string;
|
|
33
|
+
/** Structured parse of `loopArray` (the loop's `array` string), carried so
|
|
34
|
+
* scalar-literal loop typing reads the tree instead of re-parsing. */
|
|
35
|
+
loopArrayParsed?: ParsedExpr;
|
|
36
|
+
/** The enclosing loop's `markerId` (e.g. `l0`) for unique naming */
|
|
37
|
+
loopMarkerId?: string;
|
|
38
|
+
/** The loop item's TS type (`Payment` from `sortedData().map(payment => …)`),
|
|
39
|
+
* resolved to Go struct fields for the wrapper struct's datum fields. */
|
|
40
|
+
loopItemType?: TypeInfo | null;
|
|
41
|
+
}
|
|
42
|
+
export interface StaticChildInstance {
|
|
43
|
+
name: string;
|
|
44
|
+
slotId: string;
|
|
45
|
+
props: IRProp[];
|
|
46
|
+
fieldName: string;
|
|
47
|
+
/** Concatenated text content from JSX children (e.g. `+1` for
|
|
48
|
+
* `<Button>+1</Button>`). Null when children include any non-text node;
|
|
49
|
+
* those take the `childrenHtml` path if purely static HTML, else dropped. */
|
|
50
|
+
childrenText: string | null;
|
|
51
|
+
/** Rendered Go-template fragment for purely-static, non-text JSX children,
|
|
52
|
+
* forwarded via `Children: template.HTML(...)` so the child's
|
|
53
|
+
* `{{or .Children ""}}` skips re-escaping. Null when children are text-only
|
|
54
|
+
* or absent, OR when the fragment contains any `{{...}}` action (those
|
|
55
|
+
* wouldn't re-evaluate through the parent's `{{.Children}}` read — kept on
|
|
56
|
+
* the drop path). */
|
|
57
|
+
childrenHtml: string | null;
|
|
58
|
+
/** Go string-concat expression for hoisted-JSX children that carry a
|
|
59
|
+
* `needsScope` root (`children={<span/>}`). The root's `bf-s` resolves to
|
|
60
|
+
* the PARENT scope, so the fragment can't bake to a static string — the
|
|
61
|
+
* runtime `scopeID` is spliced in (`"<span bf-s=\"" + scopeID + "\">x</span>"`).
|
|
62
|
+
* Null when static `childrenHtml` already covers the children, or when any
|
|
63
|
+
* other template action survives (genuinely dynamic — drop path). */
|
|
64
|
+
childrenScopedHtmlExpr: string | null;
|
|
65
|
+
/**
|
|
66
|
+
* Context values from enclosing `<Ctx.Provider value>` ancestors
|
|
67
|
+
* (`createContext` identifier → Go value literal), wired into this child
|
|
68
|
+
* slot's input against its own context-consumer fields. Empty/undefined when
|
|
69
|
+
* the child isn't under any provider.
|
|
70
|
+
*/
|
|
71
|
+
contextBindings?: ReadonlyMap<string, string>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Cross-component shape of a child component the parent renders.
|
|
75
|
+
* `paramNames` are the child's declared `propsParams`; `restBagField` is the
|
|
76
|
+
* Go field name of the child's open-ended rest bag
|
|
77
|
+
* (`Capitalize(restPropsName)`), or null when the child has no `...props` rest.
|
|
78
|
+
*/
|
|
79
|
+
export interface ChildComponentShape {
|
|
80
|
+
paramNames: Set<string>;
|
|
81
|
+
restBagField: string | null;
|
|
82
|
+
/**
|
|
83
|
+
* Child param names whose Go field is `map[string]interface{}` — an optional
|
|
84
|
+
* object/named-interface prop (`opts?: EmblaOptionsType`). A parent passing
|
|
85
|
+
* an inline object literal to such a param bakes it to a Go map literal so
|
|
86
|
+
* the keys round-trip faithfully.
|
|
87
|
+
*/
|
|
88
|
+
mapTypedParamNames: Set<string>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Top-level (non-loop) JSX intrinsic-element spread slot. The adapter emits one
|
|
92
|
+
* `Spread_<slotId> map[string]any` field on the component's Props struct and
|
|
93
|
+
* initialises it in `NewXxxProps` from the source JS expression. Loop-internal
|
|
94
|
+
* spreads don't appear here — they emit the bag inline via the loop's iteration
|
|
95
|
+
* variable instead.
|
|
96
|
+
*
|
|
97
|
+
* `bagSource` records how the bag is supplied:
|
|
98
|
+
* - `'inline'`: constructed inside `NewXxxProps` from compile-time-known data
|
|
99
|
+
* (signal initial values, prop refs, propsObject enumeration). No Input field.
|
|
100
|
+
* - `'input-bag'`: provided by the caller as a `Spread_<slotId> map[string]any`
|
|
101
|
+
* field on the Input struct (for `restPropsName` spreads whose keys are
|
|
102
|
+
* open-ended and can't be enumerated under Go's static typing).
|
|
103
|
+
*/
|
|
104
|
+
export interface SpreadSlotInfo {
|
|
105
|
+
slotId: string;
|
|
106
|
+
expr: string;
|
|
107
|
+
/**
|
|
108
|
+
* Best-effort structured parse of `expr`. Lets the conditional inline-object
|
|
109
|
+
* spread lower from the tree instead of re-parsing `expr`. When absent, a
|
|
110
|
+
* non-conditional / `unsupported` tree falls through to the other spread
|
|
111
|
+
* shapes.
|
|
112
|
+
*/
|
|
113
|
+
parsed: ParsedExpr | undefined;
|
|
114
|
+
templateExpr: string | undefined;
|
|
115
|
+
bagSource: 'inline' | 'input-bag';
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Hoisted local var representing a prop with a signal-time `??` fallback. Used
|
|
119
|
+
* to share the fallback-applied value across the prop, signal, and memo fields.
|
|
120
|
+
*/
|
|
121
|
+
export interface PropFallbackVar {
|
|
122
|
+
/** Local variable name (typically the lowercase prop identifier). */
|
|
123
|
+
varName: string;
|
|
124
|
+
/** Capitalised Go field name on the `Input` struct. */
|
|
125
|
+
fieldName: string;
|
|
126
|
+
/** Go literal used when the input value equals its zero value. */
|
|
127
|
+
goFallback: string;
|
|
128
|
+
/** Go zero literal for the prop's type (`0`, `""`, etc.). */
|
|
129
|
+
zeroLiteral: string;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Scope for `lowerCtorExpr` — lowering a JS expression to Go in the
|
|
133
|
+
* `NewXxxProps` constructor context.
|
|
134
|
+
*/
|
|
135
|
+
export interface CtorLowerEnv {
|
|
136
|
+
/** Local names bound to `searchParams()` (`const sp = searchParams()`). */
|
|
137
|
+
searchParamsVars: Set<string>;
|
|
138
|
+
/** Helper-param name → its already-lowered Go argument, for inlining. */
|
|
139
|
+
params: Map<string, string>;
|
|
140
|
+
/** Component-scope const names currently being inlined (cycle guard). */
|
|
141
|
+
consts?: Set<string>;
|
|
142
|
+
}
|
|
143
|
+
export interface GoTemplateAdapterOptions {
|
|
144
|
+
/** Go package name for generated types (default: 'components') */
|
|
145
|
+
packageName?: string;
|
|
146
|
+
/**
|
|
147
|
+
* Base path for client JS files (e.g., '/static/client/').
|
|
148
|
+
* Used to generate script registration paths.
|
|
149
|
+
*/
|
|
150
|
+
clientJsBasePath?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Path to barefoot.js runtime (e.g., '/static/client/barefoot.js').
|
|
153
|
+
*/
|
|
154
|
+
barefootJsPath?: string;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Single source of truth for the Go adapter's template-primitive surface. Each
|
|
158
|
+
* entry pairs the expected arity with the emit function so the two derived maps
|
|
159
|
+
* (`templatePrimitives` and `templatePrimitiveArities`) can't drift out of sync.
|
|
160
|
+
*/
|
|
161
|
+
export interface PrimitiveSpec {
|
|
162
|
+
arity: number;
|
|
163
|
+
emit: (args: string[]) => string;
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/adapter/lib/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Constructor-context expression lowering for derived-state memos.
|
|
3
|
+
*
|
|
4
|
+
* Free functions over a {@link GoEmitContext} that lower the narrow surface of
|
|
5
|
+
* JS expressions a derived-state memo needs into Go *code* (not template
|
|
6
|
+
* syntax) evaluated in the `NewXxxProps` constructor — e.g. a search-param read
|
|
7
|
+
* becomes `in.SearchParams.Get("k")`. `lowerCtorExpr` and `lowerCtorCond` are
|
|
8
|
+
* mutually recursive and set `state.needsStringsImport` when they emit a
|
|
9
|
+
* `strings.*` call. Anything outside the supported surface returns null so the
|
|
10
|
+
* caller can fall back to nil safely.
|
|
11
|
+
*/
|
|
12
|
+
import { type ParsedExpr } from '@barefootjs/jsx';
|
|
13
|
+
import type { GoEmitContext } from '../emit-context.ts';
|
|
14
|
+
import type { CtorLowerEnv } from '../lib/types.ts';
|
|
15
|
+
/**
|
|
16
|
+
* Lower a JS expression to a Go expression in the `NewXxxProps` constructor
|
|
17
|
+
* context. This is Go *code*, not template syntax — so a search-param read
|
|
18
|
+
* becomes `in.SearchParams.Get("k")` (method call), not the template's
|
|
19
|
+
* `.SearchParams.Get "k"`. Supports the narrow surface derived-state memos
|
|
20
|
+
* need: string/number literals, `<sp>.get('k')`, `<arr>.includes(<x>)`,
|
|
21
|
+
* module arrow-helper inlining, `<expr> ?? <fallback>`, and string ternaries.
|
|
22
|
+
* Returns null for anything else so the caller can fall back safely.
|
|
23
|
+
*/
|
|
24
|
+
export declare function lowerCtorExpr(ctx: GoEmitContext, node: ParsedExpr, env: CtorLowerEnv): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Lower a JS expression used as a *boolean* condition to a Go bool expression,
|
|
27
|
+
* or null when it is not provably boolean. Distinct from `lowerCtorExpr`, which
|
|
28
|
+
* lowers value expressions: a string-valued condition (`sp.get('tag')`) is
|
|
29
|
+
* truthy in JS but `if "<string>"` does not compile in Go, so anything not
|
|
30
|
+
* known to yield a Go bool must fall back to null.
|
|
31
|
+
*/
|
|
32
|
+
export declare function lowerCtorCond(ctx: GoEmitContext, node: ParsedExpr, env: CtorLowerEnv): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Resolve a string-array expression (a `['a','b']` literal, or a module const
|
|
35
|
+
* bound to one) to a Go `[]string{…}` literal, or null when it isn't a pure
|
|
36
|
+
* string-array. Used by `lowerCtorExpr` for `<arr>.includes(<x>)`.
|
|
37
|
+
*/
|
|
38
|
+
export declare function lowerCtorStringArray(ctx: GoEmitContext, node: ParsedExpr): string | null;
|
|
39
|
+
//# sourceMappingURL=ctor-lowering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ctor-lowering.d.ts","sourceRoot":"","sources":["../../../src/adapter/memo/ctor-lowering.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAsBnD;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,YAAY,GAChB,MAAM,GAAG,IAAI,CA0Jf;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,aAAa,EAClB,IAAI,EAAE,UAAU,EAChB,GAAG,EAAE,YAAY,GAChB,MAAM,GAAG,IAAI,CA2Bf;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAexF"}
|