@scriptc/compiler 0.0.0 → 0.0.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 (206) hide show
  1. package/LICENSE +202 -0
  2. package/ambient/package.json +3 -0
  3. package/ambient/scriptc-node-fallback.d.ts +3001 -0
  4. package/ambient/scriptc-overrides.d.ts +95 -0
  5. package/ambient/scriptc.d.ts +74 -0
  6. package/dist/backend/cc.d.ts +169 -0
  7. package/dist/backend/cc.js +897 -0
  8. package/dist/backend/cc.js.map +1 -0
  9. package/dist/backend/emission/emit-async.d.ts +145 -0
  10. package/dist/backend/emission/emit-async.js +996 -0
  11. package/dist/backend/emission/emit-async.js.map +1 -0
  12. package/dist/backend/emission/emit-exprs.d.ts +3 -0
  13. package/dist/backend/emission/emit-exprs.js +5947 -0
  14. package/dist/backend/emission/emit-exprs.js.map +1 -0
  15. package/dist/backend/emission/emit-island.d.ts +45 -0
  16. package/dist/backend/emission/emit-island.js +271 -0
  17. package/dist/backend/emission/emit-island.js.map +1 -0
  18. package/dist/backend/emission/emit-shapes.d.ts +142 -0
  19. package/dist/backend/emission/emit-shapes.js +575 -0
  20. package/dist/backend/emission/emit-shapes.js.map +1 -0
  21. package/dist/backend/emission/emit-stmts.d.ts +78 -0
  22. package/dist/backend/emission/emit-stmts.js +960 -0
  23. package/dist/backend/emission/emit-stmts.js.map +1 -0
  24. package/dist/backend/emission/emit-types.d.ts +65 -0
  25. package/dist/backend/emission/emit-types.js +652 -0
  26. package/dist/backend/emission/emit-types.js.map +1 -0
  27. package/dist/backend/emission/emit-walkers.d.ts +154 -0
  28. package/dist/backend/emission/emit-walkers.js +1587 -0
  29. package/dist/backend/emission/emit-walkers.js.map +1 -0
  30. package/dist/backend/emission/emitter.d.ts +452 -0
  31. package/dist/backend/emission/emitter.js +1249 -0
  32. package/dist/backend/emission/emitter.js.map +1 -0
  33. package/dist/backend/emission/may-throw.d.ts +15 -0
  34. package/dist/backend/emission/may-throw.js +250 -0
  35. package/dist/backend/emission/may-throw.js.map +1 -0
  36. package/dist/backend/llvm/blocks.d.ts +21 -0
  37. package/dist/backend/llvm/blocks.js +68 -0
  38. package/dist/backend/llvm/blocks.js.map +1 -0
  39. package/dist/backend/llvm/classes.d.ts +84 -0
  40. package/dist/backend/llvm/classes.js +438 -0
  41. package/dist/backend/llvm/classes.js.map +1 -0
  42. package/dist/backend/llvm/dyn.d.ts +123 -0
  43. package/dist/backend/llvm/dyn.js +2624 -0
  44. package/dist/backend/llvm/dyn.js.map +1 -0
  45. package/dist/backend/llvm/emitter.d.ts +3 -0
  46. package/dist/backend/llvm/emitter.js +10087 -0
  47. package/dist/backend/llvm/emitter.js.map +1 -0
  48. package/dist/backend/llvm/shapes.d.ts +78 -0
  49. package/dist/backend/llvm/shapes.js +754 -0
  50. package/dist/backend/llvm/shapes.js.map +1 -0
  51. package/dist/backend/llvm/unsupported.d.ts +6 -0
  52. package/dist/backend/llvm/unsupported.js +12 -0
  53. package/dist/backend/llvm/unsupported.js.map +1 -0
  54. package/dist/backend/llvm/walkers.d.ts +58 -0
  55. package/dist/backend/llvm/walkers.js +793 -0
  56. package/dist/backend/llvm/walkers.js.map +1 -0
  57. package/dist/backend/mangle.d.ts +124 -0
  58. package/dist/backend/mangle.js +232 -0
  59. package/dist/backend/mangle.js.map +1 -0
  60. package/dist/coverage/report.d.ts +64 -0
  61. package/dist/coverage/report.js +226 -0
  62. package/dist/coverage/report.js.map +1 -0
  63. package/dist/diagnostics/diagnostic.d.ts +140 -0
  64. package/dist/diagnostics/diagnostic.js +458 -0
  65. package/dist/diagnostics/diagnostic.js.map +1 -0
  66. package/dist/diagnostics/render.d.ts +11 -0
  67. package/dist/diagnostics/render.js +58 -0
  68. package/dist/diagnostics/render.js.map +1 -0
  69. package/dist/frontend/cjs-lexer.d.ts +20 -0
  70. package/dist/frontend/cjs-lexer.js +813 -0
  71. package/dist/frontend/cjs-lexer.js.map +1 -0
  72. package/dist/frontend/lowering/http2-constants.d.ts +1 -0
  73. package/dist/frontend/lowering/http2-constants.js +251 -0
  74. package/dist/frontend/lowering/http2-constants.js.map +1 -0
  75. package/dist/frontend/lowering/lib-boundary.d.ts +6 -0
  76. package/dist/frontend/lowering/lib-boundary.js +143 -0
  77. package/dist/frontend/lowering/lib-boundary.js.map +1 -0
  78. package/dist/frontend/lowering/lower-assert.d.ts +18 -0
  79. package/dist/frontend/lowering/lower-assert.js +1269 -0
  80. package/dist/frontend/lowering/lower-assert.js.map +1 -0
  81. package/dist/frontend/lowering/lower-builtins.d.ts +511 -0
  82. package/dist/frontend/lowering/lower-builtins.js +5249 -0
  83. package/dist/frontend/lowering/lower-builtins.js.map +1 -0
  84. package/dist/frontend/lowering/lower-calls.d.ts +581 -0
  85. package/dist/frontend/lowering/lower-calls.js +6281 -0
  86. package/dist/frontend/lowering/lower-calls.js.map +1 -0
  87. package/dist/frontend/lowering/lower-classes.d.ts +727 -0
  88. package/dist/frontend/lowering/lower-classes.js +4701 -0
  89. package/dist/frontend/lowering/lower-classes.js.map +1 -0
  90. package/dist/frontend/lowering/lower-comptime.d.ts +53 -0
  91. package/dist/frontend/lowering/lower-comptime.js +244 -0
  92. package/dist/frontend/lowering/lower-comptime.js.map +1 -0
  93. package/dist/frontend/lowering/lower-containers.d.ts +483 -0
  94. package/dist/frontend/lowering/lower-containers.js +6281 -0
  95. package/dist/frontend/lowering/lower-containers.js.map +1 -0
  96. package/dist/frontend/lowering/lower-dgram.d.ts +20 -0
  97. package/dist/frontend/lowering/lower-dgram.js +319 -0
  98. package/dist/frontend/lowering/lower-dgram.js.map +1 -0
  99. package/dist/frontend/lowering/lower-emitter.d.ts +10 -0
  100. package/dist/frontend/lowering/lower-emitter.js +688 -0
  101. package/dist/frontend/lowering/lower-emitter.js.map +1 -0
  102. package/dist/frontend/lowering/lower-enums.d.ts +22 -0
  103. package/dist/frontend/lowering/lower-enums.js +235 -0
  104. package/dist/frontend/lowering/lower-enums.js.map +1 -0
  105. package/dist/frontend/lowering/lower-expando.d.ts +35 -0
  106. package/dist/frontend/lowering/lower-expando.js +276 -0
  107. package/dist/frontend/lowering/lower-expando.js.map +1 -0
  108. package/dist/frontend/lowering/lower-exprs.d.ts +524 -0
  109. package/dist/frontend/lowering/lower-exprs.js +8099 -0
  110. package/dist/frontend/lowering/lower-exprs.js.map +1 -0
  111. package/dist/frontend/lowering/lower-generators.d.ts +50 -0
  112. package/dist/frontend/lowering/lower-generators.js +421 -0
  113. package/dist/frontend/lowering/lower-generators.js.map +1 -0
  114. package/dist/frontend/lowering/lower-inspect.d.ts +20 -0
  115. package/dist/frontend/lowering/lower-inspect.js +1069 -0
  116. package/dist/frontend/lowering/lower-inspect.js.map +1 -0
  117. package/dist/frontend/lowering/lower-island.d.ts +108 -0
  118. package/dist/frontend/lowering/lower-island.js +650 -0
  119. package/dist/frontend/lowering/lower-island.js.map +1 -0
  120. package/dist/frontend/lowering/lower-mixins.d.ts +96 -0
  121. package/dist/frontend/lowering/lower-mixins.js +534 -0
  122. package/dist/frontend/lowering/lower-mixins.js.map +1 -0
  123. package/dist/frontend/lowering/lower-modules.d.ts +135 -0
  124. package/dist/frontend/lowering/lower-modules.js +1613 -0
  125. package/dist/frontend/lowering/lower-modules.js.map +1 -0
  126. package/dist/frontend/lowering/lower-namespaces.d.ts +168 -0
  127. package/dist/frontend/lowering/lower-namespaces.js +706 -0
  128. package/dist/frontend/lowering/lower-namespaces.js.map +1 -0
  129. package/dist/frontend/lowering/lower-server.d.ts +90 -0
  130. package/dist/frontend/lowering/lower-server.js +3471 -0
  131. package/dist/frontend/lowering/lower-server.js.map +1 -0
  132. package/dist/frontend/lowering/lower-stmts.d.ts +361 -0
  133. package/dist/frontend/lowering/lower-stmts.js +5341 -0
  134. package/dist/frontend/lowering/lower-stmts.js.map +1 -0
  135. package/dist/frontend/lowering/lower-stream.d.ts +88 -0
  136. package/dist/frontend/lowering/lower-stream.js +1533 -0
  137. package/dist/frontend/lowering/lower-stream.js.map +1 -0
  138. package/dist/frontend/lowering/lower-test.d.ts +27 -0
  139. package/dist/frontend/lowering/lower-test.js +353 -0
  140. package/dist/frontend/lowering/lower-test.js.map +1 -0
  141. package/dist/frontend/lowering/lowerer.d.ts +1748 -0
  142. package/dist/frontend/lowering/lowerer.js +6256 -0
  143. package/dist/frontend/lowering/lowerer.js.map +1 -0
  144. package/dist/frontend/lowering/surfaces.d.ts +272 -0
  145. package/dist/frontend/lowering/surfaces.js +1096 -0
  146. package/dist/frontend/lowering/surfaces.js.map +1 -0
  147. package/dist/frontend/npm-static.d.ts +55 -0
  148. package/dist/frontend/npm-static.js +300 -0
  149. package/dist/frontend/npm-static.js.map +1 -0
  150. package/dist/frontend/npm.d.ts +330 -0
  151. package/dist/frontend/npm.js +1259 -0
  152. package/dist/frontend/npm.js.map +1 -0
  153. package/dist/frontend/program.d.ts +186 -0
  154. package/dist/frontend/program.js +2172 -0
  155. package/dist/frontend/program.js.map +1 -0
  156. package/dist/frontend/provenance-registry.d.ts +48 -0
  157. package/dist/frontend/provenance-registry.js +87 -0
  158. package/dist/frontend/provenance-registry.js.map +1 -0
  159. package/dist/frontend/provenance.d.ts +6 -0
  160. package/dist/frontend/provenance.js +459 -0
  161. package/dist/frontend/provenance.js.map +1 -0
  162. package/dist/frontend/resolve.d.ts +56 -0
  163. package/dist/frontend/resolve.js +682 -0
  164. package/dist/frontend/resolve.js.map +1 -0
  165. package/dist/frontend/shared.d.ts +60 -0
  166. package/dist/frontend/shared.js +232 -0
  167. package/dist/frontend/shared.js.map +1 -0
  168. package/dist/frontend/ts7/adapter.d.ts +7 -0
  169. package/dist/frontend/ts7/adapter.js +54 -0
  170. package/dist/frontend/ts7/adapter.js.map +1 -0
  171. package/dist/frontend/ts7/ast.d.ts +50 -0
  172. package/dist/frontend/ts7/ast.js +211 -0
  173. package/dist/frontend/ts7/ast.js.map +1 -0
  174. package/dist/frontend/ts7/census-check.d.ts +1 -0
  175. package/dist/frontend/ts7/census-check.js +12 -0
  176. package/dist/frontend/ts7/census-check.js.map +1 -0
  177. package/dist/frontend/ts7/checker.d.ts +140 -0
  178. package/dist/frontend/ts7/checker.js +544 -0
  179. package/dist/frontend/ts7/checker.js.map +1 -0
  180. package/dist/frontend/ts7/enums.d.ts +18 -0
  181. package/dist/frontend/ts7/enums.js +43 -0
  182. package/dist/frontend/ts7/enums.js.map +1 -0
  183. package/dist/frontend/ts7/program.d.ts +99 -0
  184. package/dist/frontend/ts7/program.js +278 -0
  185. package/dist/frontend/ts7/program.js.map +1 -0
  186. package/dist/frontend/ts7/world-check.d.ts +3 -0
  187. package/dist/frontend/ts7/world-check.js +34 -0
  188. package/dist/frontend/ts7/world-check.js.map +1 -0
  189. package/dist/frontend/types.d.ts +205 -0
  190. package/dist/frontend/types.js +2485 -0
  191. package/dist/frontend/types.js.map +1 -0
  192. package/dist/index.d.ts +85 -0
  193. package/dist/index.js +424 -0
  194. package/dist/index.js.map +1 -0
  195. package/dist/ir/nodes.d.ts +4334 -0
  196. package/dist/ir/nodes.js +1906 -0
  197. package/dist/ir/nodes.js.map +1 -0
  198. package/dist/ir/serialize.d.ts +4 -0
  199. package/dist/ir/serialize.js +34 -0
  200. package/dist/ir/serialize.js.map +1 -0
  201. package/dist/ir/validate.d.ts +36 -0
  202. package/dist/ir/validate.js +4884 -0
  203. package/dist/ir/validate.js.map +1 -0
  204. package/package.json +30 -6
  205. package/README.md +0 -3
  206. package/index.js +0 -2
