@loopdive/js2 0.57.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.
Files changed (233) hide show
  1. package/CHANGELOG.md +1425 -0
  2. package/LICENSE +189 -0
  3. package/README.md +451 -0
  4. package/dist/checker/index.d.ts +117 -0
  5. package/dist/checker/language-service.d.ts +39 -0
  6. package/dist/checker/node-capability-map.d.ts +63 -0
  7. package/dist/checker/type-mapper.d.ts +84 -0
  8. package/dist/cjs-rewrite.d.ts +19 -0
  9. package/dist/cli.d.ts +2 -0
  10. package/dist/cli.js +363 -0
  11. package/dist/codegen/accessor-driver.d.ts +97 -0
  12. package/dist/codegen/any-helpers.d.ts +72 -0
  13. package/dist/codegen/array-element-typing.d.ts +46 -0
  14. package/dist/codegen/array-holes.d.ts +69 -0
  15. package/dist/codegen/array-methods.d.ts +68 -0
  16. package/dist/codegen/array-object-proto.d.ts +64 -0
  17. package/dist/codegen/array-reduce-fusion.d.ts +31 -0
  18. package/dist/codegen/array-to-primitive.d.ts +28 -0
  19. package/dist/codegen/async-cps.d.ts +239 -0
  20. package/dist/codegen/async-scheduler.d.ts +349 -0
  21. package/dist/codegen/binary-ops.d.ts +78 -0
  22. package/dist/codegen/binding-info.d.ts +31 -0
  23. package/dist/codegen/builtin-scaffold.d.ts +98 -0
  24. package/dist/codegen/builtin-static-globals.d.ts +8 -0
  25. package/dist/codegen/builtin-tags.d.ts +189 -0
  26. package/dist/codegen/case-convert-native.d.ts +12 -0
  27. package/dist/codegen/case-tables.d.ts +4 -0
  28. package/dist/codegen/class-bodies.d.ts +41 -0
  29. package/dist/codegen/class-member-keys.d.ts +33 -0
  30. package/dist/codegen/class-to-primitive.d.ts +39 -0
  31. package/dist/codegen/closed-method-dispatch.d.ts +42 -0
  32. package/dist/codegen/closures.d.ts +285 -0
  33. package/dist/codegen/coercion-engine.d.ts +154 -0
  34. package/dist/codegen/coercion-plan.d.ts +29 -0
  35. package/dist/codegen/context/bodies.d.ts +4 -0
  36. package/dist/codegen/context/create-context.d.ts +4 -0
  37. package/dist/codegen/context/errors.d.ts +39 -0
  38. package/dist/codegen/context/locals.d.ts +69 -0
  39. package/dist/codegen/context/source-pos.d.ts +5 -0
  40. package/dist/codegen/context/speculative.d.ts +95 -0
  41. package/dist/codegen/context/types.d.ts +1936 -0
  42. package/dist/codegen/custom-iterable.d.ts +34 -0
  43. package/dist/codegen/dataview-native.d.ts +51 -0
  44. package/dist/codegen/date-parse-native.d.ts +13 -0
  45. package/dist/codegen/dead-elimination.d.ts +26 -0
  46. package/dist/codegen/declarations.d.ts +147 -0
  47. package/dist/codegen/deno-api.d.ts +11 -0
  48. package/dist/codegen/destructuring-params.d.ts +102 -0
  49. package/dist/codegen/dyn-read.d.ts +26 -0
  50. package/dist/codegen/eval-tiering.d.ts +19 -0
  51. package/dist/codegen/expressions/assignment.d.ts +61 -0
  52. package/dist/codegen/expressions/builtins.d.ts +26 -0
  53. package/dist/codegen/expressions/calls-closures.d.ts +54 -0
  54. package/dist/codegen/expressions/calls-guards.d.ts +49 -0
  55. package/dist/codegen/expressions/calls-optional.d.ts +4 -0
  56. package/dist/codegen/expressions/calls.d.ts +83 -0
  57. package/dist/codegen/expressions/eval-inline.d.ts +24 -0
  58. package/dist/codegen/expressions/extern.d.ts +67 -0
  59. package/dist/codegen/expressions/fnctor-prototype.d.ts +52 -0
  60. package/dist/codegen/expressions/helpers.d.ts +212 -0
  61. package/dist/codegen/expressions/identifiers.d.ts +57 -0
  62. package/dist/codegen/expressions/late-imports.d.ts +81 -0
  63. package/dist/codegen/expressions/logical-ops.d.ts +18 -0
  64. package/dist/codegen/expressions/misc.d.ts +27 -0
  65. package/dist/codegen/expressions/new-super.d.ts +25 -0
  66. package/dist/codegen/expressions/promise-subclass.d.ts +38 -0
  67. package/dist/codegen/expressions/proto-override.d.ts +63 -0
  68. package/dist/codegen/expressions/unary-updates.d.ts +21 -0
  69. package/dist/codegen/expressions/unary.d.ts +6 -0
  70. package/dist/codegen/expressions.d.ts +31 -0
  71. package/dist/codegen/fallback-telemetry.d.ts +53 -0
  72. package/dist/codegen/fixups.d.ts +80 -0
  73. package/dist/codegen/fmod.d.ts +10 -0
  74. package/dist/codegen/fnctor-escape-gate.d.ts +92 -0
  75. package/dist/codegen/function-body.d.ts +52 -0
  76. package/dist/codegen/generators-native.d.ts +92 -0
  77. package/dist/codegen/helpers/body-references-own-this.d.ts +22 -0
  78. package/dist/codegen/helpers/body-uses-arguments.d.ts +12 -0
  79. package/dist/codegen/helpers/is-strict-function.d.ts +52 -0
  80. package/dist/codegen/host-import-allowlist.d.ts +140 -0
  81. package/dist/codegen/index.d.ts +500 -0
  82. package/dist/codegen/ir-tail-call.d.ts +8 -0
  83. package/dist/codegen/iterator-native.d.ts +44 -0
  84. package/dist/codegen/json-codec-native.d.ts +78 -0
  85. package/dist/codegen/json-runtime.d.ts +35 -0
  86. package/dist/codegen/json-standalone.d.ts +25 -0
  87. package/dist/codegen/linear-uint8-analysis.d.ts +46 -0
  88. package/dist/codegen/linear-uint8-arena.d.ts +7 -0
  89. package/dist/codegen/linear-uint8-codegen.d.ts +103 -0
  90. package/dist/codegen/linear-uint8-signatures.d.ts +26 -0
  91. package/dist/codegen/literals.d.ts +115 -0
  92. package/dist/codegen/map-runtime.d.ts +142 -0
  93. package/dist/codegen/math-helpers.d.ts +7 -0
  94. package/dist/codegen/member-get-dispatch.d.ts +42 -0
  95. package/dist/codegen/member-set-dispatch.d.ts +28 -0
  96. package/dist/codegen/native-proto.d.ts +98 -0
  97. package/dist/codegen/native-regex.d.ts +158 -0
  98. package/dist/codegen/native-strings.d.ts +146 -0
  99. package/dist/codegen/new-target.d.ts +30 -0
  100. package/dist/codegen/node-fs-api.d.ts +47 -0
  101. package/dist/codegen/number-format-native.d.ts +9 -0
  102. package/dist/codegen/number-ryu.d.ts +27 -0
  103. package/dist/codegen/object-ops.d.ts +94 -0
  104. package/dist/codegen/object-runtime.d.ts +171 -0
  105. package/dist/codegen/parse-number-native.d.ts +10 -0
  106. package/dist/codegen/peephole.d.ts +6 -0
  107. package/dist/codegen/property-access.d.ts +294 -0
  108. package/dist/codegen/raw-wasi-api.d.ts +13 -0
  109. package/dist/codegen/regex/bytecode.d.ts +140 -0
  110. package/dist/codegen/regex/casefold.d.ts +41 -0
  111. package/dist/codegen/regex/compile.d.ts +51 -0
  112. package/dist/codegen/regex/parse.d.ts +76 -0
  113. package/dist/codegen/regex/unicode.d.ts +42 -0
  114. package/dist/codegen/regex/vm.d.ts +24 -0
  115. package/dist/codegen/regexp-standalone.d.ts +350 -0
  116. package/dist/codegen/registry/error-types.d.ts +38 -0
  117. package/dist/codegen/registry/imports.d.ts +46 -0
  118. package/dist/codegen/registry/types.d.ts +59 -0
  119. package/dist/codegen/set-algebra.d.ts +17 -0
  120. package/dist/codegen/set-runtime.d.ts +74 -0
  121. package/dist/codegen/shared.d.ts +111 -0
  122. package/dist/codegen/stack-balance.d.ts +43 -0
  123. package/dist/codegen/statements/control-flow.d.ts +25 -0
  124. package/dist/codegen/statements/destructuring.d.ts +177 -0
  125. package/dist/codegen/statements/exceptions.d.ts +11 -0
  126. package/dist/codegen/statements/functions.d.ts +1 -0
  127. package/dist/codegen/statements/index.d.ts +1 -0
  128. package/dist/codegen/statements/loops.d.ts +7 -0
  129. package/dist/codegen/statements/nested-declarations.d.ts +78 -0
  130. package/dist/codegen/statements/shared.d.ts +38 -0
  131. package/dist/codegen/statements/tdz.d.ts +43 -0
  132. package/dist/codegen/statements/variables.d.ts +3 -0
  133. package/dist/codegen/statements.d.ts +9 -0
  134. package/dist/codegen/string-builder.d.ts +131 -0
  135. package/dist/codegen/string-ops.d.ts +87 -0
  136. package/dist/codegen/struct-accessor-closure.d.ts +36 -0
  137. package/dist/codegen/symbol-native.d.ts +55 -0
  138. package/dist/codegen/temporal-native.d.ts +8 -0
  139. package/dist/codegen/timsort.d.ts +2 -0
  140. package/dist/codegen/type-coercion.d.ts +123 -0
  141. package/dist/codegen/typeof-delete.d.ts +38 -0
  142. package/dist/codegen/uri-encoding-native.d.ts +33 -0
  143. package/dist/codegen/value-tags.d.ts +74 -0
  144. package/dist/codegen/walk-instructions.d.ts +20 -0
  145. package/dist/codegen/weak-collections-runtime.d.ts +16 -0
  146. package/dist/codegen/with-scope.d.ts +106 -0
  147. package/dist/codegen-linear/c-abi.d.ts +74 -0
  148. package/dist/codegen-linear/context.d.ts +86 -0
  149. package/dist/codegen-linear/index.d.ts +28 -0
  150. package/dist/codegen-linear/layout.d.ts +39 -0
  151. package/dist/codegen-linear/runtime.d.ts +161 -0
  152. package/dist/codegen-linear/simd.d.ts +7 -0
  153. package/dist/compiler/define-substitution.d.ts +27 -0
  154. package/dist/compiler/early-errors/assignment.d.ts +26 -0
  155. package/dist/compiler/early-errors/context.d.ts +17 -0
  156. package/dist/compiler/early-errors/duplicates.d.ts +20 -0
  157. package/dist/compiler/early-errors/index.d.ts +11 -0
  158. package/dist/compiler/early-errors/labels.d.ts +13 -0
  159. package/dist/compiler/early-errors/module-rules.d.ts +36 -0
  160. package/dist/compiler/early-errors/node-checks.d.ts +7 -0
  161. package/dist/compiler/early-errors/predicates.d.ts +140 -0
  162. package/dist/compiler/early-errors/tdz.d.ts +17 -0
  163. package/dist/compiler/import-manifest.d.ts +18 -0
  164. package/dist/compiler/output.d.ts +46 -0
  165. package/dist/compiler/validation.d.ts +45 -0
  166. package/dist/compiler.d.ts +48 -0
  167. package/dist/define-substitution-BcUeKC2A.js +109 -0
  168. package/dist/emit/binary.d.ts +50 -0
  169. package/dist/emit/c-header.d.ts +23 -0
  170. package/dist/emit/canonical-recgroup.d.ts +86 -0
  171. package/dist/emit/encoder.d.ts +28 -0
  172. package/dist/emit/object.d.ts +14 -0
  173. package/dist/emit/opcodes.d.ts +464 -0
  174. package/dist/emit/sourcemap.d.ts +33 -0
  175. package/dist/emit/wat.d.ts +6 -0
  176. package/dist/env.d.ts +46 -0
  177. package/dist/import-resolver.d.ts +68 -0
  178. package/dist/index.d.ts +486 -0
  179. package/dist/index.js +755 -0
  180. package/dist/ir/alloc-registry.d.ts +75 -0
  181. package/dist/ir/analysis/encoding.d.ts +38 -0
  182. package/dist/ir/analysis/escape.d.ts +32 -0
  183. package/dist/ir/analysis/lattice.d.ts +72 -0
  184. package/dist/ir/analysis/ownership.d.ts +31 -0
  185. package/dist/ir/analysis/stack-alloc.d.ts +20 -0
  186. package/dist/ir/backend/bytecode-emitter.d.ts +237 -0
  187. package/dist/ir/backend/bytecode-vm.d.ts +74 -0
  188. package/dist/ir/backend/emitter.d.ts +121 -0
  189. package/dist/ir/backend/handles.d.ts +133 -0
  190. package/dist/ir/backend/legality.d.ts +9 -0
  191. package/dist/ir/backend/linear-emitter.d.ts +41 -0
  192. package/dist/ir/backend/wasmgc-emitter.d.ts +43 -0
  193. package/dist/ir/builder.d.ts +401 -0
  194. package/dist/ir/from-ast.d.ts +192 -0
  195. package/dist/ir/index.d.ts +16 -0
  196. package/dist/ir/integration.d.ts +27 -0
  197. package/dist/ir/lower.d.ts +203 -0
  198. package/dist/ir/nodes.d.ts +1452 -0
  199. package/dist/ir/passes/alloc-discipline.d.ts +19 -0
  200. package/dist/ir/passes/constant-fold.d.ts +7 -0
  201. package/dist/ir/passes/dead-code.d.ts +18 -0
  202. package/dist/ir/passes/inline-small.d.ts +7 -0
  203. package/dist/ir/passes/monomorphize.d.ts +21 -0
  204. package/dist/ir/passes/simplify-cfg.d.ts +19 -0
  205. package/dist/ir/passes/tagged-union-types.d.ts +45 -0
  206. package/dist/ir/passes/tagged-unions.d.ts +22 -0
  207. package/dist/ir/propagate.d.ts +135 -0
  208. package/dist/ir/select.d.ts +81 -0
  209. package/dist/ir/types.d.ts +832 -0
  210. package/dist/ir/verify-alloc.d.ts +18 -0
  211. package/dist/ir/verify.d.ts +7 -0
  212. package/dist/link/index.d.ts +11 -0
  213. package/dist/link/isolation.d.ts +24 -0
  214. package/dist/link/linker.d.ts +37 -0
  215. package/dist/link/reader.d.ts +158 -0
  216. package/dist/link/resolver.d.ts +19 -0
  217. package/dist/optimize.d.ts +54 -0
  218. package/dist/optimize.js +262 -0
  219. package/dist/position-map.d.ts +64 -0
  220. package/dist/process-stdin-prelude.d.ts +16 -0
  221. package/dist/resolve.d.ts +82 -0
  222. package/dist/runtime/builtins.d.ts +1 -0
  223. package/dist/runtime-C-4q_KwU.js +164438 -0
  224. package/dist/runtime-containment.d.ts +6 -0
  225. package/dist/runtime-eval.d.ts +132 -0
  226. package/dist/runtime-instantiate.d.ts +16 -0
  227. package/dist/runtime.d.ts +128 -0
  228. package/dist/runtime.js +12 -0
  229. package/dist/shape-inference.d.ts +20 -0
  230. package/dist/treeshake.d.ts +17 -0
  231. package/dist/ts-api.d.ts +30 -0
  232. package/dist/wit-generator.d.ts +18 -0
  233. package/package.json +187 -0
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Built-in type-tag registry for `instanceof` short-circuit evaluation.
3
+ *
4
+ * Built-in JS types like `Array`, `Error`, `TypeError`, `Map` etc. are not
5
+ * emitted as user classes (no entry in `ctx.classTagMap`), so the existing
6
+ * struct-tag-based `instanceof` codegen cannot resolve them. The compiler
7
+ * falls back to a `__instanceof` host import, which is unavailable in
8
+ * standalone / WASI mode.
9
+ *
10
+ * This module provides:
11
+ * - a stable registry of well-known built-in type names (with hierarchy info)
12
+ * - static-evaluation helpers that let `compileHostInstanceOf` short-circuit
13
+ * to a constant `i32.const 0` or `i32.const 1` whenever the LHS TypeScript
14
+ * type (or stack value type) is provably (in)compatible with the RHS
15
+ * constructor.
16
+ *
17
+ * The numeric tag values are reserved as **negative integers** so they cannot
18
+ * collide with user-class tags assigned by `ctx.classTagCounter` (which starts
19
+ * at 0 and increments). This leaves room for a future Phase 2 that actually
20
+ * stores these tags in WasmGC structs (e.g., a $Error wrapper struct for
21
+ * thrown exceptions).
22
+ *
23
+ * Phase-1 scope (this module): the registry and static elimination only.
24
+ * Phase-2 scope (later): tagged WasmGC wrapper structs for thrown errors so
25
+ * `catch (e) { if (e instanceof TypeError) ... }` works without a JS host.
26
+ *
27
+ * See plan/issues/sprints/50/1325-instanceof-builtin-type-tag-registry.md.
28
+ */
29
+ /**
30
+ * Reserved tag values for built-in JS constructors. Negative integers so they
31
+ * do not collide with user class tags (which start at 0 and count up).
32
+ *
33
+ * Phase 1 does NOT yet write these tags into WasmGC structs — they are only
34
+ * used for static reasoning. Phase 2 will tag thrown-error wrapper structs
35
+ * with these values so pure-Wasm `catch (e) instanceof TypeError` works.
36
+ */
37
+ export declare const BUILTIN_TYPE_TAGS: {
38
+ readonly Object: -1;
39
+ readonly Function: -2;
40
+ readonly Array: -3;
41
+ readonly Boolean: -4;
42
+ readonly Number: -5;
43
+ readonly String: -6;
44
+ readonly Error: -10;
45
+ readonly TypeError: -11;
46
+ readonly RangeError: -12;
47
+ readonly SyntaxError: -13;
48
+ readonly URIError: -14;
49
+ readonly EvalError: -15;
50
+ readonly ReferenceError: -16;
51
+ readonly AggregateError: -17;
52
+ readonly Map: -20;
53
+ readonly Set: -21;
54
+ readonly WeakMap: -22;
55
+ readonly WeakSet: -23;
56
+ readonly WeakRef: -24;
57
+ readonly Date: -30;
58
+ readonly RegExp: -31;
59
+ readonly Promise: -40;
60
+ readonly ArrayBuffer: -50;
61
+ readonly SharedArrayBuffer: -51;
62
+ readonly DataView: -52;
63
+ readonly Int8Array: -70;
64
+ readonly Uint8Array: -71;
65
+ readonly Uint8ClampedArray: -72;
66
+ readonly Int16Array: -73;
67
+ readonly Uint16Array: -74;
68
+ readonly Int32Array: -75;
69
+ readonly Uint32Array: -76;
70
+ readonly Float32Array: -77;
71
+ readonly Float64Array: -78;
72
+ readonly BigInt64Array: -79;
73
+ readonly BigUint64Array: -80;
74
+ };
75
+ export type BuiltinTypeName = keyof typeof BUILTIN_TYPE_TAGS;
76
+ /**
77
+ * Returns true if `name` is a known built-in JS constructor name in the
78
+ * registry. Caller should already have checked it isn't a user class.
79
+ */
80
+ export declare function isBuiltinTypeName(name: string): name is BuiltinTypeName;
81
+ /**
82
+ * Returns true if `child` is `parent` or transitively a built-in subclass of
83
+ * `parent` (per the registry's BUILTIN_PARENT chain). Used to statically
84
+ * decide e.g. `new TypeError() instanceof Error` → true.
85
+ *
86
+ * Returns false for unknown names (caller should still fall through to the
87
+ * host import or to a `false` constant).
88
+ */
89
+ export declare function isBuiltinSubtype(child: string, parent: string): boolean;
90
+ /**
91
+ * Returns the parent constructor name for a built-in, or undefined if it has
92
+ * no parent in the registry. Exposed for tests / debugging.
93
+ */
94
+ export declare function getBuiltinParent(name: string): BuiltinTypeName | undefined;
95
+ /**
96
+ * Built-in constructors for which we emit subclass support via the existing
97
+ * `__new_<Name>(args...) -> externref` host imports. The subclass instance
98
+ * is represented as externref (NOT a WasmGC struct), and the host returns a
99
+ * real JS object with the right internal slots.
100
+ *
101
+ * Scope:
102
+ * - #1366a: Error family (Error, TypeError, RangeError, …).
103
+ * - #1366b: container builtins (Array, Map, Set, WeakMap, WeakSet, Promise,
104
+ * RegExp, ArrayBuffer). These all route through the same single-arg
105
+ * `__new_<Name>(arg) -> externref` host import; the runtime's
106
+ * `extern_class new` resolver (`runtime.ts:1604`) constructs the real
107
+ * built-in via `new globalThis[Name](...)` after stripping trailing nulls.
108
+ *
109
+ * Limitations (deferred to #1366c/d):
110
+ * - `instanceof Sub` for non-Error subclasses: the host instance's
111
+ * `[[Prototype]]` is the parent's, not Sub's, so `subInst instanceof Sub`
112
+ * resolves via the static reasoning path (`expressions.ts:714`) rather
113
+ * than runtime prototype-chain walking.
114
+ * - `Symbol.species` is honoured by the host's spec-conforming method
115
+ * impls automatically (since the instance IS a real Array/Map/etc.), but
116
+ * methods that return "a new instance of the same kind" return the
117
+ * parent type, not Sub.
118
+ * - Dynamic spread (`super(...args)` or `new Sub(...args)`) only forwards up
119
+ * to the parent constructor's statically known import arity. Array-literal
120
+ * spread is flattened, but arbitrary iterable spreading is still deferred.
121
+ */
122
+ export declare const BUILTIN_PARENTS_HOST_CONSTRUCTIBLE: ReadonlySet<BuiltinTypeName>;
123
+ /**
124
+ * Returns true if `name` is a built-in JS constructor that can act as a
125
+ * parent for a host-constructible subclass (#1366a/#1366b). The subclass
126
+ * instance is externref-backed and `super(...)` lowers to `__new_<Name>(...)`.
127
+ */
128
+ export declare function isHostConstructibleBuiltin(name: string): boolean;
129
+ /**
130
+ * (#2620) The native-collection builtins. In `nativeStrings` mode
131
+ * (`--target standalone`/`wasi`) these are served by the WasmGC-native
132
+ * Map/Set runtime (map-runtime.ts / set-runtime.ts / weak-collections-runtime.ts,
133
+ * #1103a/#2162) and are deliberately NOT registered as externClasses — base
134
+ * `new Set([...])` is intercepted to the native `$Map`-backed instance instead
135
+ * of leaking a `__new_Set` host import.
136
+ *
137
+ * A *subclass* (`class X extends Set {}`), however, still routes through the
138
+ * generic host-constructible path (these names ARE in
139
+ * `BUILTIN_PARENTS_HOST_CONSTRUCTIBLE`): under standalone that both leaks the
140
+ * `__new_<Name>` host import AND desyncs the synthetic `<Class>_<method>`
141
+ * accessor across the late-import shift (the #2043 index-shift class → invalid
142
+ * Wasm). A native subclass (native construction + direct `[[SetData]]`
143
+ * set-algebra + native iteration + `instanceof` discrimination) is the
144
+ * value-rep/collection-runtime substrate (#2162-scale), tracked separately.
145
+ * Until then, a standalone subclass of one of these is refused at compile time
146
+ * (clean CE, never invalid Wasm / never a leaked host import). See the
147
+ * refusal in class-bodies.ts.
148
+ */
149
+ export declare const NATIVE_COLLECTION_BUILTINS: ReadonlySet<string>;
150
+ /**
151
+ * (#2620) Returns true if `name` is a native-collection builtin
152
+ * (Set/Map/WeakMap/WeakSet) — used to refuse a standalone subclass of one of
153
+ * them (see {@link NATIVE_COLLECTION_BUILTINS}).
154
+ */
155
+ export declare function isNativeCollectionBuiltin(name: string): boolean;
156
+ /**
157
+ * (#2029) The primitive-wrapper builtins whose standalone SUBCLASS construction
158
+ * is broken. `Number` and `Boolean` are in
159
+ * `BUILTIN_PARENTS_HOST_CONSTRUCTIBLE` so a `class N extends Number {}` takes
160
+ * the externref-backed host path under `--target standalone`/`wasi`, lowering
161
+ * `super()`/`new Sub()` to `call $__new_Number` — but the standalone
162
+ * `__new_Number`/`__new_Boolean` internals take an **f64** argument, while the
163
+ * synthetic `<Class>_new` forwarder passes the constructor's externref local
164
+ * (`local.get $0`). The arg types don't match → `wasm-validator error in
165
+ * function N_new: call param types must match` (invalid Wasm — the binary still
166
+ * serializes but dies at instantiate/validate). No native primitive-wrapper
167
+ * *subclass* box exists standalone yet.
168
+ *
169
+ * `String` is deliberately NOT in this set: its standalone
170
+ * `__new_String(externref) -> externref` is externref-in/externref-out, which
171
+ * the externref forwarder matches exactly — `class S extends String {}` already
172
+ * compiles, instantiates with an empty import object, and answers
173
+ * `new S() instanceof S` → `true` standalone (verified on main). Refusing it
174
+ * would regress a working case.
175
+ *
176
+ * Until a native wrapper-box subclass substrate lands (value-rep follow-up,
177
+ * pairs with #1629b boxed-primitive work), a standalone subclass of
178
+ * `Number`/`Boolean` is refused at compile time (clean CE, never invalid Wasm —
179
+ * the #1888 dual-mode invariant). gc/host mode is unaffected (the externClass
180
+ * host path handles the subclass there). See the refusal in class-bodies.ts.
181
+ */
182
+ export declare const PRIMITIVE_WRAPPER_SUBCLASS_UNSUPPORTED: ReadonlySet<string>;
183
+ /**
184
+ * (#2029) Returns true if `name` is a primitive-wrapper builtin whose
185
+ * standalone subclass construction is not yet supported (Number/Boolean) —
186
+ * used to refuse a standalone subclass of one of them. `String` is excluded
187
+ * (it works standalone). See {@link PRIMITIVE_WRAPPER_SUBCLASS_UNSUPPORTED}.
188
+ */
189
+ export declare function isPrimitiveWrapperSubclassUnsupported(name: string): boolean;
@@ -0,0 +1,12 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * Ensure the per-character simple-case mapper `__case_simple_{upper,lower}` and
4
+ * the string-level `__str_toUpperCase`/`__str_toLowerCase` rewrites are emitted.
5
+ * Idempotent. Requires an i32 array type (the same `array (mut i32)` the runtime
6
+ * uses for vectors) — we register a dedicated immutable i32 array type for the
7
+ * tables.
8
+ *
9
+ * Called from ensureNativeStringHelpers; `strTypeIdx`/`strDataTypeIdx` are the
10
+ * NativeString struct + its i16 backing-array type indices.
11
+ */
12
+ export declare function emitNativeCaseConversion(ctx: CodegenContext, strTypeIdx: number, strDataTypeIdx: number, anyStrTypeIdx: number): void;
@@ -0,0 +1,4 @@
1
+ export declare const UPPER_CASE_RUNS: readonly number[];
2
+ export declare const LOWER_CASE_RUNS: readonly number[];
3
+ export declare const UPPER_CASE_SPECIAL: readonly number[];
4
+ export declare const LOWER_CASE_SPECIAL: readonly number[];
@@ -0,0 +1,41 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { FieldDef } from '../ir/types.js';
3
+ import { CodegenContext, FunctionContext } from './context/types.js';
4
+ export declare function resolveClassMemberName(ctx: CodegenContext, name: ts.PropertyName): string | undefined;
5
+ export { classMemberFuncKey } from './class-member-keys.js';
6
+ /** Collect all function declarations and interfaces */
7
+ /** Collect a class declaration or class expression: register struct type, constructor, and methods */
8
+ export declare function collectClassDeclaration(ctx: CodegenContext, decl: ts.ClassDeclaration | ts.ClassExpression, syntheticName?: string): void;
9
+ /**
10
+ * For a generic function, find the first call site in the source and resolve
11
+ * concrete param/return types from the checker's instantiated signature.
12
+ * Returns null if no call site is found (function stays with erased types).
13
+ */
14
+ export declare const INTERNAL_FIELD_NAMES: Set<string>;
15
+ /**
16
+ * Default property flags: writable (bit 0) + enumerable (bit 1) + configurable (bit 2).
17
+ * Matches PROP_FLAG_WRITABLE | PROP_FLAG_ENUMERABLE | PROP_FLAG_CONFIGURABLE from object-ops.ts.
18
+ */
19
+ export declare const PROP_FLAGS_DEFAULT = 7;
20
+ /**
21
+ * Build the per-shape default property flags table.
22
+ * Iterates all struct types registered via structMap (classes, anonymous objects,
23
+ * interfaces, type aliases) and creates a Uint8Array of default flags for each.
24
+ * One byte per user-visible field; internal fields (__tag) are excluded.
25
+ *
26
+ * This table is purely compile-time metadata with zero runtime overhead.
27
+ * Future subtasks (#797c Object.defineProperty, #797d Object.keys) will
28
+ * emit code that reads from this table at runtime.
29
+ */
30
+ export declare function buildShapePropFlagsTable(ctx: CodegenContext): void;
31
+ /** Scan all function bodies for ref.func instructions and record their targets */
32
+ export declare function collectDeclaredFuncRefs(ctx: CodegenContext): void;
33
+ /** Compile constructor and method bodies for a class declaration */
34
+ export declare function compileClassBodies(ctx: CodegenContext, decl: ts.ClassDeclaration | ts.ClassExpression, funcByName: Map<string, number>, syntheticName?: string): void;
35
+ /**
36
+ * Compile a super(args) call inside a child constructor.
37
+ * This runs the parent constructor's field-initialization logic inline:
38
+ * for each parent field, evaluate the corresponding super argument and
39
+ * store it into the child struct (which includes parent fields at the start).
40
+ */
41
+ export declare function compileSuperCall(ctx: CodegenContext, fctx: FunctionContext, childClassName: string, selfLocal: number, callExpr: ts.CallExpression, _allFields: FieldDef[], onHost?: boolean): void;
@@ -0,0 +1,33 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * Class members register in `ctx.funcMap` under `${className}_${member}` keys
4
+ * (`A_m` for `A.m`, `A_new` for the ctor, `A_get_v` for a getter, …). A
5
+ * top-level user `function A_m() {}` would claim the same flat string key, and
6
+ * `ensureSiblingFunctionsRegistered` then *silently skips* registering the user
7
+ * function because `funcMap.has("A_m")` is already true — so `A_m()` call sites
8
+ * resolve to the class member's funcIdx (wrong signature → validation trap).
9
+ *
10
+ * The fix keeps the funcMap key **byte-identical** (`A_m`) in the overwhelming
11
+ * common case (no user function of that name), and only when a real collision
12
+ * exists relocates the *class member's* funcMap key to a form a user identifier
13
+ * cannot produce (`__cm$A_m`). The user function keeps the bare `A_m` key (it
14
+ * is no longer skipped, because the class member vacated `A_m`), so its many
15
+ * bare-call / export / ref.func consumers are untouched.
16
+ *
17
+ * IMPORTANT: this relocates ONLY the `funcMap` funcIdx key. The parallel
18
+ * membership sets (`classMethodSet`, `staticMethodSet`, `classAccessorSet`,
19
+ * `staticProps`, …) and the per-name metadata maps (`funcOptionalParams`,
20
+ * `funcRestParams`, `funcUsesArguments`, …) keep the legacy
21
+ * `${className}_${member}` string — the sets answer "is this name a class
22
+ * member?" (collision-free), and the method-dispatch consumer reads the
23
+ * metadata by the same legacy `fullName`, so producer and consumer agree.
24
+ * Producers and consumers of the funcMap **funcIdx** must both route the legacy
25
+ * name through this helper so they agree on the relocated key.
26
+ *
27
+ * Known residual (out of scope, does NOT trap): if a program declares BOTH a
28
+ * class member `A.m` *and* a user `function A_m()` *and both* carry optional /
29
+ * rest params, the two share the legacy `funcOptionalParams[A_m]` slot. This
30
+ * affects only optional-arg backfill for that pathological name clash; the
31
+ * funcIdx (the trap cause) is correctly separated.
32
+ */
33
+ export declare function classMemberFuncKey(ctx: CodegenContext, fullName: string): string;
@@ -0,0 +1,39 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ export declare const CLASS_TO_PRIMITIVE = "__class_to_primitive";
3
+ /**
4
+ * Reserve the `__class_to_primitive(externref obj, i32 stringHint) -> externref`
5
+ * placeholder and return its funcIdx. Body is a bare `unreachable` until
6
+ * `fillClassToPrimitive` patches it (after `__call_valueOf`/`__call_toString`
7
+ * are registered). Idempotent. Standalone only — the JS-host lane reduces class
8
+ * instances via the host `_hostToPrimitive` OrdinaryToPrimitive loop, so this
9
+ * driver is never reached there.
10
+ */
11
+ export declare function reserveClassToPrimitive(ctx: CodegenContext): number;
12
+ /**
13
+ * Fill the reserved `__class_to_primitive` body now that the per-struct
14
+ * `__call_valueOf` / `__call_toString` dispatchers are registered (after
15
+ * `emitToPrimitiveMethodExports`). Implements §7.1.1.1 OrdinaryToPrimitive over
16
+ * the nominal-struct dispatchers:
17
+ *
18
+ * // hint==string → try toString first, else valueOf; otherwise valueOf first.
19
+ * first = stringHint ? __call_toString : __call_valueOf
20
+ * second = stringHint ? __call_valueOf : __call_toString
21
+ * r = first(obj); if (r != null) return r // a method matched → primitive
22
+ * r = second(obj); if (r != null) return r
23
+ * return obj // neither matched — unchanged
24
+ *
25
+ * `__call_*` return a boxed primitive externref on a struct match, or
26
+ * `ref.null.extern` on no match — so a non-null result is exactly "this class
27
+ * had this method, here is its (already-boxed-primitive) result". A class with
28
+ * neither method falls through to `return obj` (today's behaviour, no
29
+ * regression). The §7.1.1.1 step-6 "must return a primitive" TypeError walk for
30
+ * a method that returns an object is intentionally NOT replicated here: the
31
+ * standalone class dispatchers box only primitive method results, and the
32
+ * dynamic-`$Object` path (which DOES do the full walk) is unaffected.
33
+ *
34
+ * No-op when the driver was not reserved or the dispatchers are missing — the
35
+ * placeholder `unreachable` stays (it is unreachable from any live arm, because
36
+ * `__to_primitive` only `call`s the driver when it itself was emitted in the
37
+ * standalone class-capable path).
38
+ */
39
+ export declare function fillClassToPrimitive(ctx: CodegenContext): void;
@@ -0,0 +1,42 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * Reserve (or fetch) the closed-struct dispatcher `__call_m_<name>_<arity>`
4
+ * funcIdx with a placeholder body. The real body is built by
5
+ * {@link fillClosedMethodDispatch} at finalize. Idempotent; records the
6
+ * (method name, arity) pair in `ctx.closedMethodDispatchNames` (encoded as
7
+ * `<name>/<arity>`). Returns the reserved funcIdx.
8
+ *
9
+ * The dispatcher signature is `(recv: externref, arg0..arg{arity-1}: externref)
10
+ * -> externref`; the call site coerces each argument to externref before the
11
+ * call, and the fill side coerces each back to the method's declared param type.
12
+ *
13
+ * Only meaningful under `ctx.standalone || ctx.wasi` — callers gate on that.
14
+ */
15
+ export declare function reserveClosedMethodDispatch(ctx: CodegenContext, methodName: string, arity?: number): number;
16
+ /**
17
+ * (#2151 Slice 4) Reserve (or fetch) the VARARG closed-struct dispatcher
18
+ * `__call_m_<name>_vararg(recv: externref, args: externref) -> externref` for a
19
+ * DYNAMIC-spread method call `o.m(...xs)` whose arity is unknown at compile time.
20
+ *
21
+ * The fill (in {@link fillClosedMethodDispatch}) type-switches over every closed
22
+ * struct having `<Struct>_<name>` exactly like the fixed-arity dispatcher, but
23
+ * sources each declared param from `__extern_get_idx(args, i)` (0..K-1, K = that
24
+ * method's declared param count) instead of from a fixed dispatcher param. The
25
+ * bottom arm forwards the SAME `args` externref to
26
+ * `__extern_method_call(recv, "<name>", args)` for the open-`$Object` case.
27
+ *
28
+ * Like the fixed-arity reserve, all fallback-arm dependencies are registered NOW
29
+ * (during compilation) so the fill only READS funcMap — `ensureObjVecBuilders`
30
+ * pulls in the object runtime including `__extern_get_idx` / `__extern_length`,
31
+ * which the per-struct arms read args through. Idempotent. Only meaningful under
32
+ * `ctx.standalone || ctx.wasi`.
33
+ */
34
+ export declare function reserveClosedMethodDispatchVararg(ctx: CodegenContext, methodName: string): number;
35
+ /**
36
+ * Fill every reserved `__call_m_<name>_<arity>` AND `__call_m_<name>_vararg`
37
+ * dispatcher body at FINALIZE. Mirrors `fillApplyClosure` (object-runtime.ts).
38
+ * Must run AFTER all object-literal struct types and their `<Struct>_<name>`
39
+ * method funcs are registered, and after `addUnionImports` (so
40
+ * `__box_number`/`__box_boolean` exist). No-op when nothing was reserved.
41
+ */
42
+ export declare function fillClosedMethodDispatch(ctx: CodegenContext): void;
@@ -0,0 +1,285 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { ValType } from '../ir/types.js';
3
+ import { ClosureInfo, CodegenContext, FunctionContext } from './context/types.js';
4
+ /**
5
+ * Collect names that are LOCALLY DECLARED inside a function-like node's scope.
6
+ * Used to compute the shadow set for free-variable analysis.
7
+ *
8
+ * Includes:
9
+ * - parameter binding identifiers (function-scoped)
10
+ * - `var` declarations anywhere in the body (function-scoped)
11
+ * - top-level `function`/`class` declarations in the body
12
+ *
13
+ * Does NOT cross nested function boundaries.
14
+ *
15
+ * Conservatively excludes block-scoped `let`/`const` since they only shadow
16
+ * within their block, and adding them to the function-wide shadow set would
17
+ * incorrectly mask legitimate outer captures.
18
+ */
19
+ export declare function collectFunctionOwnLocals(funcLike: ts.Node, out: Set<string>): void;
20
+ /**
21
+ * Collect all identifiers referenced in a node.
22
+ *
23
+ * If `shadowed` is provided, identifiers in that set are NOT collected. The
24
+ * walker also detects nested function scopes and augments the shadow set with
25
+ * each nested function's own locals so that references inside them to names
26
+ * shadowed by nested var/param decls aren't incorrectly attributed to the
27
+ * outer scope.
28
+ *
29
+ * Callers analyzing free variables of a function-like body should compute the
30
+ * function's own locals via `collectFunctionOwnLocals` and pass them as the
31
+ * initial `shadowed` set, since the walker enters the body without crossing
32
+ * the boundary itself.
33
+ */
34
+ export declare function collectReferencedIdentifiers(node: ts.Node, names: Set<string>, shadowed?: ReadonlySet<string>): void;
35
+ /**
36
+ * Collect identifiers that are WRITTEN to within a node tree.
37
+ * Detects: assignment (=, +=, etc.), ++, --.
38
+ *
39
+ * Scope-aware in the same sense as `collectReferencedIdentifiers`: writes to
40
+ * names shadowed by nested function scopes are not collected.
41
+ */
42
+ export declare function collectWrittenIdentifiers(node: ts.Node, names: Set<string>, shadowed?: ReadonlySet<string>): void;
43
+ /**
44
+ * Promote captured locals to globals for getter/setter accessor functions.
45
+ *
46
+ * When an object literal getter/setter references variables from the enclosing
47
+ * function scope, those variables need to be accessible as Wasm globals (since
48
+ * the getter/setter is compiled as a separate Wasm function).
49
+ *
50
+ * This function:
51
+ * 1. Scans the accessor body for referenced identifiers
52
+ * 2. For each that maps to a local in the enclosing fctx, creates a Wasm global
53
+ * 3. Copies the local's current value into the global
54
+ * 4. Removes the name from localMap so subsequent code uses the global
55
+ * 5. Registers in ctx.capturedGlobals for resolution in the accessor body
56
+ */
57
+ export declare function promoteAccessorCapturesToGlobals(ctx: CodegenContext, fctx: FunctionContext, accessorBody: ts.Block | undefined, extraNodes?: readonly ts.Node[]): void;
58
+ /** Collect all identifier names from a binding pattern (destructuring parameter) */
59
+ export declare function collectBindingPatternNames(pattern: ts.BindingPattern, names: Set<string>): void;
60
+ /** Check if a name is defined in any of the arrow's own parameters (including destructuring) */
61
+ export declare function isOwnParamName(arrow: ts.ArrowFunction | ts.FunctionExpression, name: string): boolean;
62
+ /**
63
+ * Emit destructuring code for an arrow function parameter that uses a binding pattern.
64
+ * The parameter value is already in a local at `paramIdx`; this emits instructions to
65
+ * extract fields/elements into new locals in the lifted function context.
66
+ */
67
+ export declare function emitArrowParamDestructuring(ctx: CodegenContext, fctx: FunctionContext, param: ts.ParameterDeclaration, paramIdx: number, paramType: ValType): void;
68
+ /**
69
+ * Emit default-value initialization for arrow/closure function parameters.
70
+ * Similar to the logic in compileFunctionBody but operates on the lifted fctx.
71
+ */
72
+ export declare function emitArrowParamDefaults(ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression, paramOffset: number): void;
73
+ /**
74
+ * Emit default-value initialization for method/setter parameters with initializers.
75
+ * For each param with a default value, check if the caller omitted it
76
+ * (externref -> ref.is_null, i32 -> i32.eqz, f64 -> f64.eq 0.0) and if so
77
+ * compile the initializer expression and assign it to the param local.
78
+ */
79
+ export declare function emitMethodParamDefaults(ctx: CodegenContext, fctx: FunctionContext, params: ts.NodeArray<ts.ParameterDeclaration>, paramOffset: number): void;
80
+ /** Check if an arrow/function expression is used as a callback argument to a call
81
+ * that targets a HOST import (not a user-defined function). User-defined functions
82
+ * should receive closures via the GC struct path, not the __make_callback host path. */
83
+ export declare function isHostCallbackArgument(node: ts.Node, ctx: CodegenContext): boolean;
84
+ /**
85
+ * Returns true if the arrow's parent CallExpression is a stored-callback host
86
+ * method (DisposableStack.defer/use/adopt etc.). The callback is not invoked
87
+ * synchronously by the call that registers it, so its captured-mutable
88
+ * writebacks must be persistent. (#1695)
89
+ */
90
+ export declare function isDeferredCallbackArgument(node: ts.Node, ctx: CodegenContext): boolean;
91
+ export declare function compileArrowFunction(ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression): ValType | null;
92
+ /** Compile an arrow function as a first-class closure value (Wasm GC struct + funcref) */
93
+ export declare function compileArrowAsClosure(ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression): ValType | null;
94
+ /** Compile an arrow function as a host callback via __make_callback.
95
+ * Captures are bundled into a per-instance GC struct (not shared globals). */
96
+ /**
97
+ * (#2128) Collect the names a callback body WRITES that resolve to locals of
98
+ * the enclosing function — i.e. its mutable captures. Used by the
99
+ * object-literal accessor path to pre-compute, across a whole get/set pair,
100
+ * which locals must be captured through a SHARED ref cell so the getter
101
+ * observes the setter's writes.
102
+ */
103
+ export declare function collectMutatedCaptureNames(fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression): Set<string>;
104
+ /** (#2128) Per-literal registry of shared capture ref cells — see compileArrowAsCallback. */
105
+ export type SharedRefCellMap = Map<string, {
106
+ refCellLocal: number;
107
+ refCellTypeIdx: number;
108
+ valType: ValType;
109
+ }>;
110
+ export declare function compileArrowAsCallback(ctx: CodegenContext, fctx: FunctionContext, arrow: ts.ArrowFunction | ts.FunctionExpression, options?: {
111
+ needsThis?: boolean;
112
+ deferredInvocation?: boolean;
113
+ /**
114
+ * (#2128) Locals to capture mutably (via ref cell) even when THIS
115
+ * callback only reads them — a sibling callback in the same object
116
+ * literal writes them, and both must see one shared cell.
117
+ */
118
+ forceMutableCaptures?: Set<string>;
119
+ /**
120
+ * (#2128) Per-object-literal shared-cell registry. The first callback
121
+ * capturing a name mutably creates the cell and records it here; sibling
122
+ * callbacks reuse it so mutations are visible across the get/set pair.
123
+ * Scoped to one literal compilation — do NOT share across loop-iteration
124
+ * callback creations (per-iteration `let` semantics need fresh cells).
125
+ */
126
+ sharedRefCells?: SharedRefCellMap;
127
+ }): ValType | null;
128
+ /** A captured local that must flow into an async continuation. */
129
+ export interface AsyncCapture {
130
+ readonly name: string;
131
+ readonly type: ValType;
132
+ readonly localIdx: number;
133
+ }
134
+ /** Result of synthesizing an async continuation `__cb_N` function. */
135
+ export interface SyntheticContinuation {
136
+ /** Callback id — the host dispatches `__cb_${cbId}(captures, awaitValue)`. */
137
+ readonly cbId: number;
138
+ /** Capture struct type index (field i holds capture[i]), or -1 if no captures. */
139
+ readonly capStructTypeIdx: number;
140
+ /** The captures, in struct-field order. */
141
+ readonly captures: readonly AsyncCapture[];
142
+ }
143
+ /**
144
+ * (#1042) Synthesize an async-continuation function for the CPS state machine.
145
+ *
146
+ * Unlike {@link compileArrowAsCallback} this is driven by an explicit statement
147
+ * list + capture set (not an arrow AST node). It emits an exported
148
+ * `__cb_${cbId}(captures: externref, awaitValue: externref) -> externref`
149
+ * function compatible with the `__make_callback` host bridge: the host invokes
150
+ * it with the settled promise value as `awaitValue`. The function restores
151
+ * captured locals from the capture struct, binds the awaited result to
152
+ * `resumeBinding` (if any), runs `segmentStmts`, and returns `ref.null.extern`
153
+ * (the host ignores a continuation's result).
154
+ *
155
+ * Returns the cbId + capture-struct info so the caller emits the creation site
156
+ * (`i32.const cbId` + capture struct + `extern.convert_any` + `__make_callback`).
157
+ *
158
+ * Captures are immutable snapshots (value-copied into the struct) — async
159
+ * continuations don't write back to the suspended frame, so no ref cells.
160
+ */
161
+ export declare function compileSyntheticAsyncContinuation(ctx: CodegenContext, outerFctx: FunctionContext, segmentStmts: readonly ts.Statement[], captures: readonly AsyncCapture[], resumeBinding: {
162
+ name: string;
163
+ type: ValType;
164
+ } | null, options?: {
165
+ returnAwaitValue?: boolean;
166
+ }): SyntheticContinuation;
167
+ /**
168
+ * Look up a function's parameter and result types from its index.
169
+ */
170
+ export declare function getFuncSignature(ctx: CodegenContext, funcIdx: number): {
171
+ params: ValType[];
172
+ results: ValType[];
173
+ } | null;
174
+ /**
175
+ * Get or create the closure struct type and lifted func type for wrapping
176
+ * plain functions with a given signature. Struct type and func type are shared
177
+ * across all functions with the same signature, but each function gets its own
178
+ * trampoline.
179
+ */
180
+ export declare function getOrCreateFuncRefWrapperTypes(ctx: CodegenContext, userParams: ValType[], resultTypes: ValType[]): {
181
+ structTypeIdx: number;
182
+ liftedFuncTypeIdx: number;
183
+ closureInfo: ClosureInfo;
184
+ } | null;
185
+ /**
186
+ * Emit a closure struct wrapping a plain function. Creates a per-function
187
+ * trampoline that delegates to the original function. Struct types are shared
188
+ * across functions with the same signature so they can be reassigned.
189
+ * Pushes the closure struct ref onto the stack and returns its type.
190
+ */
191
+ export declare function emitFuncRefAsClosure(ctx: CodegenContext, fctx: FunctionContext, funcName: string, funcIdx: number): ValType | null;
192
+ /**
193
+ * (#2025) Eagerly register the `__new_TypeError` import + the message string
194
+ * the first time an extractable method-as-closure trampoline is built, so the
195
+ * trampoline's null-`this` arm can emit a CATCHABLE TypeError throw with
196
+ * stable, shift-tracked indices (no late-import registration during the
197
+ * fragile finalize rebuild). Idempotent. Requires a live `fctx` so the flush
198
+ * lands the deferred index shift onto the surrounding function being compiled.
199
+ */
200
+ export declare function ensureNullThisTypeError(ctx: CodegenContext, fctx: FunctionContext | null): void;
201
+ /**
202
+ * #1118: Emit an object-literal method as a first-class closure value.
203
+ *
204
+ * Object-literal methods are compiled as Wasm functions with signature
205
+ * `(self_obj, ...userParams) → ret`. When the method is read as a value
206
+ * (e.g. `var f = obj.m;` or stored in the obj's own struct field), we
207
+ * need a closure-struct ref whose funcref takes `(closure_self, …userParams)`.
208
+ *
209
+ * The two signatures differ in their first param: the method expects the
210
+ * object's struct ref, the closure value passes its own closure struct.
211
+ * We bridge them with a trampoline that drops `closure_self` and pushes
212
+ * `ref.null <objStruct>` for the method's `self_obj` slot, then forwards
213
+ * the user params and tail-calls the method.
214
+ *
215
+ * The trampoline implements method extraction with unbound `this` — JS
216
+ * spec says `var f = obj.m; f();` invokes `m` with `this = undefined`
217
+ * (strict mode) or `this = globalThis` (sloppy). For methods that don't
218
+ * reference `this` (the common test262 yield-star pattern), the null
219
+ * `self_obj` is fine; methods that DO use `this` will trap inside the
220
+ * body, mirroring spec semantics.
221
+ *
222
+ * Returns the closure-struct ref ValType (which the caller can convert
223
+ * to externref via `extern.convert_any` if the field type expects it).
224
+ */
225
+ export declare function emitObjectMethodAsClosure(ctx: CodegenContext, fctx: FunctionContext, methodName: string, methodFuncIdx: number, objStructTypeIdx: number): ValType | null;
226
+ /**
227
+ * (#1602) Rebuild every object-method-as-closure trampoline body against the
228
+ * method's FINAL signature. Must run after all function bodies are compiled
229
+ * (so `func.typeIdx` re-resolution has settled) and BEFORE late-import index
230
+ * shifting, since the rebuilt body re-emits `call methodFuncIdx` at the current
231
+ * (pre-shift) index — the shift machinery then walks it like any other body.
232
+ *
233
+ * The trampoline's own signature (its wrapper func type) is left untouched; we
234
+ * only fix the forwarding body so its `local.get` count and the `call`'s
235
+ * operand types match the method's resolved params. The wrapper's user-param
236
+ * count is invariant (derived from the same method), so the trampoline param
237
+ * indices stay valid; only the per-arg coercion is what could drift, and any
238
+ * coercion the call needs is applied by mirroring the method's param types.
239
+ */
240
+ export declare function finalizeMethodTrampolines(ctx: CodegenContext): void;
241
+ /**
242
+ * (#1394) Emit a cached singleton closure for a class method, preserving
243
+ * identity: every emit of `C.prototype.<method>` (or `instance.<method>`
244
+ * as a value) returns the same externref so JS's `===` works (e.g.
245
+ * `c.m === C.prototype.m`). 478 tests under
246
+ * `language/{expressions,statements}/class/elements/*` exercise this
247
+ * exact assertion via `verifyProperty(C.prototype, "m", { value: m })`.
248
+ *
249
+ * The cache is a per-class-method module-level externref global,
250
+ * lazily initialised on first access (matches the existing
251
+ * `emitLazyProtoGet` pattern). The canonical trampoline is registered
252
+ * once per method too — its name is
253
+ * `__obj_meth_tramp_${methodName}_cached`, distinct from the legacy
254
+ * per-call-site `__obj_meth_tramp_${methodName}_${counter}` that
255
+ * `emitObjectMethodAsClosure` emits.
256
+ *
257
+ * Returns `true` if the access was emitted; `false` if the method's
258
+ * signature couldn't be resolved (caller should fall back).
259
+ */
260
+ export declare function emitCachedMethodClosureAccess(ctx: CodegenContext, fctx: FunctionContext, methodName: string, methodFuncIdx: number, objStructTypeIdx: number): boolean;
261
+ /**
262
+ * (#1340) Emit a cached singleton closure for a top-level function declaration
263
+ * used as a first-class value. Mirrors `emitCachedMethodClosureAccess` (#1394)
264
+ * for the function-decl case.
265
+ *
266
+ * Without caching, every textual occurrence of `foo` (in value position)
267
+ * compiled a fresh `struct.new $closure_struct`, so `foo === foo` was false
268
+ * and sidecar writes on `foo.prototype` keyed by the struct identity never
269
+ * round-tripped (test262 Iterator helpers misclassified as `wasm_compile`).
270
+ *
271
+ * One externref cache global per function name, lazily initialised on first
272
+ * read; all later reads return the same externref. Call dispatch is unchanged
273
+ * (resolved via `funcMap` + direct `call funcIdx`); only the value-context
274
+ * read uses the cached closure.
275
+ *
276
+ * Only safe for captureless functions — captures must be filled at the
277
+ * per-construction site, not once at module init.
278
+ *
279
+ * Returns the closure struct's `ref` ValType when the cached access was
280
+ * emitted (so downstream consumers like array-methods.ts can take the
281
+ * direct `call_ref` fast path against the closure's funcref slot rather
282
+ * than the externref-bridge slow path through `__call_2_f64`). Returns
283
+ * `null` when the signature couldn't be resolved (caller falls back).
284
+ */
285
+ export declare function emitCachedFuncClosureAccess(ctx: CodegenContext, fctx: FunctionContext, funcName: string, funcIdx: number): ValType | null;