@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.
- package/CHANGELOG.md +1425 -0
- package/LICENSE +189 -0
- package/README.md +451 -0
- package/dist/checker/index.d.ts +117 -0
- package/dist/checker/language-service.d.ts +39 -0
- package/dist/checker/node-capability-map.d.ts +63 -0
- package/dist/checker/type-mapper.d.ts +84 -0
- package/dist/cjs-rewrite.d.ts +19 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +363 -0
- package/dist/codegen/accessor-driver.d.ts +97 -0
- package/dist/codegen/any-helpers.d.ts +72 -0
- package/dist/codegen/array-element-typing.d.ts +46 -0
- package/dist/codegen/array-holes.d.ts +69 -0
- package/dist/codegen/array-methods.d.ts +68 -0
- package/dist/codegen/array-object-proto.d.ts +64 -0
- package/dist/codegen/array-reduce-fusion.d.ts +31 -0
- package/dist/codegen/array-to-primitive.d.ts +28 -0
- package/dist/codegen/async-cps.d.ts +239 -0
- package/dist/codegen/async-scheduler.d.ts +349 -0
- package/dist/codegen/binary-ops.d.ts +78 -0
- package/dist/codegen/binding-info.d.ts +31 -0
- package/dist/codegen/builtin-scaffold.d.ts +98 -0
- package/dist/codegen/builtin-static-globals.d.ts +8 -0
- package/dist/codegen/builtin-tags.d.ts +189 -0
- package/dist/codegen/case-convert-native.d.ts +12 -0
- package/dist/codegen/case-tables.d.ts +4 -0
- package/dist/codegen/class-bodies.d.ts +41 -0
- package/dist/codegen/class-member-keys.d.ts +33 -0
- package/dist/codegen/class-to-primitive.d.ts +39 -0
- package/dist/codegen/closed-method-dispatch.d.ts +42 -0
- package/dist/codegen/closures.d.ts +285 -0
- package/dist/codegen/coercion-engine.d.ts +154 -0
- package/dist/codegen/coercion-plan.d.ts +29 -0
- package/dist/codegen/context/bodies.d.ts +4 -0
- package/dist/codegen/context/create-context.d.ts +4 -0
- package/dist/codegen/context/errors.d.ts +39 -0
- package/dist/codegen/context/locals.d.ts +69 -0
- package/dist/codegen/context/source-pos.d.ts +5 -0
- package/dist/codegen/context/speculative.d.ts +95 -0
- package/dist/codegen/context/types.d.ts +1936 -0
- package/dist/codegen/custom-iterable.d.ts +34 -0
- package/dist/codegen/dataview-native.d.ts +51 -0
- package/dist/codegen/date-parse-native.d.ts +13 -0
- package/dist/codegen/dead-elimination.d.ts +26 -0
- package/dist/codegen/declarations.d.ts +147 -0
- package/dist/codegen/deno-api.d.ts +11 -0
- package/dist/codegen/destructuring-params.d.ts +102 -0
- package/dist/codegen/dyn-read.d.ts +26 -0
- package/dist/codegen/eval-tiering.d.ts +19 -0
- package/dist/codegen/expressions/assignment.d.ts +61 -0
- package/dist/codegen/expressions/builtins.d.ts +26 -0
- package/dist/codegen/expressions/calls-closures.d.ts +54 -0
- package/dist/codegen/expressions/calls-guards.d.ts +49 -0
- package/dist/codegen/expressions/calls-optional.d.ts +4 -0
- package/dist/codegen/expressions/calls.d.ts +83 -0
- package/dist/codegen/expressions/eval-inline.d.ts +24 -0
- package/dist/codegen/expressions/extern.d.ts +67 -0
- package/dist/codegen/expressions/fnctor-prototype.d.ts +52 -0
- package/dist/codegen/expressions/helpers.d.ts +212 -0
- package/dist/codegen/expressions/identifiers.d.ts +57 -0
- package/dist/codegen/expressions/late-imports.d.ts +81 -0
- package/dist/codegen/expressions/logical-ops.d.ts +18 -0
- package/dist/codegen/expressions/misc.d.ts +27 -0
- package/dist/codegen/expressions/new-super.d.ts +25 -0
- package/dist/codegen/expressions/promise-subclass.d.ts +38 -0
- package/dist/codegen/expressions/proto-override.d.ts +63 -0
- package/dist/codegen/expressions/unary-updates.d.ts +21 -0
- package/dist/codegen/expressions/unary.d.ts +6 -0
- package/dist/codegen/expressions.d.ts +31 -0
- package/dist/codegen/fallback-telemetry.d.ts +53 -0
- package/dist/codegen/fixups.d.ts +80 -0
- package/dist/codegen/fmod.d.ts +10 -0
- package/dist/codegen/fnctor-escape-gate.d.ts +92 -0
- package/dist/codegen/function-body.d.ts +52 -0
- package/dist/codegen/generators-native.d.ts +92 -0
- package/dist/codegen/helpers/body-references-own-this.d.ts +22 -0
- package/dist/codegen/helpers/body-uses-arguments.d.ts +12 -0
- package/dist/codegen/helpers/is-strict-function.d.ts +52 -0
- package/dist/codegen/host-import-allowlist.d.ts +140 -0
- package/dist/codegen/index.d.ts +500 -0
- package/dist/codegen/ir-tail-call.d.ts +8 -0
- package/dist/codegen/iterator-native.d.ts +44 -0
- package/dist/codegen/json-codec-native.d.ts +78 -0
- package/dist/codegen/json-runtime.d.ts +35 -0
- package/dist/codegen/json-standalone.d.ts +25 -0
- package/dist/codegen/linear-uint8-analysis.d.ts +46 -0
- package/dist/codegen/linear-uint8-arena.d.ts +7 -0
- package/dist/codegen/linear-uint8-codegen.d.ts +103 -0
- package/dist/codegen/linear-uint8-signatures.d.ts +26 -0
- package/dist/codegen/literals.d.ts +115 -0
- package/dist/codegen/map-runtime.d.ts +142 -0
- package/dist/codegen/math-helpers.d.ts +7 -0
- package/dist/codegen/member-get-dispatch.d.ts +42 -0
- package/dist/codegen/member-set-dispatch.d.ts +28 -0
- package/dist/codegen/native-proto.d.ts +98 -0
- package/dist/codegen/native-regex.d.ts +158 -0
- package/dist/codegen/native-strings.d.ts +146 -0
- package/dist/codegen/new-target.d.ts +30 -0
- package/dist/codegen/node-fs-api.d.ts +47 -0
- package/dist/codegen/number-format-native.d.ts +9 -0
- package/dist/codegen/number-ryu.d.ts +27 -0
- package/dist/codegen/object-ops.d.ts +94 -0
- package/dist/codegen/object-runtime.d.ts +171 -0
- package/dist/codegen/parse-number-native.d.ts +10 -0
- package/dist/codegen/peephole.d.ts +6 -0
- package/dist/codegen/property-access.d.ts +294 -0
- package/dist/codegen/raw-wasi-api.d.ts +13 -0
- package/dist/codegen/regex/bytecode.d.ts +140 -0
- package/dist/codegen/regex/casefold.d.ts +41 -0
- package/dist/codegen/regex/compile.d.ts +51 -0
- package/dist/codegen/regex/parse.d.ts +76 -0
- package/dist/codegen/regex/unicode.d.ts +42 -0
- package/dist/codegen/regex/vm.d.ts +24 -0
- package/dist/codegen/regexp-standalone.d.ts +350 -0
- package/dist/codegen/registry/error-types.d.ts +38 -0
- package/dist/codegen/registry/imports.d.ts +46 -0
- package/dist/codegen/registry/types.d.ts +59 -0
- package/dist/codegen/set-algebra.d.ts +17 -0
- package/dist/codegen/set-runtime.d.ts +74 -0
- package/dist/codegen/shared.d.ts +111 -0
- package/dist/codegen/stack-balance.d.ts +43 -0
- package/dist/codegen/statements/control-flow.d.ts +25 -0
- package/dist/codegen/statements/destructuring.d.ts +177 -0
- package/dist/codegen/statements/exceptions.d.ts +11 -0
- package/dist/codegen/statements/functions.d.ts +1 -0
- package/dist/codegen/statements/index.d.ts +1 -0
- package/dist/codegen/statements/loops.d.ts +7 -0
- package/dist/codegen/statements/nested-declarations.d.ts +78 -0
- package/dist/codegen/statements/shared.d.ts +38 -0
- package/dist/codegen/statements/tdz.d.ts +43 -0
- package/dist/codegen/statements/variables.d.ts +3 -0
- package/dist/codegen/statements.d.ts +9 -0
- package/dist/codegen/string-builder.d.ts +131 -0
- package/dist/codegen/string-ops.d.ts +87 -0
- package/dist/codegen/struct-accessor-closure.d.ts +36 -0
- package/dist/codegen/symbol-native.d.ts +55 -0
- package/dist/codegen/temporal-native.d.ts +8 -0
- package/dist/codegen/timsort.d.ts +2 -0
- package/dist/codegen/type-coercion.d.ts +123 -0
- package/dist/codegen/typeof-delete.d.ts +38 -0
- package/dist/codegen/uri-encoding-native.d.ts +33 -0
- package/dist/codegen/value-tags.d.ts +74 -0
- package/dist/codegen/walk-instructions.d.ts +20 -0
- package/dist/codegen/weak-collections-runtime.d.ts +16 -0
- package/dist/codegen/with-scope.d.ts +106 -0
- package/dist/codegen-linear/c-abi.d.ts +74 -0
- package/dist/codegen-linear/context.d.ts +86 -0
- package/dist/codegen-linear/index.d.ts +28 -0
- package/dist/codegen-linear/layout.d.ts +39 -0
- package/dist/codegen-linear/runtime.d.ts +161 -0
- package/dist/codegen-linear/simd.d.ts +7 -0
- package/dist/compiler/define-substitution.d.ts +27 -0
- package/dist/compiler/early-errors/assignment.d.ts +26 -0
- package/dist/compiler/early-errors/context.d.ts +17 -0
- package/dist/compiler/early-errors/duplicates.d.ts +20 -0
- package/dist/compiler/early-errors/index.d.ts +11 -0
- package/dist/compiler/early-errors/labels.d.ts +13 -0
- package/dist/compiler/early-errors/module-rules.d.ts +36 -0
- package/dist/compiler/early-errors/node-checks.d.ts +7 -0
- package/dist/compiler/early-errors/predicates.d.ts +140 -0
- package/dist/compiler/early-errors/tdz.d.ts +17 -0
- package/dist/compiler/import-manifest.d.ts +18 -0
- package/dist/compiler/output.d.ts +46 -0
- package/dist/compiler/validation.d.ts +45 -0
- package/dist/compiler.d.ts +48 -0
- package/dist/define-substitution-BcUeKC2A.js +109 -0
- package/dist/emit/binary.d.ts +50 -0
- package/dist/emit/c-header.d.ts +23 -0
- package/dist/emit/canonical-recgroup.d.ts +86 -0
- package/dist/emit/encoder.d.ts +28 -0
- package/dist/emit/object.d.ts +14 -0
- package/dist/emit/opcodes.d.ts +464 -0
- package/dist/emit/sourcemap.d.ts +33 -0
- package/dist/emit/wat.d.ts +6 -0
- package/dist/env.d.ts +46 -0
- package/dist/import-resolver.d.ts +68 -0
- package/dist/index.d.ts +486 -0
- package/dist/index.js +755 -0
- package/dist/ir/alloc-registry.d.ts +75 -0
- package/dist/ir/analysis/encoding.d.ts +38 -0
- package/dist/ir/analysis/escape.d.ts +32 -0
- package/dist/ir/analysis/lattice.d.ts +72 -0
- package/dist/ir/analysis/ownership.d.ts +31 -0
- package/dist/ir/analysis/stack-alloc.d.ts +20 -0
- package/dist/ir/backend/bytecode-emitter.d.ts +237 -0
- package/dist/ir/backend/bytecode-vm.d.ts +74 -0
- package/dist/ir/backend/emitter.d.ts +121 -0
- package/dist/ir/backend/handles.d.ts +133 -0
- package/dist/ir/backend/legality.d.ts +9 -0
- package/dist/ir/backend/linear-emitter.d.ts +41 -0
- package/dist/ir/backend/wasmgc-emitter.d.ts +43 -0
- package/dist/ir/builder.d.ts +401 -0
- package/dist/ir/from-ast.d.ts +192 -0
- package/dist/ir/index.d.ts +16 -0
- package/dist/ir/integration.d.ts +27 -0
- package/dist/ir/lower.d.ts +203 -0
- package/dist/ir/nodes.d.ts +1452 -0
- package/dist/ir/passes/alloc-discipline.d.ts +19 -0
- package/dist/ir/passes/constant-fold.d.ts +7 -0
- package/dist/ir/passes/dead-code.d.ts +18 -0
- package/dist/ir/passes/inline-small.d.ts +7 -0
- package/dist/ir/passes/monomorphize.d.ts +21 -0
- package/dist/ir/passes/simplify-cfg.d.ts +19 -0
- package/dist/ir/passes/tagged-union-types.d.ts +45 -0
- package/dist/ir/passes/tagged-unions.d.ts +22 -0
- package/dist/ir/propagate.d.ts +135 -0
- package/dist/ir/select.d.ts +81 -0
- package/dist/ir/types.d.ts +832 -0
- package/dist/ir/verify-alloc.d.ts +18 -0
- package/dist/ir/verify.d.ts +7 -0
- package/dist/link/index.d.ts +11 -0
- package/dist/link/isolation.d.ts +24 -0
- package/dist/link/linker.d.ts +37 -0
- package/dist/link/reader.d.ts +158 -0
- package/dist/link/resolver.d.ts +19 -0
- package/dist/optimize.d.ts +54 -0
- package/dist/optimize.js +262 -0
- package/dist/position-map.d.ts +64 -0
- package/dist/process-stdin-prelude.d.ts +16 -0
- package/dist/resolve.d.ts +82 -0
- package/dist/runtime/builtins.d.ts +1 -0
- package/dist/runtime-C-4q_KwU.js +164438 -0
- package/dist/runtime-containment.d.ts +6 -0
- package/dist/runtime-eval.d.ts +132 -0
- package/dist/runtime-instantiate.d.ts +16 -0
- package/dist/runtime.d.ts +128 -0
- package/dist/runtime.js +12 -0
- package/dist/shape-inference.d.ts +20 -0
- package/dist/treeshake.d.ts +17 -0
- package/dist/ts-api.d.ts +30 -0
- package/dist/wit-generator.d.ts +18 -0
- package/package.json +187 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
import { ExportSignature } from './ir/types.js';
|
|
2
|
+
export type ImportIntent = {
|
|
3
|
+
type: "string_literal";
|
|
4
|
+
value: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: "math";
|
|
7
|
+
method: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "console_log";
|
|
10
|
+
variant: string;
|
|
11
|
+
} | {
|
|
12
|
+
type: "extern_class";
|
|
13
|
+
className: string;
|
|
14
|
+
action: "new" | "method" | "get" | "set";
|
|
15
|
+
member?: string;
|
|
16
|
+
namespacePath?: string[];
|
|
17
|
+
} | {
|
|
18
|
+
type: "string_method";
|
|
19
|
+
method: string;
|
|
20
|
+
} | {
|
|
21
|
+
type: "builtin";
|
|
22
|
+
name: string;
|
|
23
|
+
} | {
|
|
24
|
+
type: "callback_maker";
|
|
25
|
+
} | {
|
|
26
|
+
type: "getter_callback_maker";
|
|
27
|
+
} | {
|
|
28
|
+
type: "await";
|
|
29
|
+
} | {
|
|
30
|
+
type: "typeof_check";
|
|
31
|
+
targetType: string;
|
|
32
|
+
} | {
|
|
33
|
+
type: "box";
|
|
34
|
+
targetType: string;
|
|
35
|
+
} | {
|
|
36
|
+
type: "unbox";
|
|
37
|
+
targetType: string;
|
|
38
|
+
} | {
|
|
39
|
+
type: "extern_get";
|
|
40
|
+
} | {
|
|
41
|
+
type: "extern_set";
|
|
42
|
+
} | {
|
|
43
|
+
type: "extern_set_strict";
|
|
44
|
+
} | {
|
|
45
|
+
type: "truthy_check";
|
|
46
|
+
} | {
|
|
47
|
+
type: "date_new";
|
|
48
|
+
} | {
|
|
49
|
+
type: "date_method";
|
|
50
|
+
method: string;
|
|
51
|
+
} | {
|
|
52
|
+
type: "date_now";
|
|
53
|
+
} | {
|
|
54
|
+
type: "declared_global";
|
|
55
|
+
name: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: "host_eq";
|
|
58
|
+
} | {
|
|
59
|
+
type: "host_loose_eq";
|
|
60
|
+
} | {
|
|
61
|
+
type: "host_add";
|
|
62
|
+
} | {
|
|
63
|
+
type: "host_compare";
|
|
64
|
+
} | {
|
|
65
|
+
type: "same_value_zero";
|
|
66
|
+
} | {
|
|
67
|
+
type: "dynamic_import";
|
|
68
|
+
} | {
|
|
69
|
+
type: "proxy_create";
|
|
70
|
+
} | {
|
|
71
|
+
type: "node_builtin";
|
|
72
|
+
moduleName: string;
|
|
73
|
+
} | {
|
|
74
|
+
type: "node_builtin_fn";
|
|
75
|
+
moduleName: string;
|
|
76
|
+
name: string;
|
|
77
|
+
} | {
|
|
78
|
+
type: "web_storage";
|
|
79
|
+
which: "local" | "session";
|
|
80
|
+
} | {
|
|
81
|
+
type: "timer_set";
|
|
82
|
+
mode: "timeout" | "interval";
|
|
83
|
+
} | {
|
|
84
|
+
type: "timer_clear";
|
|
85
|
+
mode: "timeout" | "interval";
|
|
86
|
+
} | {
|
|
87
|
+
type: "node_dirname";
|
|
88
|
+
} | {
|
|
89
|
+
type: "node_filename";
|
|
90
|
+
} | {
|
|
91
|
+
type: "node_import_meta_url";
|
|
92
|
+
} | {
|
|
93
|
+
type: "jsx_runtime";
|
|
94
|
+
method: "jsx" | "jsxs" | "Fragment" | "jsxDEV";
|
|
95
|
+
specifier: string;
|
|
96
|
+
};
|
|
97
|
+
export interface ImportDescriptor {
|
|
98
|
+
module: "env" | "wasm:js-string" | "string_constants";
|
|
99
|
+
name: string;
|
|
100
|
+
kind: "func" | "global";
|
|
101
|
+
intent: ImportIntent;
|
|
102
|
+
}
|
|
103
|
+
export type { ExportSignature, TypedArrayKind } from './ir/types.js';
|
|
104
|
+
export interface CompileResult {
|
|
105
|
+
/** Wasm binary with GC proposal */
|
|
106
|
+
binary: Uint8Array;
|
|
107
|
+
/** WAT text representation (debug) */
|
|
108
|
+
wat: string;
|
|
109
|
+
/** TypeScript declaration file for exports and imports */
|
|
110
|
+
dts: string;
|
|
111
|
+
/** JS module with createImports() helper function */
|
|
112
|
+
importsHelper: string;
|
|
113
|
+
/** true if compilation was successful */
|
|
114
|
+
success: boolean;
|
|
115
|
+
/** Error messages with line numbers */
|
|
116
|
+
errors: CompileError[];
|
|
117
|
+
/** String literal pool (values used in the source) */
|
|
118
|
+
stringPool: string[];
|
|
119
|
+
/** Source map v3 JSON string (only present when sourceMap option is enabled) */
|
|
120
|
+
sourceMap?: string;
|
|
121
|
+
/** Import descriptors for closed import building */
|
|
122
|
+
imports: ImportDescriptor[];
|
|
123
|
+
/** C header file content (only present when abi: "c") */
|
|
124
|
+
cHeader?: string;
|
|
125
|
+
/** WIT interface definition (only present when wit option is enabled) */
|
|
126
|
+
wit?: string;
|
|
127
|
+
/** Whether the source declares an exported main() function */
|
|
128
|
+
hasMain: boolean;
|
|
129
|
+
/** Whether the source has top-level executable statements (module init code) */
|
|
130
|
+
hasTopLevelStatements: boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Per-export TypedArray classifications (#1700). Surfaced so
|
|
133
|
+
* {@link wrapExports} can marshal `Uint8Array` (and other TypedArray)
|
|
134
|
+
* params/results across the JS↔Wasm boundary — the Wasm signature is
|
|
135
|
+
* ambiguous (`Uint8Array` and `number[]` share the same `(ref null $Vec[f64])`
|
|
136
|
+
* lowering), so we expose the TS-level distinction as metadata.
|
|
137
|
+
*
|
|
138
|
+
* Only present (and even then, possibly an empty object) when at least
|
|
139
|
+
* one exported function has a TypedArray param or return. Forward the
|
|
140
|
+
* value to `wrapExports(exports, { signatures: result.exportSignatures })`.
|
|
141
|
+
*/
|
|
142
|
+
exportSignatures?: Record<string, ExportSignature>;
|
|
143
|
+
/**
|
|
144
|
+
* Ready-to-pass JS-host import object for default/JS-host mode (#1667).
|
|
145
|
+
*
|
|
146
|
+
* In default mode the compiled binary needs host imports (`env.*`,
|
|
147
|
+
* `wasm:js-string`, `string_constants`), so `WebAssembly.instantiate(binary,
|
|
148
|
+
* {})` throws. This getter wires the runtime helpers from {@link buildImports}
|
|
149
|
+
* into a single object the caller passes directly:
|
|
150
|
+
*
|
|
151
|
+
* ```js
|
|
152
|
+
* const r = await compile(src);
|
|
153
|
+
* const { instance } = await WebAssembly.instantiate(r.binary, r.importObject);
|
|
154
|
+
* ```
|
|
155
|
+
*
|
|
156
|
+
* Standalone / `wasi` mode is the zero-import portable default and needs no
|
|
157
|
+
* import object; for those targets this is an empty object. Computed lazily —
|
|
158
|
+
* accessing it builds the runtime once and caches the result.
|
|
159
|
+
*
|
|
160
|
+
* Always present on results from the public `compile*` entry points; the
|
|
161
|
+
* low-level `compile*Source` helpers in compiler.ts do not attach it.
|
|
162
|
+
*/
|
|
163
|
+
readonly importObject?: WebAssembly.Imports;
|
|
164
|
+
/**
|
|
165
|
+
* #2089 — silent-fallback telemetry counters captured during codegen
|
|
166
|
+
* (per class → per site → count). Only populated when the
|
|
167
|
+
* `trackSilentFallbacks` option is set (the gate
|
|
168
|
+
* `scripts/check-codegen-fallbacks.ts` sets it); `undefined` otherwise so
|
|
169
|
+
* normal compiles pay nothing.
|
|
170
|
+
*/
|
|
171
|
+
fallbackCounts?: import('./codegen/fallback-telemetry.js').FallbackCounts;
|
|
172
|
+
/**
|
|
173
|
+
* #1923 — IR post-claim demotions. When the IR selector *claims* a function
|
|
174
|
+
* but it then fails during build/verify/lower/backend-legality, it demotes to
|
|
175
|
+
* the legacy path through the warning channel (`codegen/index.ts`) and is
|
|
176
|
+
* counted by no selector-level metric (`IrFallbackReason` covers only
|
|
177
|
+
* selector-level rejections). Always collected on the WasmGC path (cheap,
|
|
178
|
+
* mirrors `fallbackCounts`); empty/absent for the linear backend (no IR path).
|
|
179
|
+
* Each entry carries the `IrIntegrationError.kind` (build/verify/lower/
|
|
180
|
+
* backend-legality) and the function/message so the ratchet gate
|
|
181
|
+
* `scripts/check-ir-fallbacks.ts` can bucket by kind + normalized message
|
|
182
|
+
* class.
|
|
183
|
+
*/
|
|
184
|
+
irPostClaimErrors?: {
|
|
185
|
+
kind: string;
|
|
186
|
+
func: string;
|
|
187
|
+
message: string;
|
|
188
|
+
}[];
|
|
189
|
+
}
|
|
190
|
+
export interface CompileError {
|
|
191
|
+
message: string;
|
|
192
|
+
line: number;
|
|
193
|
+
column: number;
|
|
194
|
+
severity: "error" | "warning";
|
|
195
|
+
/** TS diagnostic code (if from TypeScript diagnostics) */
|
|
196
|
+
code?: number;
|
|
197
|
+
/**
|
|
198
|
+
* Source file the diagnostic originated in (#1929). Populated from
|
|
199
|
+
* `diag.file.fileName` for TypeScript diagnostics; absent for diagnostics
|
|
200
|
+
* with no associated file (global/options errors). Essential for the
|
|
201
|
+
* multi-file / files APIs where `line`/`column` alone can't say *which*
|
|
202
|
+
* file. Additive — existing single-file callers can ignore it.
|
|
203
|
+
*/
|
|
204
|
+
file?: string;
|
|
205
|
+
}
|
|
206
|
+
export interface DomContainmentOptions {
|
|
207
|
+
domRoot: Element | ShadowRoot;
|
|
208
|
+
}
|
|
209
|
+
export interface ImportPolicy {
|
|
210
|
+
blocked: Set<string>;
|
|
211
|
+
}
|
|
212
|
+
export interface CompileOptions {
|
|
213
|
+
/** Emit WAT debug output (default: true) */
|
|
214
|
+
emitWat?: boolean;
|
|
215
|
+
/** Module name (for debugging) */
|
|
216
|
+
moduleName?: string;
|
|
217
|
+
/** Generate source map (default: false) */
|
|
218
|
+
sourceMap?: boolean;
|
|
219
|
+
/** Source map URL to embed in the wasm binary (default: "module.wasm.map") */
|
|
220
|
+
sourceMapUrl?: string;
|
|
221
|
+
/** Compilation target: "gc" (WasmGC, default), "linear" (linear memory),
|
|
222
|
+
* "wasi" (WASI-compatible GC), or "standalone" (pure WasmGC, no JS host
|
|
223
|
+
* and no WASI runtime — #1470). `target: "standalone"` implies
|
|
224
|
+
* `nativeStrings: true` and refuses to emit any `wasm:js-string` or
|
|
225
|
+
* `env` JS-host string imports. */
|
|
226
|
+
target?: "gc" | "linear" | "wasi" | "standalone";
|
|
227
|
+
/** Enable fast mode — i32 default numbers, performance optimizations */
|
|
228
|
+
fast?: boolean;
|
|
229
|
+
/**
|
|
230
|
+
* (#2119) Whether to infer ES-module strictness (module code is always strict,
|
|
231
|
+
* ECMA-262 11.2.2) from a genuine top-level `import`/`export`. Drives the
|
|
232
|
+
* unmapped `arguments` object for module functions. Defaults to `true` — the
|
|
233
|
+
* product compiles real module input, so this is the spec-correct behaviour.
|
|
234
|
+
*
|
|
235
|
+
* The test262 harness sets this to `false` for *script* tests: its `wrapTest`
|
|
236
|
+
* injects a synthetic `export function test()` entry point that makes
|
|
237
|
+
* TypeScript flag *every* wrapped source as a module
|
|
238
|
+
* (`externalModuleIndicator`). Inferring module-strictness from that synthetic
|
|
239
|
+
* export wrongly unmaps `arguments` for sloppy (`noStrict`) tests asserting
|
|
240
|
+
* mapped behaviour. The harness passes `false` for non-module-goal tests and
|
|
241
|
+
* leaves it `true` (default) for genuine module tests, so the compiler sees
|
|
242
|
+
* the source's *true* strictness rather than the wrapper artifact. An explicit
|
|
243
|
+
* `"use strict"` prologue and class context still force strict regardless.
|
|
244
|
+
*/
|
|
245
|
+
inferModuleStrictArguments?: boolean;
|
|
246
|
+
/** Use WasmGC-native strings (array i16) instead of wasm:js-string imports.
|
|
247
|
+
* Enabled automatically when fast: true or target: "wasi".
|
|
248
|
+
* Required for non-browser runtimes (wasmtime, wasmer, etc.) */
|
|
249
|
+
nativeStrings?: boolean;
|
|
250
|
+
/** #1588 PR-B: dual i8/i16 string storage. When true, string allocation
|
|
251
|
+
* sites the encoding analysis proves `ascii`/`utf8-guaranteed` are stored
|
|
252
|
+
* as i8-backed `Utf8String`; all others stay i16. Default false →
|
|
253
|
+
* byte-identical output. Implies `nativeStrings` on the WasmGC backend. */
|
|
254
|
+
utf8Storage?: boolean;
|
|
255
|
+
/** Test-only: emit `__test_str_from_externref` and `__test_str_to_externref`
|
|
256
|
+
* exports so test code can pass JS strings to/from native-string params (#1187).
|
|
257
|
+
* Has no effect unless `nativeStrings` is also true. Production builds should
|
|
258
|
+
* leave this unset — when off, the helpers are absent from the module entirely. */
|
|
259
|
+
testRuntime?: boolean;
|
|
260
|
+
/** Enable SIMD-accelerated string/array helpers (requires engine SIMD support) */
|
|
261
|
+
simd?: boolean;
|
|
262
|
+
/** Enable safe mode — reject unsafe TypeScript patterns at compile time */
|
|
263
|
+
safe?: boolean;
|
|
264
|
+
/** Globals allowed in safe mode (e.g. ["document"]) */
|
|
265
|
+
allowedGlobals?: string[];
|
|
266
|
+
/** Extern class members allowed in safe mode (e.g. { Element: ["textContent"] }) */
|
|
267
|
+
allowedExternMembers?: Record<string, string[]>;
|
|
268
|
+
/** Allow JavaScript source files as input (auto-detected for .js fileName) */
|
|
269
|
+
allowJs?: boolean;
|
|
270
|
+
/** Virtual file name for the source (controls language: use ".js" for JS input) */
|
|
271
|
+
fileName?: string;
|
|
272
|
+
/** Module resolution options for npm packages */
|
|
273
|
+
resolve?: {
|
|
274
|
+
/** Directories to search for modules (default: ["node_modules"]) */
|
|
275
|
+
modules?: string[];
|
|
276
|
+
/** File extensions to try during resolution (default: [".ts", ".tsx", ".d.ts"]) */
|
|
277
|
+
extensions?: string[];
|
|
278
|
+
};
|
|
279
|
+
/** Packages to keep as host imports (not resolved/bundled) */
|
|
280
|
+
externals?: string[];
|
|
281
|
+
/** ABI for exported functions: "default" (normal) or "c" (C-compatible calling conventions).
|
|
282
|
+
* C ABI is only supported with target: "linear". Strings/arrays become (ptr, len) pairs. */
|
|
283
|
+
abi?: "default" | "c";
|
|
284
|
+
/** Enable hardened mode: reject eval, Function constructor, with, __proto__ at compile time */
|
|
285
|
+
hardened?: boolean;
|
|
286
|
+
/** Skip semantic diagnostics for faster compilation (checker still available for type queries) */
|
|
287
|
+
skipSemanticDiagnostics?: boolean;
|
|
288
|
+
/** Generate a WIT (WebAssembly Interface Types) file from exported functions.
|
|
289
|
+
* When set, the result will include a `wit` field with the WIT interface definition.
|
|
290
|
+
* Value can be true (derive package name from fileName/moduleName) or an object with
|
|
291
|
+
* packageName/worldName options. */
|
|
292
|
+
wit?: boolean | {
|
|
293
|
+
packageName?: string;
|
|
294
|
+
worldName?: string;
|
|
295
|
+
};
|
|
296
|
+
/** Run Binaryen wasm-opt post-processing on the output binary (default: false).
|
|
297
|
+
* Requires either the 'binaryen' npm package or wasm-opt on PATH.
|
|
298
|
+
* Set to true for -O3 defaults, or pass a number (1-4) for a specific level. */
|
|
299
|
+
optimize?: boolean | 1 | 2 | 3 | 4;
|
|
300
|
+
/**
|
|
301
|
+
* Experimental: route a narrow set of functions through the middle-end IR
|
|
302
|
+
* (see `src/ir/`). Defaults to **on** since #1131 (the driver passes
|
|
303
|
+
* `experimentalIR !== false`); pass `false` to force the legacy
|
|
304
|
+
* direct-emission path (bit-by-bit divergence tests or emergency revert).
|
|
305
|
+
*/
|
|
306
|
+
experimentalIR?: boolean;
|
|
307
|
+
/** Compile-time constant definitions. Substitutes identifiers/dotted paths with literal values
|
|
308
|
+
* before TypeScript parsing. Example: `{ "process.env.NODE_ENV": '"production"' }`.
|
|
309
|
+
* Values must be valid JS expression literals (strings need inner quotes).
|
|
310
|
+
* Also supports shorthand: `"production"` mode sets process.env.NODE_ENV and typeof guards. */
|
|
311
|
+
define?: Record<string, string>;
|
|
312
|
+
/** Allow synchronous file-system access via `node:fs` (`readFileSync`, `writeFileSync`)
|
|
313
|
+
* as JS host imports in non-WASI targets (#1491). Gated behind an explicit flag
|
|
314
|
+
* to prevent accidental capability leakage when compiling third-party code.
|
|
315
|
+
* Default: false (calls to fs.readFileSync / fs.writeFileSync raise a compile error). */
|
|
316
|
+
allowFs?: boolean;
|
|
317
|
+
/**
|
|
318
|
+
* #2625 / #2633 — emit the per-module linkable `node:<mod>` shims instead of
|
|
319
|
+
* inlining the host APIs. WASI-only (ignored for other targets). When set,
|
|
320
|
+
* std-IO is routed through `node:fs`: the user module imports `readSync`/
|
|
321
|
+
* `writeSync` plus its linear memory from `node:fs` and carries no
|
|
322
|
+
* `wasi_snapshot_preview1` import for stream IO; console.log / process.std*.write
|
|
323
|
+
* lower to `writeSync(1|2, …)` and synchronous stdin is `readSync(0, …)`. Link
|
|
324
|
+
* against `node-fs.wasm` (or `--preload node:fs=node-fs.wasm` under wasmtime).
|
|
325
|
+
* Default off — the self-contained inline `fd_read`/`fd_write` path stays. The
|
|
326
|
+
* bespoke `js2wasm:node-process` shim (`process.stdin.read`/`stdout_write`/…)
|
|
327
|
+
* was retired in #2633; `process.stdin.read(buf, offset)` is no longer a
|
|
328
|
+
* recognised API (it matched no real Node surface — use `node:fs` `readSync`).
|
|
329
|
+
*/
|
|
330
|
+
linkNodeShims?: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Node API emulation (#2603). Opt-in via `--emulate node`. When set, the
|
|
333
|
+
* checker is given an ambient `process` declaration so Node globals js2wasm
|
|
334
|
+
* lowers (process.std{in,out,err}, argv, env, exit) type-check without
|
|
335
|
+
* @types/node — and the "Cannot find name 'process'" warning is suppressed.
|
|
336
|
+
* When NOT set, that warning instead suggests adding `--emulate node`.
|
|
337
|
+
* Type-level only; does not change emitted wasm.
|
|
338
|
+
*/
|
|
339
|
+
emulateNode?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Host environment scoping the AMBIENT global surface (#2528/#2645), now the
|
|
342
|
+
* unified host axis driven by `--target {web,node,deno}` (#2736). The legacy
|
|
343
|
+
* `--platform` flag is a deprecated alias onto this same field. It selects
|
|
344
|
+
* which globals are in scope at type-check time and whether Node-style
|
|
345
|
+
* emulation is on. The backend-lowering names (`gc`/`linear`/`wasi`/
|
|
346
|
+
* `standalone`) still live on the separate `target` option, so this stays an
|
|
347
|
+
* internal sub-axis even though the user-facing flag is unified.
|
|
348
|
+
*
|
|
349
|
+
* - `"web"` → DOM ambient surface (`window`, `document`, DOM types)
|
|
350
|
+
* in scope; node-only globals are not. Byte-identical to
|
|
351
|
+
* the historical default.
|
|
352
|
+
* - `"node"`/`"deno"` → DOM-only globals are NOT in scope (so `window.stop`
|
|
353
|
+
* in a node/deno host is a clear type error), AND the
|
|
354
|
+
* Node-emulation injection path turns on (#2645), so
|
|
355
|
+
* `process` & friends type-check without @types/node.
|
|
356
|
+
* (Real `@types/node` / Deno-lib loading is a later
|
|
357
|
+
* #2698 slice; here `deno` routes through the same
|
|
358
|
+
* node-emulation/no-DOM ambient surface as `node`.)
|
|
359
|
+
*
|
|
360
|
+
* `undefined` (unset) preserves today's behaviour exactly: the DOM ambient
|
|
361
|
+
* surface is loaded and `emulateNode` is driven solely by its own option /
|
|
362
|
+
* `node:`-import auto-detection. Type-level only; does not change emitted wasm.
|
|
363
|
+
*
|
|
364
|
+
* Precedence vs the backend `target` (e.g. `--target wasi`): the host surface
|
|
365
|
+
* and the backend are independent. When this is unset, a `wasi`/`standalone`
|
|
366
|
+
* target does NOT implicitly drop the DOM ambient surface — that would change
|
|
367
|
+
* today's output; pass `--target node`/`deno` explicitly to scope it.
|
|
368
|
+
*/
|
|
369
|
+
platform?: "web" | "node" | "deno";
|
|
370
|
+
/**
|
|
371
|
+
* Enforce dual-mode discipline (#1524): when true, codegen rejects any
|
|
372
|
+
* JS-host `env` import that is not on
|
|
373
|
+
* `src/codegen/host-import-allowlist.ts`. Auto-enabled under
|
|
374
|
+
* `target: "wasi"` unless this option is explicitly set to `false`
|
|
375
|
+
* (the `--allow-host-imports` CLI escape hatch).
|
|
376
|
+
*
|
|
377
|
+
* Compile errors raised by the gate name the offending import and the
|
|
378
|
+
* tracking issue that owns its Wasm-native replacement.
|
|
379
|
+
*/
|
|
380
|
+
strictNoHostImports?: boolean;
|
|
381
|
+
/**
|
|
382
|
+
* Linear backend (`target: "linear"`) allocator behaviour (#1856).
|
|
383
|
+
*
|
|
384
|
+
* The linear backend always uses a **bump/arena** allocator — each
|
|
385
|
+
* allocation advances a single heap pointer and nothing is freed until
|
|
386
|
+
* the Wasm instance is dropped (the "allocate-and-exit" model that suits
|
|
387
|
+
* most standalone/WASI short-lived programs; see R10 in
|
|
388
|
+
* `docs/architecture/compiler-design-lessons.md` and ADR-0017). There is
|
|
389
|
+
* deliberately no pluggable GC abstraction.
|
|
390
|
+
*
|
|
391
|
+
* - `"bump"` (default): the plain allocate-and-exit arena, smallest binary.
|
|
392
|
+
* - `"arena-reset"`: same allocator, but also exports `__arena_reset()`
|
|
393
|
+
* (O(1) rewind of the whole arena) and `__arena_used()` (bytes
|
|
394
|
+
* allocated). Use this when an embedder reuses one instance across many
|
|
395
|
+
* short-lived tasks and wants to reclaim between them.
|
|
396
|
+
*
|
|
397
|
+
* Ignored for non-`linear` targets — the WasmGC backends delegate object
|
|
398
|
+
* lifetime to the host GC and have no linear allocator.
|
|
399
|
+
*/
|
|
400
|
+
allocator?: "bump" | "arena-reset";
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Compile TypeScript source to Wasm GC binary.
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```ts
|
|
407
|
+
* const result = await compile(`
|
|
408
|
+
* export function add(a: number, b: number): number {
|
|
409
|
+
* return a + b;
|
|
410
|
+
* }
|
|
411
|
+
* `);
|
|
412
|
+
* if (result.success) {
|
|
413
|
+
* const { instance } = await WebAssembly.instantiate(result.binary, imports);
|
|
414
|
+
* console.log(instance.exports.add(2, 3)); // 5
|
|
415
|
+
* }
|
|
416
|
+
* ```
|
|
417
|
+
*/
|
|
418
|
+
export declare function compile(source: string, options?: CompileOptions): Promise<CompileResult>;
|
|
419
|
+
/**
|
|
420
|
+
* Compile multiple TypeScript source files into a single Wasm GC binary.
|
|
421
|
+
* Supports cross-file imports: `import { foo } from "./bar"`.
|
|
422
|
+
*/
|
|
423
|
+
export declare function compileMulti(files: Record<string, string>, entryFile: string, options?: CompileOptions): Promise<CompileResult>;
|
|
424
|
+
/**
|
|
425
|
+
* Compile a TypeScript project from an entry file on disk.
|
|
426
|
+
* Uses ts.createProgram with real filesystem access -- TypeScript resolves
|
|
427
|
+
* all imports (relative and package) automatically via standard module resolution.
|
|
428
|
+
* All resolved source files are compiled into a single Wasm module.
|
|
429
|
+
* Only the entry file's exports become Wasm exports.
|
|
430
|
+
*
|
|
431
|
+
* @param entryPath - Path to the entry .ts file (absolute or relative to cwd)
|
|
432
|
+
* @param options - Compile options
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* // Given: src/main.ts imports from src/utils.ts
|
|
437
|
+
* const result = await compileFiles("src/main.ts");
|
|
438
|
+
* // TypeScript resolves src/utils.ts automatically
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
export declare function compileFiles(entryPath: string, options?: CompileOptions): Promise<CompileResult>;
|
|
442
|
+
/** Only WAT text (debug) */
|
|
443
|
+
export declare function compileToWat(source: string): Promise<string>;
|
|
444
|
+
/**
|
|
445
|
+
* Compile TypeScript source to a relocatable Wasm object file (.o).
|
|
446
|
+
* The output contains LLVM-style linking and relocation metadata
|
|
447
|
+
* suitable for use with a Wasm linker.
|
|
448
|
+
*/
|
|
449
|
+
export declare function compileToObject(source: string, options?: CompileOptions): import('./compiler.js').ObjectCompileResult;
|
|
450
|
+
/**
|
|
451
|
+
* Compile a TypeScript project from an entry file on disk.
|
|
452
|
+
* Resolves npm package imports and relative imports recursively,
|
|
453
|
+
* then compiles all resolved files into a single Wasm module.
|
|
454
|
+
*
|
|
455
|
+
* @param entryFile - Absolute or relative path to the entry .ts file
|
|
456
|
+
* @param options - Compile options including resolve and externals settings
|
|
457
|
+
*/
|
|
458
|
+
export declare function compileProject(entryFile: string, options?: CompileOptions): Promise<CompileResult>;
|
|
459
|
+
/**
|
|
460
|
+
* Create an incremental compiler that reuses a persistent TypeScript Language Service.
|
|
461
|
+
* Lib files are parsed once on first compilation and cached for all subsequent compilations,
|
|
462
|
+
* eliminating ~50ms of program creation overhead per compilation.
|
|
463
|
+
*
|
|
464
|
+
* Ideal for worker pools or batch compilation scenarios where many source files
|
|
465
|
+
* are compiled sequentially in the same process.
|
|
466
|
+
*
|
|
467
|
+
* @example
|
|
468
|
+
* ```ts
|
|
469
|
+
* const compiler = createIncrementalCompiler();
|
|
470
|
+
* const result1 = compiler.compile("export function a(): number { return 1; }");
|
|
471
|
+
* const result2 = compiler.compile("export function b(): number { return 2; }"); // faster
|
|
472
|
+
* compiler.dispose(); // free resources when done
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
export declare function createIncrementalCompiler(defaultOptions?: CompileOptions): {
|
|
476
|
+
compile: (source: string, options?: CompileOptions) => Promise<CompileResult>;
|
|
477
|
+
dispose: () => void;
|
|
478
|
+
};
|
|
479
|
+
export { getBarePackageName, ModuleResolver, resolveAllImports } from './resolve.js';
|
|
480
|
+
export { preloadLibFiles } from './checker/index.js';
|
|
481
|
+
export { getEntryExportNames, treeshake } from './treeshake.js';
|
|
482
|
+
export { generateWit } from './wit-generator.js';
|
|
483
|
+
export type { WitGeneratorOptions } from './wit-generator.js';
|
|
484
|
+
export { canonicalHashOfTypeGroup, extractRuntimeGroup, fingerprintRuntimeGroup, RUNTIME_RECGROUP_ABI_VERSION, RUNTIME_RECGROUP_TYPE_NAMES, } from './emit/canonical-recgroup.js';
|
|
485
|
+
export type { RuntimeGroupFingerprint, RuntimeGroupMember } from './emit/canonical-recgroup.js';
|
|
486
|
+
export { buildImports, buildStringConstants, buildWasiPolyfill, checkPolicy, compileAndInstantiate, instantiateWasm, instantiateWasmStreaming, jsString, } from './runtime.js';
|