@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,48 @@
1
+ import { IncrementalLanguageService } from './checker/index.js';
2
+ import { CompileOptions, CompileResult } from './index.js';
3
+ export { compileToObjectSource } from './compiler/output.js';
4
+ export type { ObjectCompileResult } from './compiler/output.js';
5
+ /**
6
+ * #2657 — the source-import module string for js2wasm's raw linear-memory access
7
+ * intrinsics (`store32`/`load32`/`store8`/`load8`). These are NOT WASI host
8
+ * functions — they lower to inline `i32.store`/`i32.load`/`i32.store8`/
9
+ * `i32.load8_u` ops over the module's own exported `memory`. They are honestly
10
+ * named under a `wasm:` intrinsic namespace (mirroring `wasm:js-string`) so the
11
+ * source never mislabels a compiler intrinsic as a WASI host import: only
12
+ * `fd_read`/`fd_write` come from `"wasi_snapshot_preview1"`, the real WASI core
13
+ * module. (No host provides a `wasi_snapshot_preview1.store32`.)
14
+ */
15
+ export declare const WASM_MEMORY_INTRINSIC_MODULE = "wasm:memory";
16
+ /**
17
+ * Orchestrates the full compilation pipeline:
18
+ * TS Source → tsc Parser+Checker → Codegen → Binary + WAT
19
+ *
20
+ * Async because the optional Binaryen optimizer is lazy-loaded only when
21
+ * wasm-opt is requested (#1757 / GH #986), so normal compilation and
22
+ * standalone bundles do not need to embed Binaryen.
23
+ */
24
+ export declare function compileSource(source: string, options?: CompileOptions,
25
+ /** Optional persistent language service for incremental compilation */
26
+ languageService?: IncrementalLanguageService): Promise<CompileResult>;
27
+ /**
28
+ * Synchronous compilation core (no Binaryen optimization).
29
+ *
30
+ * Identical to {@link compileSource} but never runs the async wasm-opt pass —
31
+ * the `optimize` option is ignored here. Use this only from synchronous
32
+ * contexts that cannot await (the `eval` host shim). All other callers should
33
+ * use the async {@link compileSource}.
34
+ */
35
+ export declare function compileSourceSync(source: string, options?: CompileOptions,
36
+ /** Optional persistent language service for incremental compilation */
37
+ languageService?: IncrementalLanguageService): CompileResult;
38
+ /**
39
+ * Compile multiple TypeScript source files into a single Wasm module.
40
+ * Supports cross-file imports: `import { foo } from "./bar"`.
41
+ */
42
+ export declare function compileMultiSource(files: Record<string, string>, entryFile: string, options?: CompileOptions): Promise<CompileResult>;
43
+ /**
44
+ * Compile a TypeScript project from an entry file on disk.
45
+ * Uses ts.createProgram with real filesystem access -- TypeScript resolves
46
+ * all imports automatically via standard module resolution.
47
+ */
48
+ export declare function compileFilesSource(entryPath: string, options?: CompileOptions): Promise<CompileResult>;
@@ -0,0 +1,109 @@
1
+ class PositionMap {
2
+ /**
3
+ * A single-stage map is described by its edit list; a composed map is a
4
+ * chain `outer → inner` translated by function composition (apply `outer`'s
5
+ * single-stage transform, then defer to `inner`). Keeping composition as
6
+ * function composition (rather than flattening two edit lists into one)
7
+ * avoids the interleaving-delta correctness traps of merging transforms.
8
+ */
9
+ edits;
10
+ inner;
11
+ constructor(edits, inner) {
12
+ this.edits = [...edits].sort((a, b) => a.origStart - b.origStart);
13
+ this.inner = inner;
14
+ }
15
+ /** Identity map — output offsets equal input offsets. */
16
+ static identity() {
17
+ return new PositionMap([]);
18
+ }
19
+ /** Apply only THIS stage's single transform (output → its direct input). */
20
+ toDirectInputOffset(outOffset) {
21
+ let delta = 0;
22
+ for (const e of this.edits) {
23
+ const outEditStart = e.origStart + delta;
24
+ const outEditEnd = outEditStart + e.newLength;
25
+ if (outOffset < outEditStart) {
26
+ break;
27
+ }
28
+ if (outOffset < outEditEnd) {
29
+ return e.origStart;
30
+ }
31
+ delta += e.newLength - (e.origEnd - e.origStart);
32
+ }
33
+ return Math.max(0, outOffset - delta);
34
+ }
35
+ /**
36
+ * Translate an offset in this map's OUTPUT text all the way back to the
37
+ * ORIGINAL source: apply this stage, then defer to the earlier stage(s).
38
+ */
39
+ toInputOffset(outOffset) {
40
+ const direct = this.toDirectInputOffset(outOffset);
41
+ return this.inner ? this.inner.toInputOffset(direct) : direct;
42
+ }
43
+ /**
44
+ * Compose with the map of an EARLIER pipeline stage. `this` maps
45
+ * stage-N-output → stage-N-input; `inner` maps stage-N-input (== stage-(N−1)
46
+ * output) → original. The result maps stage-N-output → original.
47
+ */
48
+ compose(inner) {
49
+ if (inner.isIdentity) return this;
50
+ if (this.isIdentity) return inner;
51
+ return new PositionMap(this.edits, this.inner ? this.inner.compose(inner) : inner);
52
+ }
53
+ /** True when this is the identity (no edits and no earlier stage). */
54
+ get isIdentity() {
55
+ return this.edits.length === 0 && (this.inner?.isIdentity ?? true);
56
+ }
57
+ }
58
+ function applyDefineSubstitutions(source, defines) {
59
+ return applyDefineSubstitutionsWithMap(source, defines).source;
60
+ }
61
+ function applyDefineSubstitutionsWithMap(source, defines) {
62
+ if (!defines || Object.keys(defines).length === 0) {
63
+ return { source, positionMap: PositionMap.identity() };
64
+ }
65
+ const keys = Object.keys(defines).sort((a, b) => b.length - a.length);
66
+ let current = source;
67
+ let composed = PositionMap.identity();
68
+ for (const key of keys) {
69
+ const replacement = defines[key];
70
+ const pattern = key.startsWith("typeof ") ? new RegExp(`(?<![.\\w$])typeof\\s+${escapeRegExp(key.slice(7))}(?![\\w$])`, "g") : new RegExp(`(?<![.\\w$])${escapeRegExp(key)}(?![\\w$])`, "g");
71
+ const edits = [];
72
+ let out = "";
73
+ let last = 0;
74
+ for (const m of current.matchAll(pattern)) {
75
+ const start = m.index ?? 0;
76
+ const end = start + m[0].length;
77
+ out += current.slice(last, start) + replacement;
78
+ edits.push({ origStart: start, origEnd: end, newLength: replacement.length });
79
+ last = end;
80
+ }
81
+ if (edits.length === 0) continue;
82
+ out += current.slice(last);
83
+ current = out;
84
+ composed = new PositionMap(edits).compose(composed);
85
+ }
86
+ return { source: current, positionMap: composed };
87
+ }
88
+ function buildDefaultDefines(mode) {
89
+ return {
90
+ "process.env.NODE_ENV": JSON.stringify(mode),
91
+ "typeof process": JSON.stringify("undefined"),
92
+ "typeof window": JSON.stringify("undefined")
93
+ };
94
+ }
95
+ function escapeRegExp(s) {
96
+ return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
97
+ }
98
+ const defineSubstitution = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
99
+ __proto__: null,
100
+ applyDefineSubstitutions,
101
+ applyDefineSubstitutionsWithMap,
102
+ buildDefaultDefines
103
+ }, Symbol.toStringTag, { value: "Module" }));
104
+ export {
105
+ PositionMap as P,
106
+ applyDefineSubstitutionsWithMap as a,
107
+ applyDefineSubstitutions as b,
108
+ defineSubstitution as d
109
+ };
@@ -0,0 +1,50 @@
1
+ import { BlockType, FieldDef, GlobalDef, Import, Instr, SourcePos, TypeDef, ValType, WasmExport, WasmFunction, WasmModule } from '../ir/types.js';
2
+ import { WasmEncoder } from './encoder.js';
3
+ /** A source map entry: maps a wasm byte offset to a source position */
4
+ export interface SourceMapEntry {
5
+ wasmOffset: number;
6
+ sourcePos: SourcePos;
7
+ }
8
+ /** Result of binary emission with source map data */
9
+ export interface EmitResult {
10
+ binary: Uint8Array;
11
+ sourceMapEntries: SourceMapEntry[];
12
+ }
13
+ /**
14
+ * Compute rec-group boundaries for the type section. Each returned [start, end]
15
+ * (inclusive) tuple identifies a contiguous run of type definitions that must
16
+ * be encoded inside a single WasmGC rec group so that forward references between
17
+ * them validate. Singleton groups (start === end) are emitted without a rec
18
+ * wrapper, preserving canonical type identity for non-recursive entries.
19
+ */
20
+ export declare function computeRecGroups(types: TypeDef[]): Array<[number, number]>;
21
+ /** Emit a complete Wasm binary from an IR module */
22
+ export declare function emitBinary(mod: WasmModule): Uint8Array;
23
+ /**
24
+ * Emit a Wasm binary and collect source map entries.
25
+ *
26
+ * Arms the #2043 always-on index validation (see `EmitValidationCtx` above)
27
+ * for the duration of this emit and disarms it in a finally, so the encode
28
+ * helpers run unchecked for other callers (the relocatable object emitter).
29
+ * JS2WASM_SKIP_INDEX_VALIDATION=1 is an escape hatch only.
30
+ */
31
+ export declare function emitBinaryWithSourceMap(mod: WasmModule): EmitResult;
32
+ export declare function encodeTypeDef(t: TypeDef, enc: WasmEncoder): void;
33
+ export declare function encodeFieldDef(f: FieldDef, enc: WasmEncoder): void;
34
+ export declare function encodeStorageType(t: ValType, enc: WasmEncoder): void;
35
+ export declare function encodeValType(t: ValType, enc: WasmEncoder): void;
36
+ export declare function encodeImport(imp: Import, enc: WasmEncoder): void;
37
+ export declare function encodeGlobal(g: GlobalDef, enc: WasmEncoder): void;
38
+ export declare function encodeExport(exp: WasmExport, enc: WasmEncoder, _numImportFuncs: number): void;
39
+ export declare function encodeFunction(f: WasmFunction, enc: WasmEncoder): void;
40
+ export interface LocalGroup {
41
+ count: number;
42
+ type: ValType;
43
+ }
44
+ export declare function groupLocals(locals: {
45
+ type: ValType;
46
+ }[]): LocalGroup[];
47
+ export declare function encodeBlockType(bt: BlockType, enc: WasmEncoder): void;
48
+ export declare function encodeInstr(instr: Instr, enc: WasmEncoder): void;
49
+ /** Emit a sourceMappingURL custom section */
50
+ export declare function emitSourceMappingURLSection(enc: WasmEncoder, url: string): void;
@@ -0,0 +1,23 @@
1
+ import { ValType, WasmModule } from '../ir/types.js';
2
+ /** Information about a single exported function for C header generation */
3
+ export interface CHeaderExport {
4
+ /** C function name */
5
+ name: string;
6
+ /** Wasm parameter types */
7
+ params: ValType[];
8
+ /** Wasm result types */
9
+ results: ValType[];
10
+ }
11
+ /**
12
+ * Generate a C header file for the exported functions.
13
+ *
14
+ * @param moduleName - Used for the include guard (e.g. "my_module" → MY_MODULE_H)
15
+ * @param exports - List of exported functions with their signatures
16
+ * @returns The C header file content as a string
17
+ */
18
+ export declare function generateCHeader(moduleName: string, exports: CHeaderExport[]): string;
19
+ /**
20
+ * Extract C header export info from a WasmModule.
21
+ * Only includes function exports (not memory, tables, etc.)
22
+ */
23
+ export declare function extractCHeaderExports(mod: WasmModule): CHeaderExport[];
@@ -0,0 +1,86 @@
1
+ import { ArrayTypeDef, FuncTypeDef, StructTypeDef, SubTypeDef, WasmModule } from '../ir/types.js';
2
+ /**
3
+ * The closed, ordered set of runtime GC type names that form the shared
4
+ * runtime-type boundary rec group (#2514). These are the WasmGC types whose
5
+ * objects cross a core-wasm link boundary between a user module and the shared
6
+ * runtime: the string family and the vec/array family.
7
+ *
8
+ * Order here is the *canonical* member order the ABI freezes; the emit phase
9
+ * (follow-on) will lay these out contiguously in this order so every artifact
10
+ * produces a byte-identical group. The hash below is order-sensitive, so this
11
+ * list IS the versioned ABI contract for membership + order.
12
+ *
13
+ * NOTE: not every module declares every one of these (DCE prunes unused types),
14
+ * so the verifier works on the *subset present*, preserving relative order.
15
+ *
16
+ * IMPORTANT — names are the *in-memory* TypeDef names (no `$` prefix). The `$`
17
+ * appears only in WAT rendering, not in the IR `name` field, so the verifier
18
+ * (which reads `mod.types[i].name`) matches the bare names below.
19
+ *
20
+ * Only types with a *name-stable* identity belong here. The externref vec/arr
21
+ * variants are emitted with an index-suffixed name (`__arr_ref_6`,
22
+ * `__vec_ref_6`, where `6` is the referenced type index) which is NOT stable
23
+ * across modules — so they are intentionally excluded from the name-keyed ABI
24
+ * boundary. Their structural identity is still verified transitively when a
25
+ * group member refs them (as an external `x` token).
26
+ */
27
+ export declare const RUNTIME_RECGROUP_TYPE_NAMES: readonly string[];
28
+ /** ABI version of the canonical runtime rec group. Bump on any membership,
29
+ * order, or structural change to a type in {@link RUNTIME_RECGROUP_TYPE_NAMES}. */
30
+ export declare const RUNTIME_RECGROUP_ABI_VERSION = 1;
31
+ /** A flat type table member (no nested `rec` wrappers). */
32
+ type FlatTypeDef = FuncTypeDef | StructTypeDef | ArrayTypeDef | SubTypeDef;
33
+ /**
34
+ * Compute a deterministic, name-independent, absolute-index-independent
35
+ * structural canonical hash of an ordered group of type defs.
36
+ *
37
+ * `absIndices[i]` is the absolute type index of `group[i]` in the owning
38
+ * module's type space (used to resolve intra-group refs to local positions).
39
+ *
40
+ * Two groups that are structurally identical modulo type names and absolute
41
+ * placement produce the same hash; any change in member set, member order, or
42
+ * the structure/intra-group topology of any member changes it. This is the
43
+ * soundness proxy for "the engine canonicalizes these to the same runtime
44
+ * type".
45
+ */
46
+ export declare function canonicalHashOfTypeGroup(group: readonly FlatTypeDef[], absIndices: readonly number[]): string;
47
+ /** A member of the extracted runtime group: its name + absolute index + def. */
48
+ export interface RuntimeGroupMember {
49
+ name: string;
50
+ absIndex: number;
51
+ def: FlatTypeDef;
52
+ }
53
+ /**
54
+ * Locate the runtime-type members present in a module's flat type table, in
55
+ * the module's emission order. Only types whose name is in
56
+ * {@link RUNTIME_RECGROUP_TYPE_NAMES} are returned (a module that doesn't use
57
+ * strings/vecs simply yields a subset, or none).
58
+ *
59
+ * Requires a *flat* type table (no nested `rec` wrappers), which is the shape
60
+ * codegen produces today (`computeRecGroups` derives groups at emit time, the
61
+ * `mod.types` array itself is flat).
62
+ */
63
+ export declare function extractRuntimeGroup(mod: WasmModule): RuntimeGroupMember[];
64
+ /** Result of fingerprinting a module's runtime rec group. */
65
+ export interface RuntimeGroupFingerprint {
66
+ /** ABI version this fingerprint was computed under. */
67
+ abiVersion: number;
68
+ /** Canonical structural hash (the identity proxy). */
69
+ hash: string;
70
+ /** Member names in emission order — the membership+order half of the ABI. */
71
+ members: string[];
72
+ /** Number of runtime types present. */
73
+ count: number;
74
+ }
75
+ /**
76
+ * Produce a stable fingerprint of a module's runtime rec group: the structural
77
+ * canonical hash plus the ordered member list. Equal fingerprints across two
78
+ * artifacts ⇒ their runtime GC types will canonicalize to the same runtime
79
+ * type, so GC objects can cross a core-wasm link between them.
80
+ *
81
+ * This is the building block for a drift gate: capture the fingerprint of a
82
+ * reference artifact (e.g. the future `runtime.wasm`) and assert every user
83
+ * module reproduces it, including AFTER `wasm-opt` (the #2514 risk #2 check).
84
+ */
85
+ export declare function fingerprintRuntimeGroup(mod: WasmModule): RuntimeGroupFingerprint;
86
+ export {};
@@ -0,0 +1,28 @@
1
+ export declare class WasmEncoder {
2
+ private buf;
3
+ byte(b: number): void;
4
+ bytes(bs: number[] | Uint8Array): void;
5
+ /** Unsigned LEB128 */
6
+ u32(value: number): void;
7
+ /** Signed LEB128 */
8
+ i32(value: number): void;
9
+ /** Signed LEB128 i64 — truncate to 64 bits to prevent overflow */
10
+ i64(value: bigint): void;
11
+ /** IEEE 754 f64 little-endian */
12
+ f64(value: number): void;
13
+ /** IEEE 754 f32 little-endian */
14
+ f32(value: number): void;
15
+ /** v128 constant — 16 bytes little-endian */
16
+ v128(bytes: Uint8Array): void;
17
+ /** UTF-8 string with length prefix */
18
+ name(s: string): void;
19
+ /** Section: id + length-prefixed content */
20
+ section(id: number, content: (enc: WasmEncoder) => void): void;
21
+ /** Vector: u32 count + items */
22
+ vector<T>(items: T[], encode: (item: T, enc: WasmEncoder) => void): void;
23
+ /** Get current buffer length */
24
+ get length(): number;
25
+ /** Get current write position (alias for length, used by relocation tracking) */
26
+ get position(): number;
27
+ finish(): Uint8Array;
28
+ }
@@ -0,0 +1,14 @@
1
+ import { WasmModule } from '../ir/types.js';
2
+ export interface RelocEntry {
3
+ type: number;
4
+ offset: number;
5
+ symbolIndex: number;
6
+ }
7
+ export interface SymbolInfo {
8
+ kind: number;
9
+ name: string;
10
+ index: number;
11
+ flags: number;
12
+ }
13
+ /** Emit a relocatable Wasm object file (.o) from an IR module */
14
+ export declare function emitObject(mod: WasmModule): Uint8Array;