@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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* True when `srcType` is a `ref`/`ref_null` to a struct that defines a
|
|
5
|
+
* `[Symbol.iterator]()` method (registered as `${structName}_@@iterator`), and
|
|
6
|
+
* is therefore a user-defined iterable that should be drained through the
|
|
7
|
+
* iterator protocol rather than treated as a vec.
|
|
8
|
+
*
|
|
9
|
+
* Known vecs, native generators, native strings and externref JS iterables are
|
|
10
|
+
* handled by earlier branches at the call sites; this only fires for the
|
|
11
|
+
* object-literal / class-instance iterable case those branches don't cover.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isCustomIterable(ctx: CodegenContext, srcType: ValType): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Drain a user-defined iterable into a freshly built vec struct of element type
|
|
16
|
+
* `vecTypeIdx` via the iterator protocol, leaving `ref_null $vec` on the stack.
|
|
17
|
+
* The iterable value must already be stored in `iterableLocal` (a `ref`/
|
|
18
|
+
* `ref_null` to the iterable struct).
|
|
19
|
+
*
|
|
20
|
+
* Emits (using the `__iterator` / `__iterator_next` JS-host bridge):
|
|
21
|
+
* iter = __iterator(extern(obj)) // calls obj[Symbol.iterator]()
|
|
22
|
+
* cap = 4; data = new arr[cap]; len = 0
|
|
23
|
+
* loop:
|
|
24
|
+
* (done, val) = __iterator_next(iter)
|
|
25
|
+
* if done break
|
|
26
|
+
* if len == cap: grow (double, array.copy)
|
|
27
|
+
* data[len] = coerce(val: externref -> elemType); len++
|
|
28
|
+
* struct.new $vec { len, data }
|
|
29
|
+
*
|
|
30
|
+
* Mirrors the doubling-array drain the #1749 override-spread path uses. Returns
|
|
31
|
+
* `false` (emitting nothing) when the vec type can't be resolved or the
|
|
32
|
+
* iterator imports are unavailable, so the caller can fall back.
|
|
33
|
+
*/
|
|
34
|
+
export declare function emitDrainCustomIterableToVec(ctx: CodegenContext, fctx: FunctionContext, iterableLocal: number, iterableType: ValType, vecTypeIdx: number): boolean;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ValType } from '../ir/types.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
3
|
+
export declare function isDataViewAccessor(name: string): boolean;
|
|
4
|
+
/**
|
|
5
|
+
* #1698 — `ab.slice(begin?, end?)` in no-JS-host mode. Returns a new
|
|
6
|
+
* ArrayBuffer (i32_byte vec struct) holding bytes `[begin, end)` of the
|
|
7
|
+
* source, with the spec §25.1.5.3 negative-offset / clamp / default-end
|
|
8
|
+
* normalisation applied at runtime. Receiver and result are externref
|
|
9
|
+
* (the user's `const sliced = ab.slice(...)` local is typed externref;
|
|
10
|
+
* matching that here keeps `new Uint8Array(sliced)` working without
|
|
11
|
+
* additional coercion).
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitArrayBufferSlice(ctx: CodegenContext, fctx: FunctionContext, receiver: import("../ts-api.js").ts.Expression, args: readonly import("../ts-api.js").ts.Expression[], compileExpr: (expr: import("../ts-api.js").ts.Expression, hint?: ValType) => ValType | null): ValType | null;
|
|
14
|
+
/**
|
|
15
|
+
* (#2159 / #38) Lazily register the standalone `$__dv_window` wrapper struct:
|
|
16
|
+
* `{buf: (ref null __vec_i32_byte), byteOffset: i32, byteLength: i32}`.
|
|
17
|
+
*
|
|
18
|
+
* `new DataView(buffer, byteOffset, byteLength)` produces one of these when the
|
|
19
|
+
* view is *windowed* (byteOffset > 0 or an explicit byteLength); it shares the
|
|
20
|
+
* parent buffer's backing array so windowed writes are visible through the full
|
|
21
|
+
* view, and carries the window's byteOffset/byteLength so `dv.byteOffset` /
|
|
22
|
+
* `dv.byteLength` reflect the ctor args. Offset-0 default-length views keep the
|
|
23
|
+
* bare i32_byte vec representation (no wrapper) — the dominant, fully-native
|
|
24
|
+
* case — so the accessor must accept BOTH a wrapper and a bare vec receiver.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getOrRegisterDvWindowType(ctx: CodegenContext): number;
|
|
27
|
+
export declare function emitDataViewAccessor(ctx: CodegenContext, fctx: FunctionContext, methodName: string, receiver: import("../ts-api.js").ts.Expression, args: readonly import("../ts-api.js").ts.Expression[], compileExpr: (expr: import("../ts-api.js").ts.Expression, hint?: ValType) => ValType | null): {
|
|
28
|
+
kind: "get";
|
|
29
|
+
result: ValType;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "set";
|
|
32
|
+
} | null;
|
|
33
|
+
/**
|
|
34
|
+
* (#2639) Stage a native DataView's bytes into the linear write scratch so
|
|
35
|
+
* `node:fs` `writeSync(fd, dv)` can hand the shim a (ptr, len) pair.
|
|
36
|
+
*
|
|
37
|
+
* The DataView arg (an externref / GC ref already produced by compiling the
|
|
38
|
+
* argument expression — its `recvType` passed in) is resolved via
|
|
39
|
+
* {@link recoverDvBacking} to its i32_byte backing array + base byte offset +
|
|
40
|
+
* view byte length, mirroring exactly what the DataView accessors use. Then it
|
|
41
|
+
* copies `viewLen` bytes from `arr[base + j]` (masked to a byte) into
|
|
42
|
+
* `scratch[scratchStart + j]`. The DataView's backing array is `i32_byte` (one
|
|
43
|
+
* i32 per byte, 0..255), so each element is `& 0xff`-ed before the byte store.
|
|
44
|
+
*
|
|
45
|
+
* Returns the i32 local holding the view byte length (the count to write), or
|
|
46
|
+
* `-1` when the receiver isn't a resolvable DataView/ArrayBuffer view. The
|
|
47
|
+
* receiver value must already be on the stack (its `recvType` is consumed here).
|
|
48
|
+
* Memory is assumed already grown for `[scratchStart, scratchStart+viewLen)` —
|
|
49
|
+
* the caller grows it (it must, since the length is only known at runtime).
|
|
50
|
+
*/
|
|
51
|
+
export declare function emitDataViewToWriteScratch(ctx: CodegenContext, fctx: FunctionContext, recvType: ValType | null, scratchStart: number): number;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CodegenContext } from './context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Emit the native `__date_parse` helper if it is not already present.
|
|
4
|
+
*
|
|
5
|
+
* Locals (after param 0 = s:externref):
|
|
6
|
+
* 1 flat:ref$NativeString 2 data:ref$i16arr 3 len:i32 4 i:i32 5 c:i32
|
|
7
|
+
* 6 sign:i64 (year sign) 7 year:i64 8 month:i64 9 day:i64
|
|
8
|
+
* 10 hour:i64 11 min:i64 12 sec:i64 13 ms:i64
|
|
9
|
+
* 14 tzSign:i64 15 tzH:i64 16 tzM:i64
|
|
10
|
+
* 17 fail:i32 18 acc:i64 (digit accumulator) 19 ndig:i32 (digits read)
|
|
11
|
+
* 20 days:i64 (days-from-civil) 21 hasTime:i32 22 expanded:i32
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitNativeDateParse(ctx: CodegenContext): void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { WasmModule } from '../ir/types.js';
|
|
2
|
+
import { CodegenContext } from './context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Eliminate dead (unreferenced) function imports and type definitions
|
|
5
|
+
* from a compiled WasmModule. Mutates the module in place.
|
|
6
|
+
*
|
|
7
|
+
* #1899 — funcIdx-authority contract. This pass REMOVES dead function imports
|
|
8
|
+
* and remaps every funcIdx referenced from inside `mod` (bodies, exports,
|
|
9
|
+
* elements, declaredFuncRefs, start) through the authoritative `fR` remap, so
|
|
10
|
+
* the emitted module is internally consistent. Historically it touched ONLY
|
|
11
|
+
* `mod` and left the codegen-context side-tables (`funcMap`, `nativeStrHelpers`,
|
|
12
|
+
* …) stale by the removed-import delta. Any consumer that bakes a NEW `call`
|
|
13
|
+
* from those maps AFTER this pass (e.g. the `__unbox_number` repair in
|
|
14
|
+
* `fixups.ts`, which runs in `repairStructTypeMismatches` /
|
|
15
|
+
* `fixupExternConvertAny` right after dead-elim) would then target the wrong
|
|
16
|
+
* function — the recurring late-shift / index-desync class (#1677/#1809/#1839/
|
|
17
|
+
* #1886/#329/#1461/#2043). Pass `ctx` so the SAME authoritative `fR` is applied
|
|
18
|
+
* to the side-tables, keeping them in lockstep with the module exactly as the
|
|
19
|
+
* add-shift passes (`shiftLateImportIndices` / `reconcileNativeStrFinalizeShift`)
|
|
20
|
+
* already do for the import-ADD direction. The `ctx` arg is optional so non-codegen
|
|
21
|
+
* callers (tests, the standalone module rewriter) need no context; when omitted,
|
|
22
|
+
* only `mod` is remapped (the prior behaviour). The whole side-table remap is a
|
|
23
|
+
* no-op when no dead imports were removed (`fR.size === 0`), which is the common
|
|
24
|
+
* case mid-finalize.
|
|
25
|
+
*/
|
|
26
|
+
export declare function eliminateDeadImports(mod: WasmModule, ctx?: CodegenContext): void;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext } from './context/types.js';
|
|
4
|
+
/** Accumulated state for the single-pass collector */
|
|
5
|
+
interface UnifiedCollectorState {
|
|
6
|
+
consoleNeededByMethod: Map<string, Set<"number" | "bool" | "string" | "externref">>;
|
|
7
|
+
primitiveNeeded: Set<string>;
|
|
8
|
+
stringLiterals: Set<string>;
|
|
9
|
+
hasTypeofExprForStrings: boolean;
|
|
10
|
+
hasTaggedTemplate: boolean;
|
|
11
|
+
insideComputedPropertyName: number;
|
|
12
|
+
stringMethodNeeded: Set<string>;
|
|
13
|
+
/** String methods called with RegExp args — need host import even in native strings mode */
|
|
14
|
+
stringRegexpMethodNeeded: Set<string>;
|
|
15
|
+
mathNeeded: Set<string>;
|
|
16
|
+
mathNeedsToUint32: boolean;
|
|
17
|
+
parseNeeded: Set<string>;
|
|
18
|
+
dateParseHostNeeded: boolean;
|
|
19
|
+
uriNeeded: Set<string>;
|
|
20
|
+
needsFromCharCode: boolean;
|
|
21
|
+
needsFromCodePoint: boolean;
|
|
22
|
+
promiseNeeded: Set<string>;
|
|
23
|
+
promiseNeedConstructor: boolean;
|
|
24
|
+
promiseNeedThen2: boolean;
|
|
25
|
+
jsonNeedStringify: boolean;
|
|
26
|
+
jsonNeedParse: boolean;
|
|
27
|
+
callbackFound: boolean;
|
|
28
|
+
getterCallbackFound: boolean;
|
|
29
|
+
asyncCpsFound: boolean;
|
|
30
|
+
funcArrayNeed1: boolean;
|
|
31
|
+
funcArrayNeed2: boolean;
|
|
32
|
+
unionFound: boolean;
|
|
33
|
+
generatorFound: boolean;
|
|
34
|
+
iteratorFound: boolean;
|
|
35
|
+
arrayIteratorFound: boolean;
|
|
36
|
+
forInFound: boolean;
|
|
37
|
+
forInLiterals: Set<string>;
|
|
38
|
+
inExprLiterals: Set<string>;
|
|
39
|
+
objectMethodLiterals: Set<string>;
|
|
40
|
+
objectMethodHasValues: boolean;
|
|
41
|
+
wrapperFound: boolean;
|
|
42
|
+
unknownCtorNeeded: Map<string, number>;
|
|
43
|
+
sourceFile: ts.SourceFile;
|
|
44
|
+
}
|
|
45
|
+
export declare function createUnifiedCollectorState(sourceFile: ts.SourceFile): UnifiedCollectorState;
|
|
46
|
+
/** Single-pass visitor called on every AST node */
|
|
47
|
+
export declare function unifiedVisitNode(ctx: CodegenContext, state: UnifiedCollectorState, node: ts.Node): void;
|
|
48
|
+
/** Run all post-walk finalization (register imports based on collected state) */
|
|
49
|
+
export declare function finalizeUnifiedCollector(ctx: CodegenContext, state: UnifiedCollectorState): void;
|
|
50
|
+
/**
|
|
51
|
+
* Perform a single AST walk that collects all import-phase information.
|
|
52
|
+
* Replaces 19 separate collect* passes with one O(n) traversal.
|
|
53
|
+
* (#592)
|
|
54
|
+
*/
|
|
55
|
+
export declare function resolveGenericCallSiteTypes(ctx: CodegenContext, funcName: string, sourceFile: ts.SourceFile): {
|
|
56
|
+
params: ValType[];
|
|
57
|
+
results: ValType[];
|
|
58
|
+
} | null;
|
|
59
|
+
/**
|
|
60
|
+
* Infer a concrete type for an untyped function parameter by scanning call sites.
|
|
61
|
+
* When a parameter has no type annotation (TS gives it `any`), we look at every
|
|
62
|
+
* call to that function and collect the argument types at the given index.
|
|
63
|
+
* If all call sites agree on a single concrete wasm type, we return it.
|
|
64
|
+
* Returns null if no call site found or types disagree.
|
|
65
|
+
*/
|
|
66
|
+
export declare function inferParamTypeFromCallSites(ctx: CodegenContext, funcName: string, paramIndex: number, sourceFile: ts.SourceFile): ValType | null;
|
|
67
|
+
/**
|
|
68
|
+
* #1121: Fallback param-type inference from body usage. Used when
|
|
69
|
+
* `inferParamTypeFromCallSites` finds no call sites (e.g. an exported
|
|
70
|
+
* entrypoint that is only called from JS host) but the function body
|
|
71
|
+
* itself reveals how the parameter is used.
|
|
72
|
+
*
|
|
73
|
+
* Recognises three numeric-flow patterns:
|
|
74
|
+
* 1. `param` passed as an argument to a function whose return is in
|
|
75
|
+
* `ctx.numericReturnTypes` (the recursive numeric kernels detected
|
|
76
|
+
* by inferNumericReturnTypes).
|
|
77
|
+
* 2. `param` used as an operand of a numeric binary operator
|
|
78
|
+
* (+, -, *, /, %, **, |, &, ^, <<, >>, >>>, ToInt32 coercion).
|
|
79
|
+
* 3. `param` used as a numeric loop bound / comparison operand
|
|
80
|
+
* (<, <=, >, >=).
|
|
81
|
+
*
|
|
82
|
+
* Returns null if none of those patterns are found, leaving the param
|
|
83
|
+
* unchanged. This is intentionally conservative — the call-site path
|
|
84
|
+
* is still preferred when it has information.
|
|
85
|
+
*/
|
|
86
|
+
export declare function inferParamTypeFromBody(ctx: CodegenContext, decl: ts.FunctionLikeDeclaration, paramIndex: number): ValType | null;
|
|
87
|
+
/**
|
|
88
|
+
* #1121: Infer numeric (f64) return types for functions whose body is a
|
|
89
|
+
* purely-numeric kernel even when TypeScript reports the return as
|
|
90
|
+
* `any`/`unknown` (e.g. unannotated recursive helpers like
|
|
91
|
+
* `function fib(n) { ... }`).
|
|
92
|
+
*
|
|
93
|
+
* We do a fixpoint over the entire source file:
|
|
94
|
+
* 1. Seed: every function declaration whose TS return type is implicit
|
|
95
|
+
* any/unknown becomes a candidate for f64 promotion (assuming numeric).
|
|
96
|
+
* 2. Iterate: a candidate stays in the set only while every `return X`
|
|
97
|
+
* in its body produces a value whose type is structurally numeric
|
|
98
|
+
* under the assumption that all other candidates also return f64.
|
|
99
|
+
* 3. The fixpoint converges in O(N * passes) where passes is bounded by
|
|
100
|
+
* the number of candidates.
|
|
101
|
+
*
|
|
102
|
+
* This intentionally does NOT consider parameter types — by the time we
|
|
103
|
+
* are called, the param-inference pass has already retyped each
|
|
104
|
+
* implicit-any parameter via `inferParamTypeFromCallSites`. We only need
|
|
105
|
+
* to fix the return-type side, which is what TS gives up on for
|
|
106
|
+
* recursive numeric kernels.
|
|
107
|
+
*/
|
|
108
|
+
export declare function inferNumericReturnTypes(ctx: CodegenContext, sourceFile: ts.SourceFile): Map<string, ValType>;
|
|
109
|
+
/**
|
|
110
|
+
* Pre-pass: detect empty object literals (`var obj = {}`) that later receive
|
|
111
|
+
* property assignments (`obj.prop = val`) and record the extra properties so
|
|
112
|
+
* that ensureStructForType creates a struct with the correct fields.
|
|
113
|
+
*
|
|
114
|
+
* This runs *before* collectDeclarations so the struct type is correct from
|
|
115
|
+
* the start.
|
|
116
|
+
*/
|
|
117
|
+
export declare function collectEmptyObjectWidening(ctx: CodegenContext, checker: ts.TypeChecker, sourceFile: ts.SourceFile): void;
|
|
118
|
+
export declare function collectPropsFromStatements(checker: ts.TypeChecker, ctx: CodegenContext, stmts: readonly ts.Statement[], varName: string, extraProps: {
|
|
119
|
+
name: string;
|
|
120
|
+
type: ValType;
|
|
121
|
+
}[], seenProps: Set<string>): void;
|
|
122
|
+
/**
|
|
123
|
+
* Apply shape inference: detect module-level variables used as array-like objects
|
|
124
|
+
* and override their global types from externref/AnyValue to vec struct types.
|
|
125
|
+
* Must be called after collectDeclarations (which registers module globals).
|
|
126
|
+
*/
|
|
127
|
+
export declare function applyShapeInference(ctx: CodegenContext, checker: ts.TypeChecker, sourceFile: ts.SourceFile): void;
|
|
128
|
+
export declare function collectDeclarations(ctx: CodegenContext, sourceFile: ts.SourceFile, isEntryFile?: boolean): void;
|
|
129
|
+
export declare function collectInterface(ctx: CodegenContext, decl: ts.InterfaceDeclaration): void;
|
|
130
|
+
/**
|
|
131
|
+
* After all interfaces and type aliases are collected, re-resolve field types
|
|
132
|
+
* that were initially mapped to externref but should be ref $struct.
|
|
133
|
+
* This handles cross-references between interfaces regardless of declaration order.
|
|
134
|
+
*/
|
|
135
|
+
export declare function resolveStructFieldTypes(ctx: CodegenContext, sourceFile: ts.SourceFile): void;
|
|
136
|
+
export declare function collectObjectType(ctx: CodegenContext, name: string, type: ts.Type): void;
|
|
137
|
+
/** Compile all function bodies (including class constructors and methods) */
|
|
138
|
+
export declare function compileDeclarations(ctx: CodegenContext, sourceFile: ts.SourceFile): void;
|
|
139
|
+
export {};
|
|
140
|
+
/**
|
|
141
|
+
* Post-compilation fixup: insert extern.convert_any after struct.new when
|
|
142
|
+
* the result is stored into an externref local (local.set / local.tee).
|
|
143
|
+
*
|
|
144
|
+
* This happens when a vec/class struct is created but the target variable
|
|
145
|
+
* was typed as externref by the compiler.
|
|
146
|
+
*/
|
|
147
|
+
/** Internal field names that are not user-visible properties */
|
|
@@ -0,0 +1,11 @@
|
|
|
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 Deno synchronous stdio call under `--target wasi`. Returns
|
|
6
|
+
* the result (`number | null` externref for readSync, `number` f64 for
|
|
7
|
+
* writeSync), or `undefined` when this isn't a Deno stdio call (the generic
|
|
8
|
+
* compiler then proceeds). Non-WASI targets fall through entirely — a Deno
|
|
9
|
+
* program "runs under real Deno" uncompiled; we only LOWER it under wasi.
|
|
10
|
+
*/
|
|
11
|
+
export declare function tryCompileDenoStdioCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
* Number of iterator steps an array binding/assignment pattern consumes
|
|
6
|
+
* (§8.5.3 IteratorBindingInitialization). Each element — INCLUDING elision
|
|
7
|
+
* holes (`OmittedExpression`) — costs exactly one IteratorStep. A rest element
|
|
8
|
+
* drains the remainder of the iterator → unbounded → -1.
|
|
9
|
+
*
|
|
10
|
+
* Binding patterns mark rest via `BindingElement.dotDotDotToken`; assignment
|
|
11
|
+
* patterns use `SpreadElement`. The returned count feeds `__array_from_iter_n`
|
|
12
|
+
* so a no-rest pattern materializes EXACTLY `elements.length` steps instead of
|
|
13
|
+
* draining a lazy generator to completion (#1592). `-1` routes through the
|
|
14
|
+
* unbounded (legacy `__array_from_iter`) path, preserving all IteratorClose
|
|
15
|
+
* tuning (#1219).
|
|
16
|
+
*/
|
|
17
|
+
export declare function patternIteratorStepCount(elements: readonly (ts.ArrayBindingElement | ts.Expression)[]): number;
|
|
18
|
+
/**
|
|
19
|
+
* Destructuring mode for the param-destructure helpers (#1553a).
|
|
20
|
+
*
|
|
21
|
+
* - `"param"` (default): function-parameter destructuring; emits no TDZ flags.
|
|
22
|
+
* - `"catch"`: catch-clause destructuring; behaves like `"param"` today
|
|
23
|
+
* (centralised here so #1552's catch helper can opt in later).
|
|
24
|
+
* - `"decl"`: declaration-form (`let`/`const`/`var`) destructuring; emits
|
|
25
|
+
* `emitLocalTdzInit` after every binding `local.set`, and (for `let`/`const`)
|
|
26
|
+
* calls `ensureLetConstBindingPatternTdzFlags` at entry so each bound
|
|
27
|
+
* identifier has a TDZ flag local before its sibling defaults run.
|
|
28
|
+
*/
|
|
29
|
+
export type DestructureMode = "param" | "catch" | "decl";
|
|
30
|
+
/**
|
|
31
|
+
* Caller-declared binding kind. Only meaningful when `mode === "decl"`:
|
|
32
|
+
*
|
|
33
|
+
* - `"let"` / `"const"`: requires per-binding TDZ flags.
|
|
34
|
+
* - `"var"`: `emitLocalTdzInit` is a no-op (no flag was allocated by the
|
|
35
|
+
* pre-pass), so behaviour is correct without an extra branch.
|
|
36
|
+
* - `"param"`: catch-mode + param-mode default; the helper ignores it.
|
|
37
|
+
*/
|
|
38
|
+
export type BindingKind = "let" | "const" | "var" | "param";
|
|
39
|
+
export interface DestructureOpts {
|
|
40
|
+
mode?: DestructureMode;
|
|
41
|
+
bindingKind?: BindingKind;
|
|
42
|
+
}
|
|
43
|
+
export declare function buildDestructureNullThrow(ctx: CodegenContext, fctx?: FunctionContext): Instr[];
|
|
44
|
+
/**
|
|
45
|
+
* Returns true when `expr` is a literal `null` or `undefined` — which per spec
|
|
46
|
+
* must throw TypeError when used as the source value for a destructuring pattern
|
|
47
|
+
* (RequireObjectCoercible / GetIterator).
|
|
48
|
+
*
|
|
49
|
+
* Used by parameter default-emission to statically reject `({pat} = null)` and
|
|
50
|
+
* `({pat} = undefined)` even when paramType is numeric (loses null/undef info).
|
|
51
|
+
*/
|
|
52
|
+
export declare function isNullOrUndefinedLiteral(expr: ts.Expression): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Destructure a function parameter (externref) using __extern_get for property access.
|
|
55
|
+
* This handles primitives, objects, and any externref value safely — no struct cast needed.
|
|
56
|
+
* Used as fallback when the value is not the expected struct type (#852).
|
|
57
|
+
*/
|
|
58
|
+
export declare function destructureParamObjectExternref(ctx: CodegenContext, fctx: FunctionContext, paramIdx: number, pattern: ts.ObjectBindingPattern, opts?: DestructureOpts): void;
|
|
59
|
+
/**
|
|
60
|
+
* Emit a null/undefined check for an externref destructuring parameter.
|
|
61
|
+
* Checks both ref.is_null (Wasm null) and __extern_is_undefined (JS undefined).
|
|
62
|
+
* Throws TypeError if either is true.
|
|
63
|
+
*/
|
|
64
|
+
export declare function emitExternrefDestructureGuard(ctx: CodegenContext, fctx: FunctionContext, paramIdx: number): void;
|
|
65
|
+
/**
|
|
66
|
+
* (#2568) Derive the WasmGC struct type a destructuring object binding pattern
|
|
67
|
+
* resolves to, as a `ref`-typed compile hint for the pattern's default object
|
|
68
|
+
* literal. Mirrors the struct-type derivation in `destructureParamObject` below
|
|
69
|
+
* so an outer param default materializes in the SAME shape the destructuring
|
|
70
|
+
* `ref.test`/`ref.cast` expects (otherwise the default boxes its nested fields
|
|
71
|
+
* to externref → a `{ field: externref }` struct that fails the `ref.test`, drops
|
|
72
|
+
* to the `__extern_get` else-branch, and reads 0). Returns `undefined` when no
|
|
73
|
+
* resolvable struct exists (rest pattern, missing fields, primitive) — the
|
|
74
|
+
* caller then keeps the externref hint. Shared by the class-method
|
|
75
|
+
* (class-bodies.ts) and plain-function (function-body.ts) param-default sites.
|
|
76
|
+
*/
|
|
77
|
+
export declare function structHintForBindingPattern(ctx: CodegenContext, pattern: ts.ObjectBindingPattern): ValType | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Destructure a function parameter that is an ObjectBindingPattern.
|
|
80
|
+
* The parameter value (a struct ref) is at param index `paramIdx`.
|
|
81
|
+
* We extract each bound field into a new local.
|
|
82
|
+
*/
|
|
83
|
+
export declare function destructureParamObject(ctx: CodegenContext, fctx: FunctionContext, paramIdx: number, pattern: ts.ObjectBindingPattern, paramType: ValType, opts?: DestructureOpts): void;
|
|
84
|
+
/**
|
|
85
|
+
* Destructure a function parameter that is an ArrayBindingPattern.
|
|
86
|
+
* The parameter value (a vec struct ref) is at param index `paramIdx`.
|
|
87
|
+
* We extract each element into a new local.
|
|
88
|
+
*/
|
|
89
|
+
export declare function destructureParamArray(ctx: CodegenContext, fctx: FunctionContext, paramIdx: number, pattern: ts.ArrayBindingPattern, paramType: ValType, opts?: DestructureOpts): void;
|
|
90
|
+
/**
|
|
91
|
+
* Cache string literal thunk calls in locals for the given function.
|
|
92
|
+
*
|
|
93
|
+
* After a function body has been compiled, this scans all instructions
|
|
94
|
+
* (including nested blocks/loops/ifs) for `call` instructions that invoke
|
|
95
|
+
* string literal thunks (__str_N). For each unique thunk found it:
|
|
96
|
+
* 1. Allocates an `externref` local to hold the cached value.
|
|
97
|
+
* 2. Prepends `call $__str_N` + `local.set $cached` at function entry.
|
|
98
|
+
* 3. Replaces every matching `call` in the body with `local.get $cached`.
|
|
99
|
+
*
|
|
100
|
+
* This avoids repeated import calls for the same string literal, which is
|
|
101
|
+
* especially beneficial inside loops.
|
|
102
|
+
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Register the `__dyn_has` / `__dyn_get` runtime read primitives. Idempotent and
|
|
4
|
+
* **gated on `ctx.usesDynRead`** — a no-op unless a call site (M1+) has flagged
|
|
5
|
+
* that the module needs them, so M0 (no call sites) emits nothing.
|
|
6
|
+
*
|
|
7
|
+
* Call this in the finalize phase, after `ensureObjectRuntime`/`ensureAnyHelpers`
|
|
8
|
+
* (the helpers reference `$AnyValue` + `__extern_get`). It must run before
|
|
9
|
+
* dead-elim / late-import settle so the baked funcIdx values are stable.
|
|
10
|
+
*/
|
|
11
|
+
export declare function ensureDynReadHelpers(ctx: CodegenContext): void;
|
|
12
|
+
/**
|
|
13
|
+
* (#2580 M1) Call-site helper: emit a `__dyn_get(recv, "<keyName>")` at a property
|
|
14
|
+
* read site. The RECEIVER externref must already be on the stack; this pushes the
|
|
15
|
+
* key string (externref) and the `call __dyn_get`, leaving the value externref
|
|
16
|
+
* (the property, or `undefined` when absent) on the stack.
|
|
17
|
+
*
|
|
18
|
+
* Runs during BODY compilation (not finalize): it eagerly `ensureObjectRuntime`
|
|
19
|
+
* (so `__extern_get` exists — safe to register its struct types here, the normal
|
|
20
|
+
* path) and eagerly emits the dyn-read helpers (so `__dyn_get`'s funcIdx is known
|
|
21
|
+
* for the `call` below). Sets `ctx.usesDynRead` so the finalize pass is a no-op
|
|
22
|
+
* (the latch is already set). Returns true on success; false (no-op, receiver
|
|
23
|
+
* left on stack) if the runtime is unavailable — the caller then keeps its prior
|
|
24
|
+
* lowering.
|
|
25
|
+
*/
|
|
26
|
+
export declare function emitDynGet(ctx: CodegenContext, fctx: FunctionContext, keyName: string): boolean;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { default as ts } from 'typescript';
|
|
2
|
+
export declare enum EvalTier {
|
|
3
|
+
/** No eval anywhere — full optimization. */
|
|
4
|
+
NoEval = 1,
|
|
5
|
+
/** Only static-literal eval — inlined at compile time (#1163). */
|
|
6
|
+
StaticLiteral = 2,
|
|
7
|
+
/** Indirect eval — affects global scope only; locals unaffected. */
|
|
8
|
+
Indirect = 3,
|
|
9
|
+
/** Direct eval, strict mode — locals stay unboxed, no function replacement. */
|
|
10
|
+
DirectStrict = 4,
|
|
11
|
+
/** Direct eval, sloppy mode — full boxing + mutable funcref globals. */
|
|
12
|
+
DirectSloppy = 5
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Classify a module's eval usage into its worst-case tier. Read-only.
|
|
16
|
+
*
|
|
17
|
+
* Returns `EvalTier.NoEval` when the module contains no real eval call.
|
|
18
|
+
*/
|
|
19
|
+
export declare function classifyEvalTier(sourceFile: ts.SourceFile, checker: ts.TypeChecker): EvalTier;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
import { InnerResult } from '../shared.js';
|
|
5
|
+
export declare function compileAssignment(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): InnerResult;
|
|
6
|
+
/**
|
|
7
|
+
* Detect strict-mode context for a node (§10.2.1).
|
|
8
|
+
* A node is in strict mode if:
|
|
9
|
+
* - Containing source file starts with `"use strict";` directive.
|
|
10
|
+
* - Inside a class body (classes are always strict).
|
|
11
|
+
* - Inside a function whose body begins with `"use strict";`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function isStrictContext(node: ts.Node): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* True if `id` is an identifier that cannot be resolved to any binding the
|
|
16
|
+
* compiler knows about. Mirrors the check in identifiers.ts:393 for reads
|
|
17
|
+
* but also excludes bindings that only exist in the codegen (locals, captures,
|
|
18
|
+
* globals, func imports).
|
|
19
|
+
*/
|
|
20
|
+
export declare function isUnresolvableIdent(ctx: CodegenContext, fctx: FunctionContext, id: ts.Identifier): boolean;
|
|
21
|
+
export declare function findUnresolvableInObjectPattern(ctx: CodegenContext, fctx: FunctionContext, target: ts.ObjectLiteralExpression): boolean;
|
|
22
|
+
export declare function findUnresolvableInArrayPattern(ctx: CodegenContext, fctx: FunctionContext, target: ts.ArrayLiteralExpression): boolean;
|
|
23
|
+
declare function compileDestructuringAssignment(ctx: CodegenContext, fctx: FunctionContext, target: ts.ObjectLiteralExpression, value: ts.Expression): InnerResult;
|
|
24
|
+
declare function compileArrayDestructuringAssignment(ctx: CodegenContext, fctx: FunctionContext, target: ts.ArrayLiteralExpression, value: ts.Expression): InnerResult;
|
|
25
|
+
declare function compilePropertyAssignment(ctx: CodegenContext, fctx: FunctionContext, target: ts.PropertyAccessExpression, value: ts.Expression): InnerResult;
|
|
26
|
+
declare function compileElementAssignment(ctx: CodegenContext, fctx: FunctionContext, target: ts.ElementAccessExpression, value: ts.Expression): InnerResult;
|
|
27
|
+
/**
|
|
28
|
+
* Fallback for element assignment on non-array types.
|
|
29
|
+
* Converts the object to externref and calls __extern_set(obj, key, val).
|
|
30
|
+
* The object value is already on the stack.
|
|
31
|
+
*/
|
|
32
|
+
declare function compileExternSetFallback(ctx: CodegenContext, fctx: FunctionContext, target: ts.ElementAccessExpression, value: ts.Expression, objType: ValType): InnerResult;
|
|
33
|
+
/**
|
|
34
|
+
* Compile logical assignment operators: ??=, ||=, &&=
|
|
35
|
+
*
|
|
36
|
+
* Desugars to value-preserving semantics:
|
|
37
|
+
* a ??= b → if (a is null) a = b; result = a
|
|
38
|
+
* a ||= b → if (!a) a = b; result = a
|
|
39
|
+
* a &&= b → if (a) a = b; result = a
|
|
40
|
+
*/
|
|
41
|
+
export declare function compileLogicalAssignment(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression, op: ts.SyntaxKind): ValType | null;
|
|
42
|
+
export declare function isCompoundAssignment(op: ts.SyntaxKind): boolean;
|
|
43
|
+
export declare function compileCompoundAssignment(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression, op: ts.SyntaxKind): ValType | null;
|
|
44
|
+
/**
|
|
45
|
+
* (#2666) ToPropertyKey §7.1.19, applied EXACTLY ONCE to the key externref on
|
|
46
|
+
* the stack, leaving the coerced key externref on the stack. For a member
|
|
47
|
+
* read-modify-write (`o[key] op= rhs`, `o[key]++`) the LHS Reference is
|
|
48
|
+
* evaluated once (§13.15.2 / §13.4), so the key's ToPropertyKey must fire once —
|
|
49
|
+
* but the raw key flows to both `__extern_get` and `__extern_set`, each of which
|
|
50
|
+
* ToPropertyKeys internally, double-firing a side-effecting `toString`/`valueOf`.
|
|
51
|
+
* Coercing here once yields a primitive (string) or a preserved Symbol, which is
|
|
52
|
+
* idempotent under the host's internal ToPropertyKey (string→string,
|
|
53
|
+
* symbol→symbol) so the subsequent get/set do not re-coerce.
|
|
54
|
+
*
|
|
55
|
+
* HOST mode: the `__to_property_key` JS import wraps `_toPropertyKey` (§7.1.19,
|
|
56
|
+
* Symbol-preserving). STANDALONE: the native `__to_property_key` helper
|
|
57
|
+
* (object-runtime.ts) — ensure the object runtime so it is emitted.
|
|
58
|
+
*/
|
|
59
|
+
export declare function emitToPropertyKeyOnce(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
60
|
+
/** Unwrap parenthesized expressions: (x) -> x, ((x)) -> x, etc. */
|
|
61
|
+
export { compileArrayDestructuringAssignment, compileDestructuringAssignment, compileElementAssignment, compileExternSetFallback, compilePropertyAssignment, };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
import { InnerResult } from '../shared.js';
|
|
5
|
+
declare function compileConsoleCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, method: string): InnerResult;
|
|
6
|
+
/** Ensure the $__Date struct type exists, return its type index. */
|
|
7
|
+
export declare function ensureDateStruct(ctx: CodegenContext): number;
|
|
8
|
+
/**
|
|
9
|
+
* Ensure the __date_days_from_civil helper function exists.
|
|
10
|
+
* Signature: (i64 year, i64 month, i64 day) -> i64 days_since_epoch
|
|
11
|
+
*
|
|
12
|
+
* Implements Hinnant's days_from_civil algorithm (inverse of civil_from_days).
|
|
13
|
+
*/
|
|
14
|
+
export declare function ensureDateDaysFromCivilHelper(ctx: CodegenContext): number;
|
|
15
|
+
/**
|
|
16
|
+
* Compile a Date method call on a Date struct receiver.
|
|
17
|
+
* Returns undefined if this is not a Date method (caller should continue).
|
|
18
|
+
*/
|
|
19
|
+
declare function compileDateMethodCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression, receiverType: ts.Type): InnerResult | undefined;
|
|
20
|
+
/** Allocate a UTF-8 string in a data segment and return its offset/length */
|
|
21
|
+
declare function wasiAllocStringData(ctx: CodegenContext, str: string): {
|
|
22
|
+
offset: number;
|
|
23
|
+
length: number;
|
|
24
|
+
};
|
|
25
|
+
declare function compileMathCall(ctx: CodegenContext, fctx: FunctionContext, method: string, expr: ts.CallExpression): ValType | null | undefined;
|
|
26
|
+
export { compileConsoleCall, compileDateMethodCall, compileMathCall, wasiAllocStringData };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ClosureInfo, CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
import { InnerResult } from '../shared.js';
|
|
4
|
+
/** Compile a call to a closure variable: closureVar(args...) */
|
|
5
|
+
export declare function compileClosureCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, varName: string, info: ClosureInfo): InnerResult;
|
|
6
|
+
/**
|
|
7
|
+
* Handle calls where the property is a getter that returns a callable:
|
|
8
|
+
* c.method(args) where `get method()` returns a function reference.
|
|
9
|
+
*
|
|
10
|
+
* Strategy: check if the getter returns a method of the same class
|
|
11
|
+
* (common pattern: `get method() { return this.#method; }`).
|
|
12
|
+
* If so, call the underlying method directly with the receiver.
|
|
13
|
+
* Otherwise, call the getter and invoke the result via host import.
|
|
14
|
+
*/
|
|
15
|
+
export declare function compileGetterCallable(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, receiverClassName: string, getterIdx: number): InnerResult | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Object.prototype method fallback for known class instances (#799 WI1).
|
|
18
|
+
*
|
|
19
|
+
* When a method call like `obj.toString()` cannot be resolved on a user-defined
|
|
20
|
+
* class or its ancestors, this function checks if the method is an Object.prototype
|
|
21
|
+
* method and emits host-delegated code via externref conversion.
|
|
22
|
+
*/
|
|
23
|
+
export declare function compileObjectPrototypeFallback(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, receiverClassName: string, methodName: string): InnerResult | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* Handle calls to callable struct fields: obj.callback() where callback
|
|
26
|
+
* is a function-typed property stored in a struct field (not a method).
|
|
27
|
+
* Returns undefined if the property is not a callable struct field,
|
|
28
|
+
* allowing the caller to fall through to other handling.
|
|
29
|
+
*/
|
|
30
|
+
export declare function compileCallablePropertyCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, className: string): InnerResult | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Handle calls where the callee is an element-access expression on a value
|
|
33
|
+
* whose element type has TS call signatures: `arr[i](args)`, `arr[const](args)`,
|
|
34
|
+
* `arr["0"](args)`. This mirrors the externref-field branch of
|
|
35
|
+
* `compileCallablePropertyCall` but routes through the existing element-access
|
|
36
|
+
* codegen for the receiver, so it works for vec-of-callable, ref-of-callable,
|
|
37
|
+
* tuple-of-callable, and any other element-access shape.
|
|
38
|
+
*
|
|
39
|
+
* Returns undefined when the element type has no call signature (e.g. native
|
|
40
|
+
* `i32[]` / `f64[]`), letting the caller fall through to the historical
|
|
41
|
+
* `ref.null.extern; drop` fallback.
|
|
42
|
+
*
|
|
43
|
+
* #1306: `mws[idx](c, next)` on a closure-typed array previously dropped the
|
|
44
|
+
* call. With this helper the value is loaded via __vec_get / array.get, unboxed
|
|
45
|
+
* (externref → __fn_wrap struct) and dispatched via call_ref.
|
|
46
|
+
*/
|
|
47
|
+
export declare function compileCallableElementAccessCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, elemAccess: ts.ElementAccessExpression): InnerResult | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Try to resolve a method call on an `any`-typed receiver through registered extern classes.
|
|
50
|
+
* When the type checker resolves the receiver as `any` (e.g. when lib files aren't loaded
|
|
51
|
+
* in ESM/bundled contexts), we dispatch known collection methods (Set.union, Map.get, etc.)
|
|
52
|
+
* by looking them up in ctx.externClasses and lazily registering the import.
|
|
53
|
+
*/
|
|
54
|
+
export declare function tryExternClassMethodOnAny(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression, methodName: string): InnerResult;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
import { InnerResult } from '../shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* (#1732) Calling a built-in non-constructor namespace — `Math()`, `JSON()`,
|
|
6
|
+
* `Reflect()`, `Atomics()` — must throw TypeError ("no [[Call]]"). These
|
|
7
|
+
* namespace objects have neither a [[Call]] nor [[Construct]] internal method
|
|
8
|
+
* (§sec-math-object etc.). The `new`-site already throws via the mirror guard
|
|
9
|
+
* in new-super.ts (NAMESPACE_NON_CONSTRUCTORS); this closes the call-as-function
|
|
10
|
+
* form (built-ins/Math/prop-desc.js "no [[Call]]"). Unwrap paren/as/!-assertion
|
|
11
|
+
* wrappers so `(Math as any)()` also fires.
|
|
12
|
+
*
|
|
13
|
+
* Returns an externref result when it throws; `undefined` when the callee is not
|
|
14
|
+
* a non-callable namespace identifier (caller continues dispatch).
|
|
15
|
+
*/
|
|
16
|
+
export declare function tryNamespaceNonCallable(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* (#1540) JSX runtime call intercept — `_jsx(type, props, key?)` /
|
|
19
|
+
* `_jsxs(type, props, key?)` / `_jsxDEV(...)`. TypeScript emits these
|
|
20
|
+
* automatically when `jsx: react-jsx` is set; preprocessImports recorded the
|
|
21
|
+
* actual local-binding names in `ctx.jsxRuntime`. We route the call to the
|
|
22
|
+
* matching `__jsx_runtime_*` host import (registered in
|
|
23
|
+
* `registerJsxRuntimeImports`), passing args as externref.
|
|
24
|
+
*
|
|
25
|
+
* Returns an externref result when it intercepts; `undefined` otherwise.
|
|
26
|
+
*/
|
|
27
|
+
export declare function tryJsxRuntimeCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* `RegExp(pattern, flags)` called without `new` — per spec, equivalent to
|
|
30
|
+
* `new RegExp(pattern, flags)` (unless pattern is already a RegExp with flags
|
|
31
|
+
* undefined, an edge case we accept). Host mode emits RegExp_new directly;
|
|
32
|
+
* standalone mode routes static literal patterns to #682's native subset and
|
|
33
|
+
* keeps unsupported forms on the explicit refusal path.
|
|
34
|
+
*
|
|
35
|
+
* Returns an externref result when it handles the call; `undefined` otherwise.
|
|
36
|
+
*/
|
|
37
|
+
export declare function tryRegExpConstructorCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* `Object(x)` called without `new` — ECMAScript §20.1.1.1 / §7.1.18 ToObject.
|
|
40
|
+
* Per spec: Object() / Object(null) / Object(undefined) → fresh empty object;
|
|
41
|
+
* Object(number) → new Number wrapper (typeof === "object");
|
|
42
|
+
* Object(string) → new String wrapper; Object(boolean) → new Boolean wrapper;
|
|
43
|
+
* Object(object) → return the argument unchanged.
|
|
44
|
+
* (#1129) Without this, `Object(42)` fell through to the generic builtin path
|
|
45
|
+
* which produced `ref.null.extern`.
|
|
46
|
+
*
|
|
47
|
+
* Returns an externref result when the callee is `Object`; `undefined` otherwise.
|
|
48
|
+
*/
|
|
49
|
+
export declare function tryObjectCoercionCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
import { InnerResult } from '../shared.js';
|
|
4
|
+
export declare function compileOptionalCallExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult;
|