@kernlang/core 3.3.9 → 3.4.1

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.
Files changed (97) hide show
  1. package/dist/capability-matrix.d.ts +15 -0
  2. package/dist/capability-matrix.js +245 -0
  3. package/dist/capability-matrix.js.map +1 -0
  4. package/dist/codegen/body-ts.d.ts +68 -0
  5. package/dist/codegen/body-ts.js +214 -0
  6. package/dist/codegen/body-ts.js.map +1 -0
  7. package/dist/codegen/data-layer.d.ts +1 -1
  8. package/dist/codegen/data-layer.js +59 -23
  9. package/dist/codegen/data-layer.js.map +1 -1
  10. package/dist/codegen/events.js +1 -1
  11. package/dist/codegen/events.js.map +1 -1
  12. package/dist/codegen/functions.js +48 -7
  13. package/dist/codegen/functions.js.map +1 -1
  14. package/dist/codegen/ground-layer.js +10 -6
  15. package/dist/codegen/ground-layer.js.map +1 -1
  16. package/dist/codegen/helpers.d.ts +3 -1
  17. package/dist/codegen/helpers.js +5 -1
  18. package/dist/codegen/helpers.js.map +1 -1
  19. package/dist/codegen/kern-stdlib.d.ts +63 -0
  20. package/dist/codegen/kern-stdlib.js +160 -0
  21. package/dist/codegen/kern-stdlib.js.map +1 -0
  22. package/dist/codegen/machines.js +4 -3
  23. package/dist/codegen/machines.js.map +1 -1
  24. package/dist/codegen/modules.d.ts +1 -0
  25. package/dist/codegen/modules.js +52 -1
  26. package/dist/codegen/modules.js.map +1 -1
  27. package/dist/codegen/screens.js +31 -9
  28. package/dist/codegen/screens.js.map +1 -1
  29. package/dist/codegen/stdlib-preamble.d.ts +58 -0
  30. package/dist/codegen/stdlib-preamble.js +271 -0
  31. package/dist/codegen/stdlib-preamble.js.map +1 -0
  32. package/dist/codegen/type-system.d.ts +113 -1
  33. package/dist/codegen/type-system.js +404 -31
  34. package/dist/codegen/type-system.js.map +1 -1
  35. package/dist/codegen-core.d.ts +2 -2
  36. package/dist/codegen-core.js +65 -10
  37. package/dist/codegen-core.js.map +1 -1
  38. package/dist/codegen-expression.d.ts +11 -0
  39. package/dist/codegen-expression.js +199 -0
  40. package/dist/codegen-expression.js.map +1 -0
  41. package/dist/concepts.d.ts +3 -3
  42. package/dist/config.d.ts +16 -0
  43. package/dist/config.js +13 -0
  44. package/dist/config.js.map +1 -1
  45. package/dist/decompiler.js +575 -4
  46. package/dist/decompiler.js.map +1 -1
  47. package/dist/importer.d.ts +1 -0
  48. package/dist/importer.js +574 -34
  49. package/dist/importer.js.map +1 -1
  50. package/dist/index.d.ts +16 -3
  51. package/dist/index.js +19 -3
  52. package/dist/index.js.map +1 -1
  53. package/dist/node-props.d.ts +181 -1
  54. package/dist/node-props.js.map +1 -1
  55. package/dist/parser-core.d.ts +7 -1
  56. package/dist/parser-core.js +33 -7
  57. package/dist/parser-core.js.map +1 -1
  58. package/dist/parser-diagnostics.js +8 -0
  59. package/dist/parser-diagnostics.js.map +1 -1
  60. package/dist/parser-expression.d.ts +22 -0
  61. package/dist/parser-expression.js +774 -0
  62. package/dist/parser-expression.js.map +1 -0
  63. package/dist/parser-keywords.js +16 -0
  64. package/dist/parser-keywords.js.map +1 -1
  65. package/dist/parser-tokenizer.d.ts +5 -3
  66. package/dist/parser-tokenizer.js +97 -16
  67. package/dist/parser-tokenizer.js.map +1 -1
  68. package/dist/parser-validate-effects.d.ts +21 -0
  69. package/dist/parser-validate-effects.js +188 -0
  70. package/dist/parser-validate-effects.js.map +1 -0
  71. package/dist/parser-validate-expressions.d.ts +6 -0
  72. package/dist/parser-validate-expressions.js +41 -0
  73. package/dist/parser-validate-expressions.js.map +1 -0
  74. package/dist/parser-validate-propagation.d.ts +105 -0
  75. package/dist/parser-validate-propagation.js +684 -0
  76. package/dist/parser-validate-propagation.js.map +1 -0
  77. package/dist/parser-validate-union-kind.d.ts +24 -0
  78. package/dist/parser-validate-union-kind.js +97 -0
  79. package/dist/parser-validate-union-kind.js.map +1 -0
  80. package/dist/parser.d.ts +10 -3
  81. package/dist/parser.js +11 -5
  82. package/dist/parser.js.map +1 -1
  83. package/dist/schema.d.ts +1 -1
  84. package/dist/schema.js +562 -30
  85. package/dist/schema.js.map +1 -1
  86. package/dist/semantic-validator.js +24 -13
  87. package/dist/semantic-validator.js.map +1 -1
  88. package/dist/spec.d.ts +5 -2
  89. package/dist/spec.js +36 -2
  90. package/dist/spec.js.map +1 -1
  91. package/dist/types.d.ts +7 -1
  92. package/dist/types.js +7 -1
  93. package/dist/types.js.map +1 -1
  94. package/dist/value-ir.d.ts +96 -0
  95. package/dist/value-ir.js +25 -0
  96. package/dist/value-ir.js.map +1 -0
  97. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ /** (target × feature × position) capability matrix.
2
+ * Per-slice codegen declares which features compile in which contexts on which targets.
3
+ * Populated incrementally as language evolution slices ship. */
4
+ import type { KernTarget } from './config.js';
5
+ export type FeaturePosition = 'top-level' | 'fn-body' | 'render' | 'template' | 'expression';
6
+ export type Support = 'native' | 'lowered' | 'unsupported';
7
+ export interface CapabilityEntry {
8
+ feature: string;
9
+ position: FeaturePosition;
10
+ support: Support;
11
+ note?: string;
12
+ }
13
+ export type CapabilityMatrix = Record<KernTarget, CapabilityEntry[]>;
14
+ export declare const CAPABILITY_MATRIX: CapabilityMatrix;
15
+ export declare function capabilitySupport(target: KernTarget, feature: string, position: FeaturePosition): Support;
@@ -0,0 +1,245 @@
1
+ /** (target × feature × position) capability matrix.
2
+ * Per-slice codegen declares which features compile in which contexts on which targets.
3
+ * Populated incrementally as language evolution slices ship. */
4
+ const TS_CORE_CAPABILITIES = [
5
+ { feature: 'literal-float', position: 'expression', support: 'native' },
6
+ { feature: 'literal-numeric-separator', position: 'expression', support: 'native' },
7
+ { feature: 'literal-bigint', position: 'expression', support: 'native' },
8
+ { feature: 'literal-hex', position: 'expression', support: 'native' },
9
+ { feature: 'literal-binary', position: 'expression', support: 'native' },
10
+ { feature: 'literal-octal', position: 'expression', support: 'native' },
11
+ {
12
+ feature: 'literal-string-single-quote',
13
+ position: 'expression',
14
+ support: 'lowered',
15
+ note: 'normalized to double-quote on output',
16
+ },
17
+ { feature: 'optional-chain', position: 'expression', support: 'native' },
18
+ { feature: 'nullish-coalesce', position: 'expression', support: 'native' },
19
+ { feature: 'spread', position: 'expression', support: 'native' },
20
+ { feature: 'template-literal', position: 'expression', support: 'native' },
21
+ // Slice 1j — const.value is emitted via ValueIR expression codegen on TS targets.
22
+ // Quoted strings round-trip through JSON.stringify; bare expressions canonicalize via emitExpression.
23
+ { feature: 'const-value-as-expression', position: 'top-level', support: 'native' },
24
+ // Slice 2a — tuple types via type.alias / field.type / fn.returns / fn.params,
25
+ // including optional, rest, labeled, nested, and empty forms. Routed through
26
+ // emitTypeAnnotation's bracket-balance pass; no new node type required.
27
+ { feature: 'tuple-type', position: 'top-level', support: 'native' },
28
+ // Slice 2b — `enum` node for numeric (values=A|B|C) and string-valued
29
+ // (member name=X value="..." children) enums; `const enum` form supported.
30
+ { feature: 'enum-type', position: 'top-level', support: 'native' },
31
+ // Slice 2c — `indexer` child node on interface, emits `[key: K]: V` index
32
+ // signature with optional `readonly` modifier.
33
+ { feature: 'index-signature', position: 'top-level', support: 'native' },
34
+ // Slice 2d — type guards (predicate return types: `value is T`, `asserts x is T`,
35
+ // `this is T`). Already supported today via fn.returns + emitTypeAnnotation
36
+ // passthrough; formalised with regression tests in slice 2d.
37
+ { feature: 'type-guard', position: 'top-level', support: 'native' },
38
+ // Slice 2e — function overloads via `overload` child node. Each overload
39
+ // emits a `function name(params): R;` line before the implementation.
40
+ { feature: 'function-overloads', position: 'top-level', support: 'native' },
41
+ // Slice 2f — generics: `generics="<T>"` / `<T extends Base>` / `<T = Default>` /
42
+ // `<K, V>` on type, interface, fn, class. Routed through emitTypeAnnotation
43
+ // (whitespace + bracket-balance).
44
+ { feature: 'generics', position: 'top-level', support: 'native' },
45
+ // Slice 2g — cross-`.kern` symbol resolution via `use path="..."` parent
46
+ // with `from name=X as=Y export=true` children. `.kern` paths translate to
47
+ // `.js` in the emitted TS import; `export=true` produces an additional
48
+ // `export { ... } from '...'` re-export line.
49
+ { feature: 'cross-kern-import', position: 'top-level', support: 'native' },
50
+ // Slice 3a — `let.value` extends iteration-scoped bindings to use the
51
+ // ValueIR-canonicalised native expression form (mirrors `const.value`
52
+ // from slice 1j). `expr=` remains as the rawExpr passthrough fallback.
53
+ { feature: 'let-native-value', position: 'top-level', support: 'native' },
54
+ // Slice 3b — `field.value` extends class/service/config field initializers
55
+ // to the ValueIR-canonicalised native form (mirrors slice 1j/3a). `default=`
56
+ // remains as the rawExpr passthrough fallback for back-compat with seeds
57
+ // that author bare-string defaults like `default=plan` for string-typed
58
+ // fields, where the legacy type-aware coercion still applies.
59
+ { feature: 'field-native-value', position: 'top-level', support: 'native' },
60
+ // Slice 3c — `param.value` extends fn/method/constructor parameter defaults
61
+ // to the ValueIR-canonicalised native form via structured `param` child
62
+ // nodes. Mirrors slice 1j/3a/3b. Legacy `params="..."` string with embedded
63
+ // defaults remains supported for back-compat. Importer + migrate-class-body
64
+ // emit `param` children all-or-nothing per signature, gated to skip
65
+ // signatures with optional/variadic/destructured params (those stay legacy).
66
+ { feature: 'param-native-value', position: 'top-level', support: 'native' },
67
+ // Slice 3d — `destructure` adds a native node for TS-style destructured
68
+ // const/let bindings: `const {a, b: rename} = obj` (object pattern with
69
+ // `binding` children) and `const [x, y] = arr` (array pattern with
70
+ // `element` children). For complex patterns (rest `...`, defaults `=v`,
71
+ // nested `{a:{b}}`), the importer falls back to `expr={{...}}` carrying
72
+ // the raw TS statement verbatim. Codegen, importer, and decompiler all
73
+ // round-trip simple patterns; complex patterns survive but stay opaque.
74
+ { feature: 'destructure-native', position: 'top-level', support: 'native' },
75
+ // Slice 3e — `mapLit`/`setLit` add native top-level nodes for Map/Set
76
+ // declarations: `mapLit name=cache type="Map<string,number>"` with
77
+ // `mapEntry key=k value=v` children emits `new Map([[k, v]])`; same for
78
+ // `setLit`/`setItem`. Complex shapes (computed keys, spread, conditional
79
+ // entries) fall through to legacy `const` with handler block. Inline
80
+ // Map/Set literals inside expression-typed props still use the
81
+ // `value={{ new Map([...]) }}` escape hatch — slice 3e is statement-level
82
+ // sugar only, not a parser-grammar extension.
83
+ { feature: 'maplit-setlit-native', position: 'top-level', support: 'native' },
84
+ ];
85
+ const PY_CORE_CAPABILITIES = [
86
+ { feature: 'literal-float', position: 'expression', support: 'native' },
87
+ { feature: 'literal-numeric-separator', position: 'expression', support: 'native' },
88
+ {
89
+ feature: 'literal-bigint',
90
+ position: 'expression',
91
+ support: 'lowered',
92
+ note: 'Python int is arbitrary precision; n suffix dropped',
93
+ },
94
+ { feature: 'literal-hex', position: 'expression', support: 'native' },
95
+ { feature: 'literal-binary', position: 'expression', support: 'native' },
96
+ { feature: 'literal-octal', position: 'expression', support: 'native' },
97
+ { feature: 'literal-string-single-quote', position: 'expression', support: 'native' },
98
+ {
99
+ feature: 'optional-chain',
100
+ position: 'expression',
101
+ support: 'lowered',
102
+ note: 'lowered to (x if x is not None else None).y pattern',
103
+ },
104
+ {
105
+ feature: 'nullish-coalesce',
106
+ position: 'expression',
107
+ support: 'lowered',
108
+ note: 'lowered to x if x is not None else y',
109
+ },
110
+ { feature: 'spread', position: 'expression', support: 'lowered', note: 'lowered to *iter / **mapping' },
111
+ { feature: 'template-literal', position: 'expression', support: 'lowered', note: 'lowered to f-string' },
112
+ // Slice 1j — Python codegen has its own const path (FastAPI generator); ValueIR consumption is deferred.
113
+ {
114
+ feature: 'const-value-as-expression',
115
+ position: 'top-level',
116
+ support: 'unsupported',
117
+ note: 'Python const codegen has not yet been wired to ValueIR; bare values emit raw',
118
+ },
119
+ // Slice 2a — mapTsTypeToPython has no tuple branch yet, so a TS alias like
120
+ // `[string, number]` falls through unchanged and would emit invalid Python.
121
+ // Until lowering lands (`[T, U]` → `tuple[T, U]`), report unsupported so feature
122
+ // gates don't permit broken output.
123
+ {
124
+ feature: 'tuple-type',
125
+ position: 'top-level',
126
+ support: 'unsupported',
127
+ note: 'mapTsTypeToPython has no tuple branch; alias passthrough emits raw TS form',
128
+ },
129
+ // Slice 2b — Python has Enum class via `from enum import Enum`, but the
130
+ // FastAPI generator does not yet emit class-based enums for the `enum` node.
131
+ // Mark unsupported until that path lands; flipping to `lowered` requires a
132
+ // dedicated Python generator (would emit `class Status(str, Enum): ...`).
133
+ {
134
+ feature: 'enum-type',
135
+ position: 'top-level',
136
+ support: 'unsupported',
137
+ note: 'FastAPI codegen does not yet handle the enum node; would produce no output',
138
+ },
139
+ // Slice 2c — Python has dict[K, V] / TypedDict but the FastAPI generator
140
+ // does not yet emit either form from an `indexer` child. Mark unsupported.
141
+ {
142
+ feature: 'index-signature',
143
+ position: 'top-level',
144
+ support: 'unsupported',
145
+ note: 'FastAPI codegen does not yet handle indexer; would produce no output',
146
+ },
147
+ // Slice 2d — Python has `TypeGuard[T]` and `TypeIs[T]` (3.13+) from typing,
148
+ // but mapTsTypeToPython has no `value is T` / `asserts x is T` translation.
149
+ // Passthrough would emit invalid Python.
150
+ {
151
+ feature: 'type-guard',
152
+ position: 'top-level',
153
+ support: 'unsupported',
154
+ note: 'mapTsTypeToPython has no predicate-return-type branch (TypeGuard/TypeIs)',
155
+ },
156
+ // Slice 2e — Python has `@typing.overload` decorators, but the FastAPI
157
+ // generator does not yet emit @overload-decorated stubs from `overload`
158
+ // children.
159
+ {
160
+ feature: 'function-overloads',
161
+ position: 'top-level',
162
+ support: 'unsupported',
163
+ note: 'FastAPI codegen does not yet emit @typing.overload stubs',
164
+ },
165
+ // Slice 2f — Python has TypeVar / Generic[T] for parameterised types but
166
+ // the FastAPI generator does not yet emit `T = TypeVar("T")` / `class X(Generic[T])`.
167
+ {
168
+ feature: 'generics',
169
+ position: 'top-level',
170
+ support: 'unsupported',
171
+ note: 'FastAPI codegen does not yet emit TypeVar / Generic[T] declarations',
172
+ },
173
+ // Slice 2g — Python could in principle map `.kern → .py` via `from <module>
174
+ // import <name> as <alias>`, but the FastAPI generator has no such branch
175
+ // yet. Default to unsupported until the path is wired explicitly.
176
+ {
177
+ feature: 'cross-kern-import',
178
+ position: 'top-level',
179
+ support: 'unsupported',
180
+ note: 'FastAPI codegen does not yet translate `.kern` paths to Python `from x import y` syntax',
181
+ },
182
+ // Slice 3b — Python (FastAPI) field codegen reads `fp.default` directly
183
+ // and has no ValueIR pipeline yet, so `field.value` is unsupported until a
184
+ // dedicated Python emitter for canonicalised field initializers lands.
185
+ {
186
+ feature: 'field-native-value',
187
+ position: 'top-level',
188
+ support: 'unsupported',
189
+ note: 'FastAPI codegen has not been wired to ValueIR for field initializers; `value=` would emit raw',
190
+ },
191
+ // Slice 3c P2 follow-up (shipped) — FastAPI's 4 ad-hoc param parsers were
192
+ // consolidated behind `buildPythonParamList` in packages/fastapi/src/codegen-helpers.ts,
193
+ // which reads structured `param` children first (slice 3c+ canonical form)
194
+ // and falls back to legacy `params="..."` for back-compat. Optional `?`
195
+ // emits `Optional[T] = None`, variadic `...` emits `*args: T`, destructured
196
+ // `{a,b}` patterns are skipped (Python has no equivalent — caller unpacks
197
+ // in body).
198
+ {
199
+ feature: 'param-native-value',
200
+ position: 'top-level',
201
+ support: 'native',
202
+ note: 'FastAPI codegen wired through `buildPythonParamList` (slice 3c P2 follow-up); reads structured param children with value=/default=/optional=/variadic=',
203
+ },
204
+ // Slice 3d — Python has no native syntactic equivalent of TS object/array
205
+ // destructuring on `const`/`let`. FastAPI codegen would have to lower
206
+ // `destructure` to a sequence of bindings (`a = obj.a; b = obj.b`) which
207
+ // is a separate work item. Marked unsupported per slice 3b/3c precedent.
208
+ {
209
+ feature: 'destructure-native',
210
+ position: 'top-level',
211
+ support: 'unsupported',
212
+ note: 'FastAPI codegen has not been wired to lower `destructure` nodes; would need per-binding assignment lowering',
213
+ },
214
+ // Slice 3e — Python's `dict`/`set` literals are syntactically different
215
+ // from TS `Map`/`Set` and FastAPI codegen has not been wired to lower
216
+ // `mapLit`/`setLit` to either form. Marked unsupported per slice 3b/3c/3d
217
+ // precedent until a dedicated Python emitter exists.
218
+ {
219
+ feature: 'maplit-setlit-native',
220
+ position: 'top-level',
221
+ support: 'unsupported',
222
+ note: 'FastAPI codegen has not been wired to lower `mapLit`/`setLit` to Python `dict`/`set` literals',
223
+ },
224
+ ];
225
+ export const CAPABILITY_MATRIX = {
226
+ auto: TS_CORE_CAPABILITIES,
227
+ lib: TS_CORE_CAPABILITIES,
228
+ nextjs: TS_CORE_CAPABILITIES,
229
+ tailwind: TS_CORE_CAPABILITIES,
230
+ web: TS_CORE_CAPABILITIES,
231
+ native: TS_CORE_CAPABILITIES,
232
+ express: TS_CORE_CAPABILITIES,
233
+ cli: TS_CORE_CAPABILITIES,
234
+ terminal: TS_CORE_CAPABILITIES,
235
+ ink: TS_CORE_CAPABILITIES,
236
+ vue: TS_CORE_CAPABILITIES,
237
+ nuxt: TS_CORE_CAPABILITIES,
238
+ fastapi: PY_CORE_CAPABILITIES,
239
+ mcp: TS_CORE_CAPABILITIES,
240
+ };
241
+ export function capabilitySupport(target, feature, position) {
242
+ const entries = CAPABILITY_MATRIX[target] ?? [];
243
+ return entries.find((e) => e.feature === feature && e.position === position)?.support ?? 'unsupported';
244
+ }
245
+ //# sourceMappingURL=capability-matrix.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capability-matrix.js","sourceRoot":"","sources":["../src/capability-matrix.ts"],"names":[],"mappings":"AAAA;;iEAEiE;AAiBjE,MAAM,oBAAoB,GAAsB;IAC9C,EAAE,OAAO,EAAE,eAAe,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE;IACvE,EAAE,OAAO,EAAE,2BAA2B,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE;IACnF,EAAE,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE;IACxE,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE;IACrE,EAAE,OAAO,EAAE,gBAA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AAI,EAAE,CAAC;IAChD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,OAAO,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,CAAC,EAAE,OAAO,IAAI,aAAa,CAAC;AACzG,CAAC"}
@@ -0,0 +1,68 @@
1
+ /** Native KERN handler-body codegen — TypeScript target (slices 1–3).
2
+ *
3
+ * Walks the children of a handler with `lang=kern` and emits a TypeScript
4
+ * body string. Recognized statements:
5
+ *
6
+ * - `let name=X value="EXPR"` — `const X = EXPR;` (slice 1)
7
+ * - `return value="EXPR"` / bare `return` — `return EXPR;` (slice 1)
8
+ * - `if cond="EXPR"` / sibling `else` — `if (EXPR) { … } else { … }` (slice 2c)
9
+ *
10
+ * Statement-level propagation `?` lowers to the same hoisted shape that
11
+ * slice 7 established for raw-body propagation:
12
+ *
13
+ * const __k_t1 = await call();
14
+ * if (__k_t1.kind === 'err') return __k_t1;
15
+ * const u = __k_t1.value;
16
+ *
17
+ * Slice 3 — symmetric `{ code, imports }` shape with the Python target so
18
+ * body-emitter callers have a uniform signature regardless of language.
19
+ * TS's KERN-stdlib lowerings don't currently demand any imports (`Math` is
20
+ * global, `Set`/`Map` are global), so `imports` is typically empty. The
21
+ * `BodyEmitOptions.symbolMap` parameter is currently unused on the TS
22
+ * target — TS preserves the camelCase identifier shape end-to-end — but
23
+ * is plumbed through for parity with the Python emitter (and for any
24
+ * future TS-only renames such as reserved-word collision handling).
25
+ *
26
+ * Slice scope:
27
+ * - Result-flavored propagation only (`'err'` discriminant). Option
28
+ * propagation in native bodies is deferred to slice 8 (typecheck-driven).
29
+ * - `if` requires `cond="EXPR"`. `else` is a sibling node (no condition).
30
+ * `else if` chains land in slice 3 — for slice 2c users nest `if` inside
31
+ * the `else` branch.
32
+ *
33
+ * `gensymCounter` is local to each emit call — every handler gets its own
34
+ * fresh `__k_t1`, `__k_t2`, … sequence (same convention as slice 7).
35
+ *
36
+ * Indentation: the recursive walk threads an `indent` string so nested
37
+ * `if`/`else` branches indent correctly. The caller adds the leading indent
38
+ * for the surrounding function body. */
39
+ import type { IRNode } from '../types.js';
40
+ /** Slice 3e — caller-provided options, parity with the Python body emitter.
41
+ * `symbolMap` is currently unused on the TS target; reserved for future
42
+ * use (e.g., reserved-word renames). */
43
+ export interface BodyEmitOptions {
44
+ symbolMap?: Record<string, string>;
45
+ }
46
+ /** Slice 3e — public return shape, parity with the Python body emitter.
47
+ * TS's KERN-stdlib lowerings don't currently demand any imports; the
48
+ * `imports` set will typically be empty until a future slice introduces
49
+ * TS-stdlib entries with `requires.ts` (e.g., a `node:crypto` import). */
50
+ export interface BodyEmitResult {
51
+ code: string;
52
+ imports: Set<string>;
53
+ }
54
+ /** Emit the body of a native KERN handler as TypeScript source. Returns
55
+ * the joined body text. Each top-level line is unindented; nested
56
+ * branches indent by 2 spaces per level.
57
+ *
58
+ * Legacy slice 1/2 signature — returns just the code string. Callers
59
+ * that also need the import set (slice 3b parity with Python) should
60
+ * use `emitNativeKernBodyTSWithImports`. */
61
+ export declare function emitNativeKernBodyTS(handlerNode: IRNode, options?: BodyEmitOptions): string;
62
+ /** Slice 3e — context-aware variant returning `{ code, imports }`.
63
+ * TS's KERN-stdlib lowerings don't currently demand any imports; the
64
+ * `imports` set will typically be empty until a future slice introduces
65
+ * TS-stdlib entries with `requires.ts` (e.g., a `node:crypto` import).
66
+ * Provided for symmetry with the Python target so generators that drive
67
+ * both languages have a uniform call shape. */
68
+ export declare function emitNativeKernBodyTSWithImports(handlerNode: IRNode, _options?: BodyEmitOptions): BodyEmitResult;
@@ -0,0 +1,214 @@
1
+ /** Native KERN handler-body codegen — TypeScript target (slices 1–3).
2
+ *
3
+ * Walks the children of a handler with `lang=kern` and emits a TypeScript
4
+ * body string. Recognized statements:
5
+ *
6
+ * - `let name=X value="EXPR"` — `const X = EXPR;` (slice 1)
7
+ * - `return value="EXPR"` / bare `return` — `return EXPR;` (slice 1)
8
+ * - `if cond="EXPR"` / sibling `else` — `if (EXPR) { … } else { … }` (slice 2c)
9
+ *
10
+ * Statement-level propagation `?` lowers to the same hoisted shape that
11
+ * slice 7 established for raw-body propagation:
12
+ *
13
+ * const __k_t1 = await call();
14
+ * if (__k_t1.kind === 'err') return __k_t1;
15
+ * const u = __k_t1.value;
16
+ *
17
+ * Slice 3 — symmetric `{ code, imports }` shape with the Python target so
18
+ * body-emitter callers have a uniform signature regardless of language.
19
+ * TS's KERN-stdlib lowerings don't currently demand any imports (`Math` is
20
+ * global, `Set`/`Map` are global), so `imports` is typically empty. The
21
+ * `BodyEmitOptions.symbolMap` parameter is currently unused on the TS
22
+ * target — TS preserves the camelCase identifier shape end-to-end — but
23
+ * is plumbed through for parity with the Python emitter (and for any
24
+ * future TS-only renames such as reserved-word collision handling).
25
+ *
26
+ * Slice scope:
27
+ * - Result-flavored propagation only (`'err'` discriminant). Option
28
+ * propagation in native bodies is deferred to slice 8 (typecheck-driven).
29
+ * - `if` requires `cond="EXPR"`. `else` is a sibling node (no condition).
30
+ * `else if` chains land in slice 3 — for slice 2c users nest `if` inside
31
+ * the `else` branch.
32
+ *
33
+ * `gensymCounter` is local to each emit call — every handler gets its own
34
+ * fresh `__k_t1`, `__k_t2`, … sequence (same convention as slice 7).
35
+ *
36
+ * Indentation: the recursive walk threads an `indent` string so nested
37
+ * `if`/`else` branches indent correctly. The caller adds the leading indent
38
+ * for the surrounding function body. */
39
+ import { emitExpression } from '../codegen-expression.js';
40
+ import { parseExpression } from '../parser-expression.js';
41
+ const INDENT_STEP = ' ';
42
+ /** Emit the body of a native KERN handler as TypeScript source. Returns
43
+ * the joined body text. Each top-level line is unindented; nested
44
+ * branches indent by 2 spaces per level.
45
+ *
46
+ * Legacy slice 1/2 signature — returns just the code string. Callers
47
+ * that also need the import set (slice 3b parity with Python) should
48
+ * use `emitNativeKernBodyTSWithImports`. */
49
+ export function emitNativeKernBodyTS(handlerNode, options) {
50
+ return emitNativeKernBodyTSWithImports(handlerNode, options).code;
51
+ }
52
+ /** Slice 3e — context-aware variant returning `{ code, imports }`.
53
+ * TS's KERN-stdlib lowerings don't currently demand any imports; the
54
+ * `imports` set will typically be empty until a future slice introduces
55
+ * TS-stdlib entries with `requires.ts` (e.g., a `node:crypto` import).
56
+ * Provided for symmetry with the Python target so generators that drive
57
+ * both languages have a uniform call shape. */
58
+ export function emitNativeKernBodyTSWithImports(handlerNode, _options) {
59
+ const ctx = { gensymCounter: 0, tryDepth: 0 };
60
+ const code = emitChildrenTS(handlerNode.children ?? [], ctx, '').join('\n');
61
+ return { code, imports: new Set() };
62
+ }
63
+ function emitChildrenTS(children, ctx, indent) {
64
+ const lines = [];
65
+ for (let i = 0; i < children.length; i++) {
66
+ const child = children[i];
67
+ if (child.type === 'let') {
68
+ for (const line of emitLetTS(child, ctx))
69
+ lines.push(`${indent}${line}`);
70
+ }
71
+ else if (child.type === 'return') {
72
+ for (const line of emitReturnTS(child, ctx))
73
+ lines.push(`${indent}${line}`);
74
+ }
75
+ else if (child.type === 'if') {
76
+ const condRaw = String(child.props?.cond ?? '');
77
+ const condIR = parseExpression(condRaw);
78
+ // Slice-2 review fix: propagation `?` in an `if` condition has no
79
+ // sensible single-line lowering; reject early with a clear message
80
+ // pointing users at the let-bind workaround.
81
+ if (condIR.kind === 'propagate') {
82
+ throw new Error("Propagation '?' is not allowed in `if cond=` — bind the call to a `let` first, then test the bound name.");
83
+ }
84
+ lines.push(`${indent}if (${emitExpression(condIR)}) {`);
85
+ for (const sl of emitChildrenTS(child.children ?? [], ctx, indent + INDENT_STEP))
86
+ lines.push(sl);
87
+ const next = children[i + 1];
88
+ if (next && next.type === 'else') {
89
+ lines.push(`${indent}} else {`);
90
+ for (const el of emitChildrenTS(next.children ?? [], ctx, indent + INDENT_STEP))
91
+ lines.push(el);
92
+ i++;
93
+ }
94
+ lines.push(`${indent}}`);
95
+ }
96
+ else if (child.type === 'else') {
97
+ // Slice-2 review fix: orphan `else` (without a preceding `if` sibling)
98
+ // is a structural error — silently dropping it produced confusing
99
+ // miscompiles. The `if` arm above consumes its paired `else` via i++,
100
+ // so reaching one here means it was orphaned.
101
+ throw new Error('`else` must immediately follow an `if` sibling. Found orphan `else` in handler body.');
102
+ }
103
+ else if (child.type === 'try') {
104
+ // Slice 4c — try/catch control flow.
105
+ // Slice 4c review fix (OpenCode + Gemini high): orphan `try` produces
106
+ // a syntactically-incomplete body. Both TS (no-catch try is legal but
107
+ // semantically wrong) and Python (SyntaxError) need a paired catch;
108
+ // require the sibling and fail loud if missing.
109
+ const next = children[i + 1];
110
+ if (!next || next.type !== 'catch') {
111
+ throw new Error('`try` must be immediately followed by a `catch` sibling. Found orphan `try` in handler body.');
112
+ }
113
+ lines.push(`${indent}try {`);
114
+ ctx.tryDepth++;
115
+ for (const sl of emitChildrenTS(child.children ?? [], ctx, indent + INDENT_STEP))
116
+ lines.push(sl);
117
+ ctx.tryDepth--;
118
+ const errName = String(next.props?.name ?? 'e');
119
+ lines.push(`${indent}} catch (${errName}) {`);
120
+ for (const cl of emitChildrenTS(next.children ?? [], ctx, indent + INDENT_STEP))
121
+ lines.push(cl);
122
+ i++;
123
+ lines.push(`${indent}}`);
124
+ }
125
+ else if (child.type === 'catch') {
126
+ throw new Error('`catch` must immediately follow a `try` sibling. Found orphan `catch` in handler body.');
127
+ }
128
+ else if (child.type === 'throw') {
129
+ // Slice 4c — throw statement.
130
+ for (const line of emitThrowTS(child, ctx))
131
+ lines.push(`${indent}${line}`);
132
+ }
133
+ else if (child.type === 'each') {
134
+ // Slice 4d — each loop.
135
+ // Slice 4c+4d review fix (Codex P1): the schema's `each` already
136
+ // declares `name` (binding) and `in` (iterable expression). The
137
+ // earlier slice-4d body-emit read `list`/`as` instead, which meant
138
+ // (a) schema-validated source `each name=x in=items` fell back to
139
+ // `for (const item of [])` (empty list, wrong binding) and
140
+ // (b) tests that used `list`/`as` failed schema validation.
141
+ // Read schema-compliant `name`/`in` first; accept legacy
142
+ // `list`/`as` as a fallback for tests that pre-date this fix.
143
+ const listRaw = String(child.props?.in ?? child.props?.list ?? '[]');
144
+ const asName = String(child.props?.name ?? child.props?.as ?? 'item');
145
+ const listIR = parseExpression(listRaw);
146
+ lines.push(`${indent}for (const ${asName} of ${emitExpression(listIR)}) {`);
147
+ for (const sl of emitChildrenTS(child.children ?? [], ctx, indent + INDENT_STEP))
148
+ lines.push(sl);
149
+ lines.push(`${indent}}`);
150
+ }
151
+ // Other child types fall through silently — slice 3 adds more.
152
+ }
153
+ return lines;
154
+ }
155
+ /** Slice 4c review fix (OpenCode + Gemini critical) — propagation `?`
156
+ * inside a `try` block has no clean lowering. The hoisted err-branch
157
+ * emits `return tmp` which exits the function entirely, BYPASSING the
158
+ * enclosing `catch`. That's almost never what users mean — they wrote
159
+ * `?` to flag a Result.err and (presumably) to let the catch handle
160
+ * it. Reject at codegen with a let-bind hint. Same shape as
161
+ * slice-2's reject-`?`-in-`if-cond` rule. */
162
+ function rejectPropagationInsideTry(ctx) {
163
+ if (ctx.tryDepth > 0) {
164
+ throw new Error("Propagation '?' is not allowed inside a `try` block — `return` from the err branch exits the function and bypasses the enclosing `catch`. " +
165
+ 'Bind the call to a `let` outside the try, then use `if x.kind === "err" throw new Error(...)` inside the try, OR use raw `lang=ts`/`lang=python` for the affected handler.');
166
+ }
167
+ }
168
+ function emitLetTS(node, ctx) {
169
+ const props = (node.props ?? {});
170
+ const name = String(props.name ?? '_');
171
+ const rawValue = props.value;
172
+ if (rawValue === undefined || rawValue === '') {
173
+ return [`const ${name} = undefined;`];
174
+ }
175
+ const valueIR = parseExpression(String(rawValue));
176
+ if (valueIR.kind === 'propagate' && valueIR.op === '?') {
177
+ rejectPropagationInsideTry(ctx);
178
+ const tmp = `__k_t${++ctx.gensymCounter}`;
179
+ const inner = emitExpression(valueIR.argument);
180
+ return [`const ${tmp} = ${inner};`, `if (${tmp}.kind === 'err') return ${tmp};`, `const ${name} = ${tmp}.value;`];
181
+ }
182
+ return [`const ${name} = ${emitExpression(valueIR)};`];
183
+ }
184
+ function emitReturnTS(node, ctx) {
185
+ const props = (node.props ?? {});
186
+ const rawValue = props.value;
187
+ if (rawValue === undefined || rawValue === '') {
188
+ return [`return;`];
189
+ }
190
+ const valueIR = parseExpression(String(rawValue));
191
+ if (valueIR.kind === 'propagate' && valueIR.op === '?') {
192
+ rejectPropagationInsideTry(ctx);
193
+ const tmp = `__k_t${++ctx.gensymCounter}`;
194
+ const inner = emitExpression(valueIR.argument);
195
+ return [`const ${tmp} = ${inner};`, `if (${tmp}.kind === 'err') return ${tmp};`, `return ${tmp}.value;`];
196
+ }
197
+ return [`return ${emitExpression(valueIR)};`];
198
+ }
199
+ function emitThrowTS(node, ctx) {
200
+ const props = (node.props ?? {});
201
+ const rawValue = props.value;
202
+ if (rawValue === undefined || rawValue === '') {
203
+ return [`throw new Error();`];
204
+ }
205
+ const valueIR = parseExpression(String(rawValue));
206
+ if (valueIR.kind === 'propagate' && valueIR.op === '?') {
207
+ rejectPropagationInsideTry(ctx);
208
+ const tmp = `__k_t${++ctx.gensymCounter}`;
209
+ const inner = emitExpression(valueIR.argument);
210
+ return [`const ${tmp} = ${inner};`, `if (${tmp}.kind === 'err') return ${tmp};`, `throw ${tmp}.value;`];
211
+ }
212
+ return [`throw ${emitExpression(valueIR)};`];
213
+ }
214
+ //# sourceMappingURL=body-ts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"body-ts.js","sourceRoot":"","sources":["../../src/codegen/body-ts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAqCyC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AA8B1D,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB;;;;;;6CAM6C;AAC7C,MAAM,UAAU,oBAAoB,CAAC,WAAmB,EAAE,OAAyB;IACjF,OAAO,+BAA+B,CAAC,WAAW,EAA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IACD,OAAO,CAAC,SAAS,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAC/C,CAAC"}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * Extracted from codegen-core.ts for modular codegen architecture.
5
5
  */
6
- import type { IRNode } from '../types.js';
6
+ import { type IRNode } from '../types.js';
7
7
  export declare function generateConfig(node: IRNode): string[];
8
8
  export declare function generateStore(node: IRNode): string[];
9
9
  export declare function generateRepository(node: IRNode): string[];