@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,171 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ export declare const FLAG_INTERNAL = 16;
3
+ /**
4
+ * Reserved own-key under which a boxed primitive wrapper stores its internal
5
+ * `[[PrimitiveValue]]` slot (#1910/#1472 S2). Uses the spec internal-slot
6
+ * spelling so it cannot collide with an ordinary identifier-shaped key created
7
+ * by user code in any realistic program; the entry is additionally flagged
8
+ * FLAG_INTERNAL so even an explicit `o["[[PrimitiveValue]]"]` user write is
9
+ * distinguishable, and it is non-enumerable so enumeration never observes it.
10
+ */
11
+ export declare const WRAPPER_PRIMITIVE_KEY = "[[PrimitiveValue]]";
12
+ /**
13
+ * Type indices for the open-object runtime structs/arrays, allocated once per
14
+ * module by `ensureObjectRuntime`. Stored on the context so subsequent slices
15
+ * (keys/values/delete/for-in) can reference the same types.
16
+ */
17
+ export interface ObjectRuntimeTypes {
18
+ propEntryTypeIdx: number;
19
+ propMapTypeIdx: number;
20
+ objectTypeIdx: number;
21
+ /** `$ObjVec` struct {len: i32, data: (ref (array (mut externref)))} — the
22
+ * growable externref vector that backs standalone `Object.keys/values/entries`
23
+ * enumeration results (#1472 Phase B Blocker B). */
24
+ objVecTypeIdx: number;
25
+ /** Backing `(array (mut externref))` for `$ObjVec.data`. */
26
+ objVecArrTypeIdx: number;
27
+ /** (#1100) `$ProxyTraps` struct — 4 funcref fields (get/set/has/apply) for the
28
+ * standalone Proxy meta-object Phase 1. Null fields forward to the ordinary
29
+ * [[Get]]/[[Set]]/[[Has]]/[[Call]] on the target. */
30
+ proxyTrapsTypeIdx: number;
31
+ /** (#1100) `$Proxy` struct — subtype of `$Object` carrying the proxy tag,
32
+ * target, handler, traps, and revoked bit. A proxy IS-A object, so every
33
+ * `ref.test $Object` still matches it. */
34
+ proxyTypeIdx: number;
35
+ }
36
+ /**
37
+ * Idempotently register the open-object runtime types + helper functions as
38
+ * defined Wasm functions in `ctx.funcMap` (under the host-import names the call
39
+ * sites already look up). Safe to call repeatedly; only the first call emits.
40
+ *
41
+ * MUST run after `ensureNativeStringHelpers` (it depends on `__str_flatten` /
42
+ * `__str_equals` and the `$NativeString` type indices) — we call it here to
43
+ * guarantee that. Because this path adds only DEFINED functions (no imports),
44
+ * the freshly-allocated func indices sit above every existing function and no
45
+ * index shift is required (same invariant as `addUnionImportsAsNativeFuncs`).
46
+ *
47
+ * That invariant only holds when NO late-import batch is pending: a deferred
48
+ * `ensureLateImport` shift (ctx.pendingLateImportShift) would later add its
49
+ * delta to every funcIdx >= its importsBefore — including the indices this
50
+ * function is about to bake with the post-batch `numImportFuncs` — leaving
51
+ * funcMap and every internal sibling call one regime too high while the
52
+ * function itself sits lower (#2039: `__obj_find` calling `__new_plain_object`
53
+ * instead of `__obj_hash`, 146 invalid-Wasm test262 binaries). So we end any
54
+ * pending batch first; registration then happens in a clean, final regime.
55
+ */
56
+ export declare function ensureObjectRuntime(ctx: CodegenContext): ObjectRuntimeTypes;
57
+ /**
58
+ * (#1100) Fill the reserved Proxy trap-invoke driver bodies at FINALIZE, AFTER
59
+ * `emitClosureMethodCallExportN(2..4)` have registered `__call_fn_method_2/3/4`
60
+ * in `funcMap`. Each driver is a thin wrapper around the closure-call bridge
61
+ * that threads the handler as `this` and forwards the spec trap args:
62
+ *
63
+ * __proxy_call_get(handler, trap, target, key, receiver)
64
+ * = __call_fn_method_3(handler, trap, target, key, receiver)
65
+ * __proxy_call_set(handler, trap, target, key, value, receiver)
66
+ * = __call_fn_method_4(handler, trap, target, key, value, receiver)
67
+ * __proxy_call_has(handler, trap, target, key)
68
+ * = __call_fn_method_2(handler, trap, target, key)
69
+ *
70
+ * No-op when the proxy runtime was never reserved (`ctx.proxyDispatchReserved`).
71
+ * When a driver WAS reserved but the matching dispatcher was never emitted (no
72
+ * closure of that arity exists — so no real trap of that arity could have been
73
+ * installed either), the body is filled with `ref.null.extern` so the module
74
+ * still verifies — mirrors `fillAccessorDrivers` / `fillApplyClosure`.
75
+ */
76
+ export declare function fillProxyDispatch(ctx: CodegenContext): void;
77
+ /**
78
+ * #1472 Phase B Slice 3 — the native `$ObjVec` builder funcIdxs that the
79
+ * `Object.assign(target, ...sources)` / object-spread call sites use to build
80
+ * the variadic `...sources` list under `--target standalone`. In JS-host mode
81
+ * those sites build a real JS array via the `__js_array_new` / `__js_array_push`
82
+ * host imports and hand it to `__object_assign`; standalone has no JS array, so
83
+ * they build a `$ObjVec` (which the native `__object_assign` iterates via
84
+ * `ref.test $ObjVec`) instead. Returns `{ newIdx, pushIdx }`, registering the
85
+ * object runtime on first call. Signatures match the host imports exactly —
86
+ * `__objvec_new : () -> externref`, `__objvec_push : (externref, externref) ->
87
+ * void` — so the only call-site change is *which funcIdx* the existing builder
88
+ * code calls.
89
+ */
90
+ export declare function ensureObjVecBuilders(ctx: CodegenContext): {
91
+ newIdx: number;
92
+ pushIdx: number;
93
+ };
94
+ /**
95
+ * (#1888 Slice 1) Reserve the `__apply_closure(externref fn, externref recv,
96
+ * externref args) -> externref` arity-bridge funcIdx with a placeholder
97
+ * `unreachable` body, registered in `funcMap`. The real body (an arity switch
98
+ * on `__extern_length(args)` dispatching to `__call_fn_method_0..4`) is filled
99
+ * by `fillApplyClosure` at FINALIZE, because the `__call_fn_method_N` exports
100
+ * it calls are only emitted there (after `closureInfoByTypeIdx` is complete).
101
+ * Mirrors the `reserveProtoIteratorDriver`/`fillProtoIteratorDriver` pattern
102
+ * (#1719). Idempotent. Sets `ctx.applyClosureReserved`.
103
+ */
104
+ export declare function reserveApplyClosure(ctx: CodegenContext): number;
105
+ /**
106
+ * (#1888 Slice 1) Fill the reserved `__apply_closure` bridge body at FINALIZE,
107
+ * AFTER `emitClosureMethodCallExportN(0..4)` have registered
108
+ * `__call_fn_method_0..4` in `funcMap`. The bridge reads the dynamic arg count
109
+ * from `__extern_length(args)` and dispatches to the matching this-threaded
110
+ * closure dispatcher:
111
+ *
112
+ * n = i32(__extern_length(args))
113
+ * if n==0: __call_fn_method_0(recv, fn)
114
+ * if n==1: __call_fn_method_1(recv, fn, idx0)
115
+ * ... up to 4 ...
116
+ * else (n>4): return undefined (sentinel)
117
+ *
118
+ * S1 SCOPE — NO THROWS. This bridge returns the undefined sentinel
119
+ * (`ref.null.extern`) for the not-a-function and arity-overflow cases rather
120
+ * than raising a `TypeError`. Reason: emitting a spec-correct throw here would
121
+ * pull `__new_TypeError` + the exn tag + a string constant into the object
122
+ * runtime, and those late registrations land AFTER the string helpers have
123
+ * already baked `call` targets at finalize — shifting func indices and
124
+ * corrupting the module ("__str_flatten expected (ref null 5) found i32"). That
125
+ * is the #1839/#117/#1886 late-registration-index-shift class. Carving S1
126
+ * without throws keeps the bridge dependency-free of late error machinery, so
127
+ * the module verifies cleanly. The spec-correct `TypeError` throws (ES §7.3.14
128
+ * step 2 "is not a function", and arity-overflow) plus the index-shift fix are
129
+ * the S2 fast-follow. Each `__call_fn_method_N` arm is only emitted when that
130
+ * export was registered (no closure of arity ≤ N ⇒ no dispatcher ⇒ that arm
131
+ * returns the undefined sentinel). No-op when `__apply_closure` was never
132
+ * reserved.
133
+ */
134
+ export declare function fillApplyClosure(ctx: CodegenContext): void;
135
+ /**
136
+ * (#1904) Fill the standalone native `__extern_is_array` predicate after all
137
+ * user functions and late runtime helpers have registered their WasmGC carrier
138
+ * types. Implements the non-Proxy subset of ES §7.2.2 IsArray that can exist in
139
+ * standalone: primitives/non-array objects return false, and compiler-emitted
140
+ * array carriers (`__vec_*`, template vectors, `$ObjVec`) return true.
141
+ */
142
+ export declare function fillExternIsArray(ctx: CodegenContext): void;
143
+ /**
144
+ * (#2190) Fill `__extern_get_idx`'s typed-`__vec_<elemKind>` indexing arms after
145
+ * every module-local array carrier is registered. Sibling of the #2189
146
+ * `.length`-through-the-boundary fix: a real array literal lowers to a
147
+ * `__vec_<elemKind>` struct, and a NUMERIC index on it through the externref
148
+ * boundary (`(arr as any)[i]`) routes here. Without these arms, only `$ObjVec`
149
+ * (enumeration results) and array-like `$Object` are recognised, so a boxed
150
+ * `__vec_f64`/`__vec_<str>` falls through to null (number→0, ref→null).
151
+ *
152
+ * Unlike `.length` (one i32 at field 0, readable uniformly via the `$__vec_base`
153
+ * supertype), element reads are element-type-polymorphic: each carrier has a
154
+ * different `data` array element type and the loaded element must be boxed to
155
+ * externref per kind. So we emit one `ref.test`/`ref.cast` arm per carrier with
156
+ * its own bounds check + per-kind boxing (`boxVecElementToExternref`).
157
+ *
158
+ * Standalone only (gated by `ctx.externGetIdxReserved`, set in standalone). Edits
159
+ * the body in place — no funcIdx churn, so cached call targets stay valid.
160
+ */
161
+ export declare function fillExternGetIdxVecArms(ctx: CodegenContext): void;
162
+ /**
163
+ * Names of the object-runtime host imports that `ensureObjectRuntime` provides
164
+ * Wasm-native implementations for. `ensureLateImport` routes these here under
165
+ * `ctx.standalone` (mirrors `UNION_NATIVE_HELPER_NAMES` for the #1471 boxing
166
+ * helpers) so existing call sites resolve to the native func with no per-site
167
+ * change. Internal helpers (`__obj_hash`, `__obj_find`, `__obj_insert`,
168
+ * `__obj_grow`) are NOT in this set — they are never requested via
169
+ * `ensureLateImport`.
170
+ */
171
+ export declare const OBJECT_RUNTIME_HELPER_NAMES: ReadonlySet<string>;
@@ -0,0 +1,10 @@
1
+ import { CodegenContext } from './context/types.js';
2
+ /**
3
+ * Emit native `parseInt` / `parseFloat` functions and register them in
4
+ * `ctx.funcMap` (and a dedicated set on ctx for idempotency). Must run before
5
+ * any function bodies that `call ctx.funcMap.get("parseInt")` are compiled, and
6
+ * after `ensureNativeStringHelpers` (which it calls) so `__str_flatten` exists.
7
+ *
8
+ * @param which Set of names to emit — subset of {"parseInt","parseFloat"}.
9
+ */
10
+ export declare function emitNativeParseNumber(ctx: CodegenContext, which: Set<string>): void;
@@ -0,0 +1,6 @@
1
+ import { WasmModule } from '../ir/types.js';
2
+ /**
3
+ * Run peephole optimizations on all function bodies in a WasmModule.
4
+ * Returns the total number of instructions eliminated.
5
+ */
6
+ export declare function peepholeOptimize(mod: WasmModule): number;
@@ -0,0 +1,294 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { Instr, ValType } from '../ir/types.js';
3
+ import { CodegenContext, FunctionContext } from './context/types.js';
4
+ /**
5
+ * #2020: resolve an inherited static-property global by walking the class
6
+ * parent chain (classParentMap), retrying `<Ancestor>_<prop>` at each level.
7
+ * Static fields, like static methods, are inherited: `class B extends A {}`
8
+ * sees `A`'s static fields through `B`. Returns the owning ancestor's global
9
+ * index, or undefined when no ancestor declares the property. Callers run the
10
+ * own-class lookup first, so own statics correctly shadow inherited ones.
11
+ */
12
+ export declare function resolveInheritedStaticProp(ctx: CodegenContext, className: string, propName: string): number | undefined;
13
+ /**
14
+ * (#2201) ES §13.15.2 NamedEvaluation for the logical-assignment operators
15
+ * (`&&=`, `||=`, `??=`): when the LHS is a bare IdentifierReference and the RHS
16
+ * is an *anonymous* function/arrow/class definition, the resulting function
17
+ * inherits the LHS identifier as its `.name`.
18
+ *
19
+ * This compiler resolves `.name` statically from a binding's initializer, which
20
+ * misses the logical-assignment form (`var value = 1; value &&= function(){}`)
21
+ * because the variable's initializer is not the function. Here we scan the
22
+ * declaration's source for a logical-assignment `<id> &&=/||=/??= <fn>` targeting
23
+ * the same symbol and apply NamedEvaluation. A *named* function/class RHS keeps
24
+ * its own name (the LHS identifier is ignored, per spec).
25
+ *
26
+ * Returns the inferred `.name` string, or undefined when no qualifying
27
+ * logical-assignment is found.
28
+ */
29
+ export declare function resolveLogicalAssignmentName(ctx: CodegenContext, id: ts.Identifier, sym: ts.Symbol): string | undefined;
30
+ /**
31
+ * (#2201) True when `node` is a `<id>.name` read whose receiver `<id>` is the
32
+ * target of a logical-assignment NamedEvaluation (`id &&=/||=/??= <fn>`). Such a
33
+ * read lowers (via the property-access `.name` static resolver above) to a
34
+ * native-string ref, but the receiver's *TS* type is `number`/`any`, so an
35
+ * equality like `id.name === "x"` would otherwise fall through to `ref.eq`
36
+ * (struct identity → always false). Used by the binary-op equality dispatch to
37
+ * route it to content-based string equality — mirrors the catch-bound Error
38
+ * `.message`/`.name`/`.stack` handling (#2192).
39
+ */
40
+ export declare function isLogicalAssignNamedEvalNameRead(ctx: CodegenContext, node: ts.Expression): boolean;
41
+ /**
42
+ * Consume an externref value and push the Array.isArray boolean result.
43
+ *
44
+ * Spec basis: ECMA-262 §23.1.2.3 delegates to IsArray (§7.2.2).
45
+ *
46
+ * Two regimes (#2047 — unified):
47
+ *
48
+ * - **`--target standalone`**: route through the in-module native
49
+ * `__extern_is_array` helper. That helper is reserved with the object runtime
50
+ * and *filled at finalize* (`fillExternIsArray`) with the COMPLETE, filtered
51
+ * array-carrier list, so a value-read of `Array.isArray` taken before a later
52
+ * array type (e.g. `boolean[]` → `__vec_i32`) is registered no longer bakes an
53
+ * incomplete `ref.test` chain. This both fixes the first-emission snapshot bug
54
+ * (`const f = Array.isArray; f(boolean[])` ⇒ `false`) and excludes the
55
+ * exclusively-non-array byte carriers (`i32_byte` ArrayBuffer/DataView,
56
+ * `i8_byte` Uint8Array) per §7.2.2.
57
+ * - **Host / WASI**: keep the inline `ref.test` chain over every registered vec
58
+ * type (it detects compiled WasmGC array values materialised into an externref
59
+ * slot — #1678), ORed in host mode with the real JS `Array.isArray` host
60
+ * predicate for foreign JS arrays (#1328). Host output is unchanged.
61
+ */
62
+ export declare function emitArrayIsArrayExternrefPredicate(ctx: CodegenContext, fctx: FunctionContext): void;
63
+ /**
64
+ * Resolve the struct name for a TypeScript type by consulting structMap,
65
+ * classExprNameMap, and anonTypeMap.
66
+ */
67
+ export declare function resolveStructName(ctx: CodegenContext, tsType: ts.Type): string | undefined;
68
+ /**
69
+ * Resolve a struct name for a property access/assignment target expression,
70
+ * with fallbacks for widened variables and `this` in function constructors.
71
+ */
72
+ export declare function resolveStructNameForExpr(ctx: CodegenContext, fctx: FunctionContext, expression: ts.Expression): string | undefined;
73
+ /**
74
+ * (#1239) Same role as `resolveStructName(ctx, type)`, but consults
75
+ * `ctx.externrefAccessorVars` first so an Identifier holding an
76
+ * accessor-bearing object literal force-bails to the externref path.
77
+ *
78
+ * Use this at every site that previously called `resolveStructName(ctx,
79
+ * <type-of-some-expression>)` when the underlying expression is
80
+ * available, so the externref-tag override propagates uniformly.
81
+ *
82
+ * Sites without an expression (synthesized type arguments etc.) keep
83
+ * calling `resolveStructName` directly — they can't involve an
84
+ * accessor-tagged variable by construction.
85
+ */
86
+ export declare function resolveEffectiveStructName(ctx: CodegenContext, expression: ts.Expression | undefined, fallbackType: ts.Type): string | undefined;
87
+ /**
88
+ * Check if a type looks like an IteratorResult (has .value and .done properties)
89
+ * even if the type checker doesn't resolve it as IteratorResult directly.
90
+ * This handles cases where the type is a union (IteratorYieldResult | IteratorReturnResult).
91
+ */
92
+ export declare function isGeneratorIteratorResultLike(ctx: CodegenContext, type: ts.Type, propName: string): boolean;
93
+ /**
94
+ * Get the value type T from IteratorResult<T>.
95
+ * Returns the ValType for the value, or null if not determinable.
96
+ */
97
+ export declare function getIteratorResultValueType(ctx: CodegenContext, type: ts.Type): ValType | null;
98
+ /**
99
+ * Returns true when the expression is guaranteed to produce a non-null value,
100
+ * allowing the caller to skip runtime null guards.
101
+ *
102
+ * Provably non-null cases:
103
+ * - `new Foo()` — constructor always returns an object
104
+ * - `{ x: 1 }` — object literals are never null
105
+ * - `[1, 2]` — array literals are never null
106
+ * - `"str"` / template — string literals are never null
107
+ * - Parenthesized wrapper around any of the above
108
+ */
109
+ export declare function isProvablyNonNull(expr: ts.Expression, checker?: ts.TypeChecker): boolean;
110
+ export declare function typeErrorThrowInstrs(ctx: CodegenContext, node?: ts.Node): Instr[];
111
+ /**
112
+ * Emit a null check on the ref currently on the stack. If null, throws
113
+ * TypeError via the exception tag. If non-null, the ref remains on the stack.
114
+ * The `refType` should be the nullable ref type of the value on the stack.
115
+ *
116
+ * Stack: [ref_null T] -> [ref_null T] (non-null at runtime after this point)
117
+ */
118
+ export declare function emitNullCheckThrow(ctx: CodegenContext, fctx: FunctionContext, refType: ValType, node?: ts.Node): void;
119
+ /**
120
+ * (#2655) Symmetric WRITE counterpart to the read-side multi-struct dispatch
121
+ * (`findAlternateStructsForField` + `struct.get` chain at the `__extern_get`
122
+ * fallback). The member-READ path resolves `any`/`externref` receivers that are
123
+ * actually typed WasmGC structs via `struct.get <slot>`; the member-WRITE path
124
+ * historically went straight to `__extern_set`, which `_safeSet` routes to a
125
+ * JS-side SIDECAR map — it CANNOT write the WasmGC struct slot. Result: reads
126
+ * see the slot, writes update the sidecar, and the two diverge (acorn's
127
+ * `this.pos += 1` loop never advances → infinite loop).
128
+ *
129
+ * This emits, for each struct candidate that has a field named `propName`:
130
+ * local.get <recvAnyLocal>
131
+ * ref.test <structTypeIdx>
132
+ * (if (then local.get recvAny; ref.cast struct; local.get <valExtLocal>;
133
+ * <coerce externref -> fieldType>; struct.set struct <slot> )
134
+ * (else <next candidate, or the externSetFallback> ))
135
+ *
136
+ * `recvAnyLocal` must hold the receiver as `anyref` (caller does
137
+ * `local.get objExt; any.convert_extern; local.set recvAny`). `valExtLocal`
138
+ * holds the value as `externref` (boxed). `externSetFallback` is the terminal
139
+ * else-arm (the existing `__extern_set`/`__extern_set_strict` sequence) — still
140
+ * required for genuine host externrefs and dynamic-only (sidecar) properties.
141
+ *
142
+ * Returns `true` if at least one struct.set arm was emitted (caller must NOT
143
+ * also emit its own `__extern_set` — it's already the else-arm here), or `false`
144
+ * when there are no struct candidates (caller emits its `__extern_set` as
145
+ * before).
146
+ */
147
+ export declare function emitAlternateStructSetDispatch(ctx: CodegenContext, fctx: FunctionContext, recvExtLocal: number, valExtLocal: number, propName: string, strict: boolean): boolean;
148
+ /**
149
+ * Find all struct types (other than excludeTypeIdx) that have a field named
150
+ * propName. Returns an array of {structTypeIdx, fieldIdx, fieldType} for
151
+ * each matching struct type. Used for multi-struct dispatch when the primary
152
+ * ref.test fails (the object may be a valid GC struct of a different type).
153
+ * When excludeTypeIdx is -1, no type is excluded (useful for the externref path
154
+ * where there is no primary struct type).
155
+ */
156
+ export declare function findAlternateStructsForField(ctx: CodegenContext, propName: string, excludeTypeIdx: number): {
157
+ structTypeIdx: number;
158
+ fieldIdx: number;
159
+ fieldType: ValType;
160
+ mutable: boolean;
161
+ }[];
162
+ export declare function emitNullGuardedStructGet(ctx: CodegenContext, fctx: FunctionContext, objType: ValType, fieldType: ValType, typeIdx: number, fieldIdx: number, propName?: string, throwOnNull?: boolean): void;
163
+ export declare function emitExternrefToStructGet(ctx: CodegenContext, fctx: FunctionContext, fieldType: ValType, structTypeIdx: number, fieldIdx: number, propName?: string, throwOnNull?: boolean): void;
164
+ export declare function compileOptionalPropertyAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression): ValType | null;
165
+ /** Helper: compile extern property get when receiver is already on stack */
166
+ export declare function compileExternPropertyGetFromStack(ctx: CodegenContext, fctx: FunctionContext, objType: ts.Type, propName: string): void;
167
+ /**
168
+ * (#2192 follow-up) Recognize a receiver expression that is itself a caught-Error
169
+ * string-field read — i.e. `<catchBinding>.message` / `.name` / `.stack`. In
170
+ * standalone mode the #2077/#2192 fast path lowers that read to a `$Error_struct`
171
+ * `struct.get` coerced to a native-string ref (`$AnyString`), so at the VALUE
172
+ * level the result IS a string. But the receiver's static TS type is `any` (the
173
+ * catch binding is `any`), so the `.length` / string-method dispatch sites —
174
+ * which gate on `isStringType(<static type>)` — never fire, and
175
+ * `e.message.length` / `e.message.charCodeAt(0)` fall through to the host
176
+ * `__extern_get` path (null standalone → 0). This predicate lets those consumer
177
+ * sites treat such a receiver as string-typed and route through the
178
+ * native-string path.
179
+ *
180
+ * Scope: standalone/WASI only (the fast path that produces a string ref is
181
+ * standalone-gated), `message`/`name`/`stack` only (the fields the read fast path
182
+ * handles), and only when the inner receiver is a catch binding (so a plain
183
+ * `obj.message` on a real object is unaffected — it keeps its own typed path).
184
+ * `.cause` is intentionally NOT covered: it is not a `$Error_struct` field yet
185
+ * (deferred follow-up).
186
+ */
187
+ export declare function receiverIsCaughtErrorStringRead(ctx: CodegenContext, recv: ts.Expression): boolean;
188
+ /**
189
+ * (#2187) Recognize a receiver IDENTIFIER whose TS static type is `any`/`unknown`
190
+ * but whose compiled local/param **ValType is a native-string ref**
191
+ * (`$AnyString` / `$NativeString`). This is the general "TS type vs local
192
+ * ValType disagreement" case behind the #2072 value-rep family: e.g. a for-of
193
+ * loop var bound from a string-yielding generator (`for (const v of g())`)
194
+ * infers `any` (no lib types in standalone) yet is compiled to a `(ref null
195
+ * $AnyString)` local. Without this, `v.length` / `v.charCodeAt(0)` gate on
196
+ * `isStringType(<static type>)` → false → the read falls to the generic
197
+ * externref/`__extern_get` path and returns 0.
198
+ *
199
+ * Strictly gated: standalone/WASI only (where native string refs exist), only a
200
+ * bare identifier (so a `.foo` property read or a real object keeps its own
201
+ * typed path), only when the TS type is `any`/`unknown` (a concrete non-string
202
+ * type is unaffected), and only when the resolved local ValType is exactly the
203
+ * native string ref type. Returns false for everything else — byte-identical for
204
+ * the common case.
205
+ */
206
+ export declare function receiverIsNativeStringValType(ctx: CodegenContext, fctx: FunctionContext, recv: ts.Expression): boolean;
207
+ /**
208
+ * (#2576, extends #2187) Generalisation of {@link receiverIsNativeStringValType}
209
+ * (which only catches a bare identifier whose *compiled local ValType* is a
210
+ * native string ref) to *any* `any`/`unknown`-typed receiver whose *runtime*
211
+ * value may be a native `$AnyString` even though no local ValType says so —
212
+ * object property values (`o.v`), generator yield reads, catch bindings, indexed
213
+ * element reads (`Object.values(o)[0]`), nested reads (`o.a.b`). These compile to
214
+ * an opaque `externref`, so the value can only be recognised at runtime: callers
215
+ * MUST emit a `ref.test $AnyString` guard (see
216
+ * {@link emitGuardedNativeStringLength} and `compileGuardedNativeStringMethodCall`)
217
+ * and keep the prior behaviour in the else arm for non-string values.
218
+ *
219
+ * Narrow scope: `any`/`unknown` only (NOT `object`/`{}`, NOT unions containing
220
+ * `string`), native-string mode only (host/gc mode's generic `__extern_get`
221
+ * already returns the correct length from the real JS value).
222
+ */
223
+ export declare function receiverMayBeNativeStringAtRuntime(ctx: CodegenContext, recv: ts.Expression): boolean;
224
+ /**
225
+ * (#2731) Symmetric mirror of `tryEmitDeleteAwareDynamicGet` for the WRITE side.
226
+ *
227
+ * In a module that contains a member-`delete`, `ctx.moduleUsesDelete` routes
228
+ * `any`/`unknown`-receiver property READS through the tombstone-aware host
229
+ * `__extern_get` (above). The corresponding WRITE had no symmetric gate, so
230
+ * `o.x = 9` still took the native `struct.set` fast-path
231
+ * (`emitAlternateStructSetDispatch`), which **bypasses `_safeSet`** — the host
232
+ * function where the delete-tombstone (`_wasmStructDeletedKeys`) is cleared on
233
+ * re-assignment (`runtime.ts`). Result: `delete o.x; o.x = 9` left the tombstone
234
+ * set, so every tombstone-consulting reader (`__extern_get`, `__for_in_has`,
235
+ * `_wasmStructHasOwn`, `__object_keys`) suppressed the re-added key
236
+ * (`o.x === undefined`, `"x" in o === false`, for-in dropped `x`).
237
+ *
238
+ * This reroutes the `any`-receiver write through the strict host setter
239
+ * `__extern_set_strict` → `_safeSet`, which clears the tombstone, writes the
240
+ * sidecar, AND mirrors the native field via `__sset_<key>` — so read/write stay
241
+ * symmetric. Returns the assignment-result type when handled, else `undefined`
242
+ * (caller falls through to the native struct-set dispatch). Gated identically to
243
+ * the read side: `moduleUsesDelete && !standalone`, `any`/`unknown` receiver,
244
+ * non-reserved-accessor, non-callable property. Delete-free modules are
245
+ * untouched (`moduleUsesDelete` false → byte-identical).
246
+ */
247
+ export declare function tryEmitDeleteAwareDynamicSet(ctx: CodegenContext, fctx: FunctionContext, target: ts.PropertyAccessExpression, value: ts.Expression, objType: ts.Type, propName: string): ValType | undefined;
248
+ export declare function compilePropertyAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression): ValType | null;
249
+ /**
250
+ * Emit a bounds-checked array.get. Stack must contain [arrayref, i32 index].
251
+ * If the index is out of bounds (< 0 or >= array.len), a default value for the
252
+ * element type is produced instead of trapping.
253
+ */
254
+ export declare function emitBoundsGuardedArraySet(fctx: FunctionContext, vecLocal: number, vecTypeIdx: number, idxLocal: number, valLocal: number, arrTypeIdx: number): void;
255
+ /**
256
+ * Check if an element access expression matches a safe bounds-check-eliminated
257
+ * pattern from a for-loop (e.g., arr[i] inside `for (...; i < arr.length; ...)`).
258
+ */
259
+ export declare function isSafeBoundsEliminated(fctx: FunctionContext, expr: ts.ElementAccessExpression): boolean;
260
+ /**
261
+ * (#1742) Read-site guard-convert for a `this`-receiver that lowered to an
262
+ * externref but, at runtime, may carry a compiled WasmGC value (a `$vec` array
263
+ * or a named struct).
264
+ *
265
+ * When a closure body reads `this[i]` / `this.length` / `this.member` and `this`
266
+ * resolves to the `__current_this` module global (host-dispatched via
267
+ * `__call_fn_method_N`, #1636-S1), the resolved value is a literal **externref**.
268
+ * The realistic override `Array.prototype[Symbol.iterator] = function*(){…this[0]…}`
269
+ * has no `this:` annotation, so TS infers `this: any` → externref; a static-type
270
+ * gate NEVER fires (CPR_DEBUG-confirmed). The discriminator MUST therefore be a
271
+ * **runtime `ref.test`**, not the static type.
272
+ *
273
+ * Emits `any.convert_extern` then, for each candidate `targetTypeIdx`, a
274
+ * `ref.test`-guarded branch: on the FIRST hit the value is `ref.cast` to that
275
+ * concrete ref and `thenEmit(concreteType)` runs the vec/struct read; if NONE
276
+ * match the value is a genuine host externref and `elseEmit()` runs the host read
277
+ * path. Both arms must leave a single value of `resultType` (read-site-guard
278
+ * steer, NOT resolve-at-source — a real host `this` passes through unchanged).
279
+ * Generic over receiver shape — consumed by #1719 (vec) and #1629 (struct getters).
280
+ *
281
+ * Stack: [externref] -> [resultType].
282
+ */
283
+ export declare function emitThisReceiverGuardConvert(ctx: CodegenContext, fctx: FunctionContext, targetTypeIdxs: number[], resultType: ValType, thenEmit: (concreteType: ValType) => void, elseEmit: () => void): void;
284
+ /**
285
+ * Optional element access `a?.[i]` (#2050). On a nullish base the index
286
+ * expression — and any side effects in it — must NOT evaluate, and the result
287
+ * is undefined-equivalent (§13.3.9 Optional Chains). Sibling of
288
+ * compileOptionalPropertyAccess: tee the base into a local, branch on
289
+ * `ref.is_null`, and emit the index + read only in the non-null arm.
290
+ */
291
+ export declare function compileOptionalElementAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.ElementAccessExpression): ValType | null;
292
+ export declare function compileElementAccess(ctx: CodegenContext, fctx: FunctionContext, expr: ts.ElementAccessExpression): ValType | null;
293
+ /** Inner element access logic — assumes objType is on the stack and non-null */
294
+ export declare function compileElementAccessBody(ctx: CodegenContext, fctx: FunctionContext, expr: ts.ElementAccessExpression, objType: ValType): ValType | null;
@@ -0,0 +1,13 @@
1
+ import { ts } from '../ts-api.js';
2
+ import { CodegenContext, FunctionContext } from './context/types.js';
3
+ import { InnerResult } from './shared.js';
4
+ /**
5
+ * Recognize + lower a call to a raw `wasi_snapshot_preview1` binding —
6
+ * `fd_read`/`fd_write` (→ a direct WASI import call) or one of the inline
7
+ * linear-memory accessors `store32`/`load32`/`store8`/`load8` (→ a single memory
8
+ * instruction). Returns the result, or `undefined` when this isn't a raw-WASI
9
+ * call we handle (the generic compiler then proceeds). Byte-neutral for any
10
+ * program that doesn't import the raw module — `ctx.wasiRawImports` is empty, so
11
+ * the early returns fire immediately.
12
+ */
13
+ export declare function tryCompileRawWasiCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
@@ -0,0 +1,140 @@
1
+ /**
2
+ * #1539 Phase 2a — Regex bytecode opcode definitions.
3
+ *
4
+ * The standalone (pure-WasmGC) RegExp engine compiles a pattern to a flat
5
+ * `number[]` program at compile time (TypeScript), then interprets it at run
6
+ * time with a single hand-authored Wasm backtracking VM (`__regex_run`). The
7
+ * program is a Pike/Thompson-style instruction stream with explicit
8
+ * backtracking ops; see `src/codegen/regex/compile.ts` for the emitter and
9
+ * `src/codegen/native-regex.ts` for the VM.
10
+ *
11
+ * Each instruction is a fixed-width record of 3 i32 slots: `[op, a, b]`. A
12
+ * flat layout keeps the Wasm interpreter trivial (program-counter steps by 3)
13
+ * and lets the whole program live in one WasmGC `array i32`.
14
+ */
15
+ /** Instruction opcodes. Values are stable — they are baked into the emitted
16
+ * Wasm VM dispatch (`__regex_run`). Do not renumber without updating both. */
17
+ export declare enum ReOp {
18
+ /** `[CHAR, codeUnit, 0]` — match one specific UTF-16 code unit. */
19
+ CHAR = 0,
20
+ /** `[ANY, dotAll, 0]` — match any code unit; when `dotAll`=0, not `\n`/`\r`/U+2028/U+2029. */
21
+ ANY = 1,
22
+ /** `[CLASS, classIdx, negated]` — match against the class table entry. */
23
+ CLASS = 2,
24
+ /** `[SPLIT, x, y]` — try pc=x first, on backtrack try pc=y. */
25
+ SPLIT = 3,
26
+ /** `[JMP, x, 0]` — unconditional jump to pc=x. */
27
+ JMP = 4,
28
+ /** `[SAVE, slot, 0]` — record current input position into capture slot. */
29
+ SAVE = 5,
30
+ /** `[MATCH, 0, 0]` — accept. */
31
+ MATCH = 6,
32
+ /** `[BOL, 0, 0]` — assert beginning-of-line (`^`). multiline handled in 2c. */
33
+ BOL = 7,
34
+ /** `[EOL, 0, 0]` — assert end-of-line (`$`). multiline handled in 2c. */
35
+ EOL = 8,
36
+ /** `[CHARI, foldedCodeUnit, 0]` — match one code unit, ASCII-case-insensitive. */
37
+ CHARI = 9,
38
+ /** `[WBOUND, negated, 0]` — assert a word boundary (`\b`; `\B` when
39
+ * `negated`=1). Word characters are `[0-9A-Za-z_]` (§22.2.2.6 IsWordChar,
40
+ * ASCII — Unicode case folding lands with the `u` flag in 2d). #1912. */
41
+ WBOUND = 10,
42
+ /** `[BACKREF, groupIdx, caseInsensitive]` — match the text captured by group
43
+ * `groupIdx` (§22.2.2.9 BackreferenceMatcher). An unset group matches the
44
+ * empty string. `caseInsensitive`=1 compares ASCII-folded units. #1912. */
45
+ BACKREF = 11,
46
+ /** `[LOOKAROUND, subPc, flags]` — zero-width assertion (§22.2.2.4 Assertion
47
+ * `(?=) (?!) (?<=) (?<!)`). Runs the sub-program starting at instruction
48
+ * `subPc` as a fresh anchored attempt at the current position via a
49
+ * recursive `__regex_run` call (atomic — no backtrack entries leak out).
50
+ * `flags` bit 0 = negated, bit 1 = lookbehind (sub-program is compiled
51
+ * REVERSED and executed with direction -1). Captures written by a
52
+ * successful positive lookaround persist; everything else restores the
53
+ * pre-assertion capture state. #1911. */
54
+ LOOKAROUND = 12,
55
+ /** `[PROGRESS, slot, 0]` — empty-iteration guard for nullable quantifiers
56
+ * (§22.2.2.3.1 RepeatMatcher: a min=0 iteration that consumes nothing
57
+ * fails, ending the loop). `slot` is a scratch capture slot into which the
58
+ * loop entry recorded `sp` via a preceding SAVE; if the current `sp` equals
59
+ * that recorded value the body matched empty, so this op FAILS the
60
+ * iteration (backtracking to the quantifier's exit arm). Only emitted for
61
+ * star/plus whose body can match the empty string. #1959. */
62
+ PROGRESS = 13,
63
+ /** `[CLEAR, loSlot, hiSlot]` — reset capture slots `loSlot..hiSlot`
64
+ * (inclusive) to -1. §22.2.2.3.1 RepeatMatcher clears the quantified
65
+ * subtree's capture set on each repetition entry, so only the final
66
+ * iteration's participation is observable. Emitted at the head of every
67
+ * star/plus/repeat body that contains capture groups; the slot range is the
68
+ * group span `[2*lo, 2*hi+1]`. Backtrack-aware via the usual caps snapshot
69
+ * (CLEAR mutates `caps`, which SPLIT snapshots). #1960. */
70
+ CLEAR = 14
71
+ }
72
+ /** Slots per instruction in the flat program array. */
73
+ export declare const INSTR_WIDTH = 3;
74
+ /**
75
+ * A character-class entry, compiled to a flat run-length table consumed by the
76
+ * VM. Ranges are inclusive `[lo, hi]` UTF-16 code-unit pairs. A single char is
77
+ * `[c, c]`. The VM walks the table for a CLASS op.
78
+ *
79
+ * The class table is emitted as a separate flat `number[]`:
80
+ * [ classCount,
81
+ * class0_rangeCount, class0_lo0, class0_hi0, class0_lo1, class0_hi1, ...,
82
+ * class1_rangeCount, ... ]
83
+ * and `ReOp.CLASS`'s `a` operand indexes into a `classOffsets` array the
84
+ * compiler returns so the VM can find a class's run by offset.
85
+ */
86
+ export interface CharClass {
87
+ /** Inclusive code-unit ranges. */
88
+ ranges: Array<[number, number]>;
89
+ /** When true the class is negated (`[^...]`). */
90
+ negated: boolean;
91
+ }
92
+ /** A fully compiled regex program ready to embed in a `$NativeRegExp`. */
93
+ export interface CompiledRegex {
94
+ /** Flat instruction stream: `INSTR_WIDTH` ints per instruction. */
95
+ prog: number[];
96
+ /**
97
+ * Flat class table. Layout per class: `[rangeCount, lo0, hi0, lo1, hi1, …]`.
98
+ * `ReOp.CLASS` operand `a` is the *start offset* into this table (not an
99
+ * index), and `b` is the negated flag. Empty when no classes are used.
100
+ */
101
+ classTable: number[];
102
+ /** Number of capture groups including group 0 (the whole match). */
103
+ nGroups: number;
104
+ /** Extra scratch slots appended after the `2*nGroups` capture slots, one per
105
+ * nullable star/plus, used by `ReOp.PROGRESS` to detect empty iterations
106
+ * (#1959). The VM allocates `2*nGroups + nScratch` slots; scratch slots are
107
+ * never reported as captures. */
108
+ nScratch: number;
109
+ /** Flags bitfield: g=1 i=2 m=4 s=8 u=16 y=32 d=64 v=128. */
110
+ flags: number;
111
+ /**
112
+ * Named capture groups: `name → 1-based capture index` (#2588). Empty when
113
+ * the pattern has no `(?<name>…)` groups. The named-group set is statically
114
+ * known at compile time, so the standalone backend materialises the `groups`
115
+ * result object and resolves `$<name>` substitution from this map (no runtime
116
+ * name→index machinery needed).
117
+ */
118
+ groupNames: Map<string, number>;
119
+ }
120
+ /** Flags bitfield bit positions (mirrors the spec flag order). */
121
+ export declare const RE_FLAG_G = 1;
122
+ export declare const RE_FLAG_I = 2;
123
+ export declare const RE_FLAG_M = 4;
124
+ export declare const RE_FLAG_S = 8;
125
+ export declare const RE_FLAG_U = 16;
126
+ export declare const RE_FLAG_Y = 32;
127
+ export declare const RE_FLAG_D = 64;
128
+ export declare const RE_FLAG_V = 128;
129
+ /** Parse a JS flags string into the bitfield. Throws on duplicate/unknown. */
130
+ export declare function parseFlags(flags: string): number;
131
+ /**
132
+ * Raised when the pattern uses a feature outside the Phase-2a subset. The
133
+ * codegen entry points catch this and emit a clean #1539-phased compile error
134
+ * (the "narrowed refusal" the architect requires) instead of producing wrong
135
+ * Wasm.
136
+ */
137
+ export declare class RegexUnsupportedError extends Error {
138
+ readonly detail: string;
139
+ constructor(detail: string);
140
+ }