@@ -0,0 +1,483 @@
1
+ import * as ts from "../ts7/adapter.js";
2
+ import type { Lowerer } from "./lowerer.js";
3
+ import { IrExpr, IrFunction, IrRecordShape, IrStmt, IrType, SrcLoc } from "../../ir/nodes.js";
4
+ /** Ambient array method calls. `push`/`pop`/`indexOf`/`includes`/`join`
5
+ * lower to arrIntrinsic; the HOF family — `map`/`filter`/`forEach`/
6
+ * `find`/`some`/`every`/`flatMap`/`reduce`/`reduceRight` — desugars to a
7
+ * direct call of a synthetic loop function (see lowerArrayHofCall and
8
+ * friends). Null when this isn't an ambient array method call. tsc has
9
+ * already checked arity and argument types against ambient/scriptc.d.ts. */
10
+ export declare function lowerArrayMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
11
+ /** `a.map(fn)` / `a.filter(fn)` / `a.forEach(fn)` desugar to a direct
12
+ * call of a synthetic module function — one per method + element/result
13
+ * type + callback-arity combination, interned — whose body is a plain
14
+ * loop over EXISTING IR nodes (varDecl/for/arrayGet/callValue/push/
15
+ * return). No new IR kinds, no backend or runtime involvement. JS
16
+ * semantics: the length is read ONCE up front (Array.prototype.map/
17
+ * filter/forEach cache it — elements appended by the callback are not
18
+ * visited), elements are read fresh each iteration, callbacks run
19
+ * left-to-right and receive whatever prefix of (element, index, array)
20
+ * they declare. */
21
+ export declare function lowerArrayHofCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, method: "map" | "filter" | "forEach", elem: IrType): IrExpr;
22
+ /** Interned synthetic loop function for one (method, elem, fnRet, arity)
23
+ * combo. Named `%arr.<method>.<n>` ('%' keeps it out of the user
24
+ * namespace); rides `liftedFns` into the module like a lifted lambda (it
25
+ * is a plain function — no captures). */
26
+ export declare function arrayHofHelper(L: Lowerer, method: "map" | "filter" | "forEach", elem: IrType, fnRet: IrType, arity: number, loc: SrcLoc): string;
27
+ /** READ-ONLY array methods on TUPLE receivers — `t.slice(...)` and
28
+ * `t.map(f)`: a tuple is a fixed-shape record, but these methods never
29
+ * write, so the positions snapshot into a fresh array (the for-of-over-
30
+ * tuples stance — pure receivers only, since the reads re-emit per
31
+ * position) and the ordinary array machinery runs over it. The element
32
+ * type is the one position type, or the positions' interned union with
33
+ * each read wrapped into its arm (exactly the checker's callback
34
+ * parameter type). Null when this isn't a tuple slice/map — writers and
35
+ * the rest of the surface keep their fences. */
36
+ export declare function lowerTupleReadMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
37
+ /** The OOB-SAFE indexed read for --npm-static package files: `xs[i]`
38
+ * answers the interned `elem | undefined` union — the element when `i`
39
+ * is an integer in [0, len), JS's property-miss undefined otherwise —
40
+ * instead of the trap divergence 4 documents for program code.
41
+ * Package JS is inference-typed, guard-style code (`registeredArguments
42
+ * .slice(-1)[0]`, commander's last-element probe), and the trap would
43
+ * fire on working Node idioms; program files keep the documented trap
44
+ * (their annotations can prove bounds). Null when the element is
45
+ * union-typed (the re-tag has no story here) — the caller keeps the
46
+ * ordinary read. */
47
+ export declare function lowerNpmStaticSafeIndexRead(L: Lowerer, arr: IrExpr & {
48
+ type: {
49
+ kind: "array";
50
+ };
51
+ }, index: IrExpr, loc: SrcLoc): IrExpr | null;
52
+ /** Interned synthetic function for one (elem, argument-shape) concat —
53
+ * `%arr.concat.<n>(a, x0, x1, ...)`: a fresh array takes a's elements
54
+ * (pushSpread), then each argument pushes (element) or spreads (array)
55
+ * in order; the receiver and array arguments are only READ. Rides
56
+ * liftedFns like the HOF helpers (a plain function — no captures). */
57
+ export declare function arrayConcatHelper(L: Lowerer, elem: IrType, shape: ("e" | "a")[], loc: SrcLoc): string;
58
+ /** The loop body of one synthetic array HOF, from existing IR nodes:
59
+ *
60
+ * map: out = []; n = a.length; for (i = 0; i < n; i++) out.push(f(a[i])); return out;
61
+ * filter: out = []; n = a.length; for (...) { v = a[i]; if (f(v)) out.push(v); } return out;
62
+ * forEach: n = a.length; for (...) f(a[i]);
63
+ *
64
+ * `filter` reads the element once into `v` so the callback and the push
65
+ * see the same value even if the callback mutates `a[i]` (JS-exact).
66
+ * `arity` is the callback's declared parameter count (1–3): the loop
67
+ * passes the index and the receiver itself after the element when the
68
+ * callback names them, exactly the arguments JS supplies. */
69
+ export declare function buildArrayHofFn(L: Lowerer, name: string, method: "map" | "filter" | "forEach", elem: IrType, fnRet: IrType, arity: number, loc: SrcLoc): IrFunction;
70
+ /** `a.find(f)` / `a.findIndex(f)` / `a.findLast(f)` / `a.findLastIndex(f)`
71
+ * / `a.some(f)` / `a.every(f)` — the early-return HOFs, same
72
+ * desugar-to-loop machinery. some/every return bool from a short-circuit
73
+ * loop; findIndex/findLastIndex return the first matching index or -1
74
+ * (plain f64 — no union). find/findLast return `T | undefined` — the
75
+ * checker's own result union —
76
+ * with the found element wrapped into its arm and the miss producing the
77
+ * undefined unit arm (for REF elements that arm is the unit instance, the
78
+ * standard union machinery). The Last pair is the SAME loop walked
79
+ * backwards (`i = n - 1; i >= 0; i--`), exactly the es2023 spec's
80
+ * descending index walk. All require a bool-returning callback
81
+ * (JS's ToBoolean of arbitrary predicate results has no lowering). */
82
+ export declare function lowerArrayFindLikeCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, method: "find" | "findIndex" | "findLast" | "findLastIndex" | "some" | "every", elem: IrType): IrExpr;
83
+ /** `a.flatMap(f)` — map plus a one-level flatten. A callback returning
84
+ * `U[]` appends the returned array's elements per receiver element; a
85
+ * callback returning a non-array U doesn't flatten (JS pushes it as-is),
86
+ * which IS map — those calls share map's interned helper. A union return
87
+ * mixing array and non-array arms would need a per-value flatten decision
88
+ * — fenced. */
89
+ export declare function lowerArrayFlatMapCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, elem: IrType): IrExpr;
90
+ /** `a.reduce(f)` / `a.reduce(f, init)` and reduceRight — both declared
91
+ * forms. The accumulator type is the call's own checked result: U with an
92
+ * initial value, the element type without one. The callback may declare
93
+ * any prefix of (acc, element, index, array). Without an initial value an
94
+ * empty receiver throws Node's exact TypeError at runtime. */
95
+ export declare function lowerArrayReduceCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, method: "reduce" | "reduceRight", elem: IrType): IrExpr;
96
+ /** `a.sort(cmp)` — in-place, returns the receiver (JS's `this`), desugared
97
+ * to an interned synthetic function like the other array HOFs. The loop
98
+ * is a binary-free INSERTION sort: stable (equal-comparing elements keep
99
+ * their source order, which is what Node's stable TimSort produces for
100
+ * any consistent comparator) and JS-faithful on the comparator contract —
101
+ * an element moves left only while cmp(left, v) > 0, so a NaN or 0
102
+ * result holds position exactly like the spec's "treat as equal". The
103
+ * SEQUENCE of comparator calls differs from V8's TimSort (SEMANTICS.md);
104
+ * results are identical for consistent comparators. The comparator-less
105
+ * form lowers for STRING elements only — JS's default converts every
106
+ * element to string and compares UTF-16 units, which for strings is the
107
+ * relational operator the compiler already has (an interned synthesized
108
+ * comparator); for numbers that default is the notorious string sort
109
+ * ([10, 9, 1] → [1, 10, 9]), deliberately fenced toward an explicit
110
+ * comparator. */
111
+ export declare function lowerArraySortCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, elem: IrType, arrT: IrType & {
112
+ kind: "array";
113
+ }): IrExpr;
114
+ /** `a.at(i)` — the es2022 relative-index read. Desugars to an interned
115
+ * helper over existing IR nodes, ToIntegerOrInfinity-exact: the index
116
+ * truncates toward zero (floor for non-negatives, mirrored floor for
117
+ * negatives, NaN → 0), negatives wrap by the length once, and anything
118
+ * still outside [0, n) answers the undefined arm — never a bounds throw.
119
+ * The result is the checker's own `T | undefined` union, the find
120
+ * machinery's wrap rules (an undefined-armed element type passes
121
+ * through). */
122
+ export declare function lowerArrayAtCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, elem: IrType): IrExpr;
123
+ /** `Array.from({ length: n }, mapfn)` — the counted-generation idiom — on
124
+ * THE stdlib Array global. The source must be an OBJECT LITERAL whose
125
+ * single property is `length` (the shape the idiom always spells; the
126
+ * ArrayLike record never exists as a value). Desugars to an interned
127
+ * synthetic loop calling the mapper with (undefined, i) exactly like JS —
128
+ * the first argument is the dyn undefined singleton, matching the
129
+ * checker's own `unknown` for it — and pushing each result. The loop
130
+ * bound is `i <= n - 1`, which IS ToLength for the finite lengths that
131
+ * terminate (fractional lengths truncate, negative/NaN produce an empty
132
+ * array — Node-exact). Every other Array.from shape (arrays, iterables,
133
+ * no mapper) keeps the fence. Null when the callee isn't an
134
+ * Array-static access. */
135
+ export declare function lowerArrayFromCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
136
+ /** Ambient Map method calls. `get`/`set`/`has`/`delete`/`clear` lower to
137
+ * mapIntrinsic; `forEach` desugars to a direct call of a synthetic loop
138
+ * function over the iteration primitives (lowerMapForEachCall). Null when
139
+ * this isn't an ambient Map method call. tsc has already checked arity
140
+ * and argument types against ambient/scriptc.d.ts. */
141
+ export declare function lowerMapMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
142
+ /** `m.forEach(fn)` desugars to a direct call of a synthetic module
143
+ * function — one per key/value type + callback arity, interned — whose
144
+ * body is an index loop over the map's ITERATION PRIMITIVES: read
145
+ * iterCount fresh every pass (entries appended by the callback are
146
+ * visited), skip tombstones with iterLive (deleted entries are skipped),
147
+ * and bracket the loop with iterEnter/iterExit inside try/finally so the
148
+ * runtime never compacts indices out from under it — even when the
149
+ * callback throws. That is JS's live-iteration contract, Node-verified
150
+ * (SEMANTICS.md). The callback receives (value, key) like JS; declaring
151
+ * fewer parameters — (value) or () — is ordinary TS and supported. */
152
+ export declare function lowerMapForEachCall(L: Lowerer, call: ts.CallExpression, receiver: IrExpr, mapT: IrType & {
153
+ kind: "map";
154
+ }): IrExpr;
155
+ /** The loop body of the Map.forEach desugar, from existing IR nodes:
156
+ *
157
+ * m.iterEnter();
158
+ * try {
159
+ * for (i = 0; i < m.iterCount; i++) {
160
+ * if (m.iterLive(i)) { v = m.iterValue(i); k = m.iterKey(i); f(v, k); }
161
+ * }
162
+ * } finally { m.iterExit(); }
163
+ *
164
+ * The finally keeps the runtime's iteration depth exact when the callback
165
+ * throws (unwinding runs the finally with the exception pending and
166
+ * propagation resumes — the emitter's standard contract). */
167
+ export declare function buildMapForEachFn(L: Lowerer, name: string, mapT: IrType & {
168
+ kind: "map";
169
+ }, arity: number, fnRet: IrType, loc: SrcLoc): IrFunction;
170
+ /** Ambient Set method calls — Map's lowering with the value slot gone.
171
+ * `add`/`has`/`delete`/`clear` lower to setIntrinsic; `forEach` desugars
172
+ * like Map's over the shared iteration primitives. Null when this isn't
173
+ * an ambient Set method call. */
174
+ export declare function lowerSetMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
175
+ /** `s.forEach(fn)` — Map's desugar shape over the set primitives. JS
176
+ * passes (value, value, set): the second parameter IS the element again,
177
+ * so both one- and two-parameter callbacks receive elem-typed arguments
178
+ * (iterKey read once, passed twice). Same live-iteration bracketing. */
179
+ export declare function lowerSetForEachCall(L: Lowerer, call: ts.CallExpression, receiver: IrExpr, setT: IrType & {
180
+ kind: "set";
181
+ }): IrExpr;
182
+ /** The loop body of the Set.forEach desugar — buildMapForEachFn with
183
+ * iterKey as the (single) element read:
184
+ *
185
+ * s.iterEnter();
186
+ * try {
187
+ * for (i = 0; i < s.iterCount; i++) {
188
+ * if (s.iterLive(i)) { v = s.iterKey(i); f(v, v); }
189
+ * }
190
+ * } finally { s.iterExit(); }
191
+ */
192
+ export declare function buildSetForEachFn(L: Lowerer, name: string, setT: IrType & {
193
+ kind: "set";
194
+ }, arity: number, fnRet: IrType, loc: SrcLoc): IrFunction;
195
+ /** Object.groupBy / Map.groupBy (ES2024): group an ARRAY's elements by a
196
+ * per-element key. Both lower to one interned helper loop per callback
197
+ * type — the callback runs synchronously per element (index included in
198
+ * the two-parameter form), the first occurrence of a key creates its
199
+ * group in encounter order, and later hits push onto the same array
200
+ * (JS's exact accumulation — the stored arrays are the live groups).
201
+ * Map.groupBy keeps typed keys under SameValueZero; Object.groupBy
202
+ * requires a STRING-KEYED result (Partial<Record<string, T[]>> — a
203
+ * literal-union key type makes a fixed-field record, which has no
204
+ * grouping representation) and stringifies number keys like JS property
205
+ * keys. Node's result carries a null prototype — records here have no
206
+ * prototype at all, so the difference is unobservable except through
207
+ * util.inspect's "[Object: null prototype]" prefix (ledgered). Other
208
+ * iterables fence (spread into an array first); Null when the callee
209
+ * isn't the stdlib Object/Map groupBy. */
210
+ export declare function lowerGroupByStaticCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
211
+ /** The lowered iterator-helper chains: `arr.values()` (the array
212
+ * iterator) through any run of map/filter/take/drop/flatMap into a
213
+ * consuming terminal (toArray/forEach/reduce/some/every/find), FUSED
214
+ * into one per-element loop — which IS the helpers' lazy pull order:
215
+ * each source element flows through every stage before the next is
216
+ * touched, take closes the pipeline without pulling upstream again
217
+ * (budget checked before delivery), and short-circuit terminals stop
218
+ * the walk at their hit. Stage callbacks take (value) or (value,
219
+ * counter) — counters count each stage's own input stream, per spec.
220
+ * take/drop budgets validate eagerly AT THE CALL (Node's RangeError,
221
+ * raw value in the message) through an interned checker call inserted
222
+ * at the argument's evaluation position. The source array is iterated
223
+ * LIVE by index against a re-read length, exactly the array iterator's
224
+ * contract. Everything else — iterator objects stored in bindings,
225
+ * generator/Set/Map receivers, Iterator.from — keeps the lib fences.
226
+ * Null when the callee isn't a terminal over such a chain. */
227
+ export declare function lowerIteratorHelperCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
228
+ /** The ES2025 Set composition methods (union/intersection/difference/
229
+ * symmetricDifference/isSubsetOf/isSupersetOf/isDisjointFrom): one
230
+ * set-like argument, desugared to an interned two-set helper loop. Only
231
+ * a REAL Set argument of the receiver's element type lowers — the
232
+ * desugar substitutes the builtin has/size for the spec's observable
233
+ * calls, which is exact for Sets and wrong for anything else (a Map or
234
+ * a custom { has, size, keys } object fences). */
235
+ export declare function lowerSetCombineCall(L: Lowerer, call: ts.CallExpression, name: string, receiver: IrExpr, setT: IrType & {
236
+ kind: "set";
237
+ }): IrExpr;
238
+ /** `for (const [k, v] of m)` / `for (const e of m)` — for-of over a Map,
239
+ * desugared IN PLACE (the body is user code, so no helper function) over
240
+ * the same iteration primitives as the forEach desugar, with the same
241
+ * Node-exact live-iteration contract: iterCount re-read every pass
242
+ * (entries appended by the body are visited), tombstones skipped
243
+ * (deleted entries are not). Shape:
244
+ *
245
+ * %m = <iterable>; %m.iterEnter();
246
+ * try {
247
+ * for (%i = 0; %i < %m.iterCount; %i++) {
248
+ * if (%m.iterLive(%i)) { <bindings>; <body> }
249
+ * }
250
+ * } catch (%c) { %m.iterExit(); rethrow %c; }
251
+ * %m.iterExit();
252
+ *
253
+ * catch-and-rethrow instead of a finally because break/continue/return
254
+ * may not cross a finally (the emitter's documented contract) and a
255
+ * for-of body legitimately contains all three: break/continue bind to
256
+ * the desugared loop INSIDE the plain try (jumps out of plain try need
257
+ * nothing), and every `return` in the body gets an iterExit inserted
258
+ * before it (exitBeforeReturns) so the depth count stays exact on that
259
+ * path too. A `[k, v]` head of plain identifiers binds straight from
260
+ * iterKey/iterValue — the tuple record never materializes; an identifier
261
+ * head binds the checker's own [K, V] tuple built per iteration. */
262
+ /** The iterator-method projections a for-of can ride directly:
263
+ * `for (const k of m.keys())`, `.values()`, `.entries()` — the SAME
264
+ * live-iteration walk as `for..of m` (JS's container iterators are live
265
+ * views, not snapshots), just yielding the key, the value, or the pair. */
266
+ export type ForOfIterProjection = "keys" | "values" | "entries";
267
+ /** for-of over a URLSearchParams (and its keys()/values()/entries()
268
+ * projections consumed directly by the head): the LIVE index walk —
269
+ * sp.size re-reads every pass, so entries appended mid-walk are visited
270
+ * and deletes shift, the spec's index-based iterator exactly. No
271
+ * enter/exit bracketing: the pair list compacts immediately (no
272
+ * tombstones), so there is no iteration depth to keep exact. */
273
+ export declare function lowerForOfSearchParams(L: Lowerer, stmt: ts.ForOfStatement, iterable: IrExpr, proj?: ForOfIterProjection): IrStmt;
274
+ export declare function lowerForOfMap(L: Lowerer, stmt: ts.ForOfStatement, iterable: IrExpr, mapT: IrType & {
275
+ kind: "map";
276
+ }, proj?: ForOfIterProjection): IrStmt;
277
+ /** `for (const v of s)` — for-of over a Set: the Map desugar with iterKey
278
+ * as the (single) element read; same live-iteration contract. */
279
+ export declare function lowerForOfSet(L: Lowerer, stmt: ts.ForOfStatement, iterable: IrExpr, setT: IrType & {
280
+ kind: "set";
281
+ }, proj?: ForOfIterProjection): IrStmt;
282
+ /** `new Map(entries)` from a tuple-array VALUE — any `[K, V][]`-typed
283
+ * expression (a variable, a .map() result, a sorted entries spread), not
284
+ * just the pair-literal form lower-classes handles inline. Desugars to a
285
+ * direct call of a synthetic function that constructs the empty map and
286
+ * set()s each pair in array order — JS-exact: pairs are visited in
287
+ * insertion order and a later duplicate key overwrites while keeping the
288
+ * first occurrence's position (set()'s own contract). Null when the
289
+ * argument isn't a matching tuple array (the caller keeps its fence). */
290
+ export declare function lowerMapSeedArrayNew(L: Lowerer, argNode: ts.Expression, mapT: IrType & {
291
+ kind: "map";
292
+ }): IrExpr | null;
293
+ /** Regex method calls, both directions: `re.test(s)` on a regex receiver,
294
+ * and `s.replace(re, tpl)` / `s.replaceAll(re, tpl)` / `s.split(re)` on a
295
+ * string receiver whose FIRST ARGUMENT is a regex (the string-pattern
296
+ * overloads keep their island lowering — the argument's mapped type is
297
+ * what routes here, before lowerIslandMethodCall can claim the name).
298
+ * Null when neither shape matches. */
299
+ export declare function lowerRegexMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, dynReceiver?: () => IrExpr): IrExpr | null;
300
+ /** `s.slice(1, 4)` and friends → strIntrinsic. Null when this isn't an
301
+ * ambient string method call (caller keeps its generic rejection). Missing
302
+ * optional arguments are omitted from `args` — the backend fills the
303
+ * documented defaults; the IR never encodes them (Infinity isn't
304
+ * JSON-safe). tsc has already checked arity and argument types against
305
+ * ambient/scriptc.d.ts. */
306
+ export declare function lowerStringMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, dynReceiver?: () => IrExpr): IrExpr | null;
307
+ /** `new Uint8Array(...)` / `new Uint32Array(...)` / `new Float32Array(...)`
308
+ * (stdlib provenance — a user's own class with the name resolves through
309
+ * classBySymbol). Lowered argument shapes: none (empty), a length
310
+ * (zero-filled; ToIndex at runtime — invalid lengths throw Node's
311
+ * RangeError), a same-kind typed array or Buffer (an independent COPY —
312
+ * the readFile chain's `new Uint8Array(await readFile(p))`), a number[]
313
+ * literal (element-coerced; its contextual type is the lib's
314
+ * ArrayLike/Iterable union, which cannot map — the Set-seed pattern), or
315
+ * a number[]-typed value. ArrayBuffer/view forms are fenced: scriptc
316
+ * typed arrays own their storage. Null when this isn't a stdlib
317
+ * typed-array construction. */
318
+ export declare function lowerBytesNew(L: Lowerer, expr: ts.NewExpression, symbol: ts.Symbol | null | undefined): IrExpr | null;
319
+ /** Method calls on typed-array/Buffer receivers: slice and subarray (BOTH
320
+ * copy — subarray's sharing is the documented divergence), set(src,
321
+ * offset?), and the u8-only Buffer surface: toString(enc?) plus the
322
+ * whole numeric read/write family (fixed widths BE/LE and the
323
+ * variable-width read/writeUIntLE quartet — BUF_NUM_METHODS). Everything
324
+ * else the lib declares (fill, indexOf, reverse, ...) falls through to
325
+ * the SC2020 member fence. Null when this isn't a bytes method call. */
326
+ export declare function lowerBytesMethodCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
327
+ /** The literal encoding argument of a Buffer surface, normalized — or a
328
+ * fence when it isn't a literal alias Node knows. */
329
+ export declare function bufEncoding(L: Lowerer, what: string, encNode: ts.Expression): string;
330
+ /** The Buffer statics — `Buffer.from(...)`, `Buffer.alloc(n)`,
331
+ * `Buffer.concat(list)`, `Buffer.isBuffer(x)` — on THE stdlib Buffer
332
+ * global (name + provenance; fallback and @types/node alike). Null when
333
+ * the callee isn't a Buffer-static access. */
334
+ export declare function lowerBufferStaticCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression): IrExpr | null;
335
+ /** `Object.keys/values/entries` over an INDEX-SIGNATURE (overflow-carrying)
336
+ * record shape: declared fields answer first from the compile-time field
337
+ * list (declaration order, undefined-valued fields skipped — exactly the
338
+ * fixed-shape lowering and SEMANTICS.md 37), then the overflow map's live
339
+ * keys in JS OWN-KEY order (canonical array indices ascending, then
340
+ * insertion order — recordOvfKeys). For a PURE index-signature shape
341
+ * (Record<string, T> — no declared fields, the typical CLI config patterns) the
342
+ * result order is Node-exact; hybrids inherit the documented
343
+ * declared-then-overflow divergence. Values surface as the checker's
344
+ * result element type: identity, an arm-into-union wrap, or (dyn
345
+ * results) the DOM conversion — recordKeyGet's own surfacing rules for
346
+ * the overflow, mirrored statically for declared fields. */
347
+ export declare function lowerObjectIterOverIndexShape(L: Lowerer, call: ts.CallExpression, member: "keys" | "values" | "entries", argIr: IrType & {
348
+ kind: "record";
349
+ }, shape: IrRecordShape): IrExpr;
350
+ /** The construction core, receiver/result pre-resolved — `node` anchors
351
+ * the fences. for-in reuses the "keys" arm directly (it iterates exactly
352
+ * the keys Object.keys answers; same intern key, one helper). */
353
+ export declare function objectIterOverIndexShape(L: Lowerer, node: ts.Node, member: "keys" | "values" | "entries", argIr: IrType & {
354
+ kind: "record";
355
+ }, shape: IrRecordShape, receiver: IrExpr, resultT: IrType & {
356
+ kind: "array";
357
+ }, loc: SrcLoc): IrExpr;
358
+ /** `Object.fromEntries(pairs)` over a `[string, V][]` VALUE into the
359
+ * checker's own index-signature result shape (`{ [k: string]: V }` —
360
+ * always declared-field-free from the lib signature): an interned helper
361
+ * loops the pairs and keyed-writes each into a fresh record's overflow —
362
+ * later duplicates overwrite in place (first insertion position wins for
363
+ * ORDER, last value wins — exactly JS). Values flow into the signature's
364
+ * value slot (dyn slots convert JSON-safe values, identity otherwise).
365
+ * The `as ModelPricing` reshape AFTER it is the width-coercion capture
366
+ * (lowerRecordOvfCaptureHelper). Null when the argument or result shape
367
+ * is outside this (Maps, richer iterables → the SC2020 fence). */
368
+ export declare function lowerObjectFromEntriesCall(L: Lowerer, call: ts.CallExpression, callee: ts.Expression): IrExpr | null;
369
+ /** Interned `%rec.capture.<n>(s)` — the INDEX-SIGNATURE reshape behind
370
+ * `Object.fromEntries(entries) as ModelPricing` (hybrid→hybrid width
371
+ * coercion) and `const r: Record<string, number> = { a: 1, b: 2 }`
372
+ * (a DECLARED-fields shape narrowing into a pure overflow shape — the
373
+ * record becomes width-free key/value storage), both called from
374
+ * widthCoerce after recordWidthHelper declines: builds the target shape
375
+ * fresh — declared fields default to their undefined arms — then
376
+ * keyed-writes every source key into it, declared fields first in the
377
+ * source's DECLARATION order (skipping ones holding the undefined arm,
378
+ * the unset convention — insertion order is what Object.keys/JSON
379
+ * answer, stance 37), then the source overflow in JS own-key order. A
380
+ * key colliding with a target DECLARED field validates through the
381
+ * keyed write's dynCheck (a mismatch throws the catchable TypeError —
382
+ * divergence 34), which is exactly what makes the `as` honest. The
383
+ * result is a COPY (divergence 36's stance). Null when the pair is
384
+ * outside the supported matrix: the target needs an index signature,
385
+ * every source value (declared fields, and the overflow slot when the
386
+ * source carries one) must enter the target's value slot (identity, a
387
+ * width lift — arm wrap/re-tag/nested reshape, or JSON-safe into a dyn
388
+ * slot), and every target field must be optional-flavored (the fresh
389
+ * record's default) and writable at runtime. */
390
+ export declare function lowerRecordOvfCaptureHelper(L: Lowerer, fromId: string, toId: string, loc: SrcLoc): string | null;
391
+ /** `Object.assign(target, ...sources)` into an INDEX-SIGNATURE record:
392
+ * the capture helper's keyed-write walk aimed at the EXISTING target —
393
+ * each source's declared fields write in declaration order (unset
394
+ * optionals skip, stance 37), then its overflow in JS own-key order,
395
+ * and the result IS the target (identity, like JS — later reads through
396
+ * the target see every merged key). One interned `%obj.assign.<n>(t, s)`
397
+ * per (target shape, source shape) pair; multiple sources chain. Null
398
+ * when outside the matrix: the target needs an index signature, every
399
+ * source value must enter its value slot (identity, a width lift, or
400
+ * the dyn conversion), and tsc's `T & U` result type must collapse back
401
+ * to the target's own record shape (the self-shaped merges init-config
402
+ * patterns spell). */
403
+ export declare function lowerObjectAssignIndexShape(L: Lowerer, call: ts.CallExpression): IrExpr | null;
404
+ /** One contributor of a pure-index-record MERGE literal: a full spread of
405
+ * an index-signature record, or one explicit key. */
406
+ export type IndexMergeContributor = {
407
+ kind: "spread";
408
+ shapeId: string;
409
+ value: IrExpr;
410
+ } | {
411
+ kind: "field";
412
+ name: string;
413
+ value: IrExpr;
414
+ }
415
+ /** A RUNTIME-keyed property (`{ ...m, ["a" + "b"]: v }`, `{ [K]: v }`
416
+ * over a runtime string K): the key is its own helper argument, passed
417
+ * immediately BEFORE its value (JS's per-property key-then-value order
418
+ * rides the call's argument evaluation), already stringified by the
419
+ * caller (ToPropertyKey). */
420
+ | {
421
+ kind: "keyedField";
422
+ key: IrExpr;
423
+ value: IrExpr;
424
+ }
425
+ /** `...(cond ? { k: v } : {})` at its literal position: the key writes
426
+ * ONLY when the value isn't the undefined arm (overflow entries model
427
+ * presence — an absent key stays absent, exactly JS's empty-arm spread).
428
+ * The caller builds `value` as `cond ? v : <interned undefined arm of
429
+ * the target's value slot>` — cond evaluates once, `v` lazily — so the
430
+ * target's index-value type must carry an undefined arm. The explicit
431
+ * `{ k: undefined }` true-arm collapses to absence, divergence 56's
432
+ * documented stance. */
433
+ | {
434
+ kind: "condField";
435
+ name: string;
436
+ value: IrExpr;
437
+ };
438
+ /** The interned merge helper behind `{ ...a, ...b, K: v }` literals whose
439
+ * TARGET shape is a PURE index-signature record (no declared fields) —
440
+ * the spawn-env pattern (`{ ...process.env, ...extraEnv }`). Contributors
441
+ * apply in literal order with keyed writes, so JS's last-write-wins holds
442
+ * for colliding runtime keys. Spread sources must be index-signature
443
+ * records whose value slot IS the target's or LIFTS into it (a
444
+ * `Record<string, string>` spreads into a `string | undefined` target by
445
+ * wrapping each copied value); their declared fields copy first (skipping
446
+ * undefined-armed absents — the unset convention), then their overflow in
447
+ * JS own-key order. Explicit values arrive pre-coerced to the target's
448
+ * value slot. Null when a spread source is outside that matrix (the
449
+ * caller keeps its fence). */
450
+ export declare function lowerIndexMergeHelper(L: Lowerer, toId: string, contributors: IndexMergeContributor[], loc: SrcLoc): string | null;
451
+ /** The interned helper flattening an env-shaped record into the
452
+ * [k0, v0, k1, v1, ...] string[] cp.execSync consumes — declared string
453
+ * fields first (undefined-armed absents skipped, the Node-drops-undefined
454
+ * rule), then index-signature overflow in JS own-key order. Every value
455
+ * source must be a string or a `string | undefined` union whose value arm
456
+ * is a string. Null when the shape carries a non-string field/value slot
457
+ * (the caller fences). */
458
+ export declare function lowerEnvToPairsHelper(L: Lowerer, shapeId: string, loc: SrcLoc): string | null;
459
+ /** The validated-STRING extraction of a dyn method receiver — the receiver
460
+ * expression the string/regex method lowerings consume. */
461
+ export declare function dynStringReceiver(L: Lowerer, recv: IrExpr, access: ts.PropertyAccessExpression): IrExpr;
462
+ /** `d.filter(pred)` on a dyn receiver: the receiver must BE a DOM array
463
+ * (else the Node-shaped TypeError above); the predicate runs per element
464
+ * over the DOM value, and each SURVIVOR is validated-extracted into the
465
+ * result's element type T — the type the checker already committed the
466
+ * call to (the contextual `RouteMapping[]`/`string[]` slot). Extraction is
467
+ * the checked-cast machinery: a survivor that doesn't fit T throws the
468
+ * catchable TypeError instead of misreading (a LYING predicate is the only
469
+ * way there). The result is a fresh STATIC array of extracted copies —
470
+ * the dyn boundary's marshal-copy stance (SEMANTICS.md). Null when the
471
+ * call shape isn't claimable (the method-call fence stays). */
472
+ export declare function lowerDynArrayFilterCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, recv: IrExpr): IrExpr | null;
473
+ /** `.flatMap(f)` on a dyn ('unknown'/`any[]`-narrowed) receiver where the
474
+ * callback returns a STATIC array (`parsed.flatMap((v) => typeof v ===
475
+ * "string" ? parseTldList(v) : [])` — the tlds-file shape): the DOM
476
+ * array walks element-by-element, the callback sees each element as the
477
+ * DOM value `unknown` code sees, and its typed results concatenate —
478
+ * depth-1 flatten by construction, no validation needed on the results
479
+ * (they are already typed; only the RECEIVER is dynamic). Non-array
480
+ * receivers throw the Node-shaped TypeError. Callbacks returning
481
+ * NON-array values (JS would keep them as single elements) or dynamic
482
+ * results keep the fence — nothing drives them yet. */
483
+ export declare function lowerDynArrayFlatMapCall(L: Lowerer, call: ts.CallExpression, access: ts.PropertyAccessExpression, recv: IrExpr): IrExpr | null;