@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,83 @@
|
|
|
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
|
+
import { compileOptionalCallExpression } from './calls-optional.js';
|
|
6
|
+
/**
|
|
7
|
+
* #2580 M3 Stage A — compile a `[[Prototype]]` argument (the proto operand of
|
|
8
|
+
* `Object.create(proto)` / `Object.setPrototypeOf(obj, proto)`) so that an
|
|
9
|
+
* INLINE OBJECT LITERAL proto is built as a native `$Object`, pushing an
|
|
10
|
+
* externref onto the stack.
|
|
11
|
+
*
|
|
12
|
+
* Root cause (standalone): the native `__object_create` / `__object_setPrototypeOf`
|
|
13
|
+
* helpers write the link field `$Object.$proto` only when the proto value
|
|
14
|
+
* `ref.test $Object` succeeds (a non-`$Object` externref coerces to null, by
|
|
15
|
+
* design — see object-runtime.ts `__object_create`/`__object_setPrototypeOf`).
|
|
16
|
+
* `compileObjectLiteral` lowers an inline literal whose TS contextual type is a
|
|
17
|
+
* CONCRETE object type (not `any`) to a CLOSED-shape struct (`struct.new <typeIdx>`),
|
|
18
|
+
* which fails `ref.test $Object`. So `Object.create({foo:7}).foo` and
|
|
19
|
+
* `Object.setPrototypeOf(o,{foo:7}); o.foo` silently lose the proto link (the
|
|
20
|
+
* chain walk reads a null `$proto` → property absent → 0). A proto passed via a
|
|
21
|
+
* `const p:any = {foo:7}` *named variable* already works because the `any`
|
|
22
|
+
* annotation diverts that literal to the open-`$Object` builder (literals.ts).
|
|
23
|
+
*
|
|
24
|
+
* Fix mirrors the merged #2076 `compileObjectAssignArg` precedent: when the proto
|
|
25
|
+
* is a plain data-property / spread object literal (the same shapes the `$Object`
|
|
26
|
+
* builder accepts), build it directly as a native `$Object` via
|
|
27
|
+
* `compileObjectLiteralAsExternref` so `ref.test $Object` succeeds and the link
|
|
28
|
+
* is recorded. Any other proto expression (identifiers, calls, `null`,
|
|
29
|
+
* `Foo.prototype`, accessor-bearing literals) keeps the ordinary
|
|
30
|
+
* `compileExpression` path unchanged. Standalone-only — host/GC mode owns the
|
|
31
|
+
* `__object_create` JS import and a separate (still-broken, tracked) proto-link
|
|
32
|
+
* mechanism, untouched here.
|
|
33
|
+
*/
|
|
34
|
+
export declare function compileProtoArg(ctx: CodegenContext, fctx: FunctionContext, arg: ts.Expression): void;
|
|
35
|
+
/**
|
|
36
|
+
* (#1397) Emit a dynamic-dispatch method call on a wrapper-object receiver:
|
|
37
|
+
*
|
|
38
|
+
* __extern_method_call(receiver, methodName, [])
|
|
39
|
+
*
|
|
40
|
+
* Used by the wrapper-reassignment branch at the top of compileMethodCall
|
|
41
|
+
* to bypass the static fast-paths when source has reassigned the method.
|
|
42
|
+
* Returns the result type (externref) on success, null if the necessary
|
|
43
|
+
* runtime imports cannot be registered (caller falls through to the
|
|
44
|
+
* static path as a best-effort fallback).
|
|
45
|
+
*/
|
|
46
|
+
export declare function emitWrapperDynamicMethodCall(ctx: CodegenContext, fctx: FunctionContext, recvExpr: ts.Expression, methodName: string, callExpr?: ts.CallExpression): ValType | null;
|
|
47
|
+
/**
|
|
48
|
+
* Reset the __argc and __extras_argv globals to their sentinel values
|
|
49
|
+
* (-1 / null). Used after closure / indirect call paths where we set the
|
|
50
|
+
* globals unconditionally but can't be sure the callee consumed them
|
|
51
|
+
* (its prologue only consumes when the body reads `arguments`). Without
|
|
52
|
+
* cleanup, a subsequent function that does read `arguments` would
|
|
53
|
+
* inherit a stale extras_argv and produce a wrong arguments.length.
|
|
54
|
+
* (#1511)
|
|
55
|
+
*/
|
|
56
|
+
export declare function emitResetArgcExtras(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
57
|
+
/**
|
|
58
|
+
* For indirect (closure / call_ref) call paths where the callee is not
|
|
59
|
+
* statically known, set `__argc` and (if there are overflow args) build
|
|
60
|
+
* `__extras_argv` from the call-site args beyond `paramCount`. The
|
|
61
|
+
* lifted callee's prologue reads these to compute `arguments.length`
|
|
62
|
+
* correctly even when more args were passed than the lifted function's
|
|
63
|
+
* formal signature accepts.
|
|
64
|
+
*
|
|
65
|
+
* Must be called AFTER the formal args have been compiled / pushed onto
|
|
66
|
+
* the stack (or saved to locals), but BEFORE the call_ref. Pair with
|
|
67
|
+
* `emitResetArgcExtras` after the call to prevent stale-extras leaking
|
|
68
|
+
* into a subsequent callee that DOES read `arguments`. (#1511)
|
|
69
|
+
*/
|
|
70
|
+
export declare function emitClosureCallArgcExtras(ctx: CodegenContext, fctx: FunctionContext, args: readonly ts.Expression[], paramCount: number): void;
|
|
71
|
+
declare function compileCallExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, expectedType?: ValType): InnerResult;
|
|
72
|
+
/**
|
|
73
|
+
* Compile an IIFE (Immediately Invoked Function Expression):
|
|
74
|
+
* (function(params) { body })(args)
|
|
75
|
+
*
|
|
76
|
+
* Strategy: compile the function expression as a named module-level function
|
|
77
|
+
* with a unique synthetic name, then emit a direct call to it.
|
|
78
|
+
* Captures from the enclosing scope are passed as extra leading parameters.
|
|
79
|
+
*
|
|
80
|
+
* Returns undefined if the expression is not an IIFE pattern.
|
|
81
|
+
*/
|
|
82
|
+
declare function compileIIFE(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
83
|
+
export { compileCallExpression, compileIIFE, compileOptionalCallExpression };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
import { InnerResult } from '../shared.js';
|
|
4
|
+
/**
|
|
5
|
+
* Recursively resolve a compile-time-constant string from an expression.
|
|
6
|
+
* Returns the string value, or null if the expression is not a constant.
|
|
7
|
+
*/
|
|
8
|
+
export declare function resolveConstantString(expr: ts.Expression): string | null;
|
|
9
|
+
/**
|
|
10
|
+
* Try to inline `eval("<constant>")` at compile time.
|
|
11
|
+
*
|
|
12
|
+
* Returns:
|
|
13
|
+
* - InnerResult (ValType or null) on success — caller treats this as the
|
|
14
|
+
* compiled call result and does NOT invoke the dynamic-eval fallback.
|
|
15
|
+
* - undefined if the call is not eligible (non-literal arg, parse errors,
|
|
16
|
+
* etc.) — caller should fall through to the dynamic-eval path.
|
|
17
|
+
*
|
|
18
|
+
* On success we always push a single externref value onto the stack (the
|
|
19
|
+
* result of the inlined script, coerced to externref to match eval's `any`
|
|
20
|
+
* return type). When the inlined code is statically unreachable (the last
|
|
21
|
+
* statement is a throw, etc.) we return `null` so the caller knows no value
|
|
22
|
+
* was produced.
|
|
23
|
+
*/
|
|
24
|
+
export declare function tryStaticEvalInline(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression): InnerResult | undefined;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { Instr, ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, ExternClassInfo, FunctionContext, RestParamInfo } from '../context/types.js';
|
|
4
|
+
import { InnerResult } from '../shared.js';
|
|
5
|
+
export declare function findExternInfoForMember(ctx: CodegenContext, className: string, memberName: string, kind: "method" | "property"): ExternClassInfo | null;
|
|
6
|
+
declare function compileExternMethodCall(ctx: CodegenContext, fctx: FunctionContext, propAccess: ts.PropertyAccessExpression, callExpr: ts.CallExpression): InnerResult | undefined;
|
|
7
|
+
/**
|
|
8
|
+
* Emit a lazy-initialized prototype global access.
|
|
9
|
+
* On first access, creates a struct instance with default values and stores it
|
|
10
|
+
* as externref in the global. Subsequent accesses return the same instance.
|
|
11
|
+
* This gives reference identity for ClassName.prototype === Object.getPrototypeOf(instance).
|
|
12
|
+
*/
|
|
13
|
+
export declare function emitLazyProtoGet(ctx: CodegenContext, fctx: FunctionContext, className: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* (#1395) Emit a lazy-initialized class-object global access. Mirrors
|
|
16
|
+
* `emitLazyProtoGet` above but for the class identifier itself (not its
|
|
17
|
+
* prototype). On first access, creates a `$ClassName` struct with default
|
|
18
|
+
* field values and registers static method names with the runtime's
|
|
19
|
+
* `_staticMethodNames` allowlist via `__register_class_object`. Subsequent
|
|
20
|
+
* accesses return the same instance, giving reference identity for
|
|
21
|
+
* `C === C`.
|
|
22
|
+
*
|
|
23
|
+
* Returns `true` if a class-object global was emitted, `false` if no global
|
|
24
|
+
* was registered for this class (e.g. externref-backed builtin subclasses
|
|
25
|
+
* from #1366a).
|
|
26
|
+
*/
|
|
27
|
+
export declare function emitLazyClassObjectGet(ctx: CodegenContext, fctx: FunctionContext, className: string): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* After dynamically adding a field to a struct type, patch all existing
|
|
30
|
+
* struct.new instructions in compiled function bodies so they push a default
|
|
31
|
+
* value for the new field. Without this, struct.new expects N values on the
|
|
32
|
+
* stack but the constructor only pushed N-1.
|
|
33
|
+
*/
|
|
34
|
+
declare function patchStructNewForDynamicField(ctx: CodegenContext, structTypeIdx: number, newFieldType: ValType): void;
|
|
35
|
+
/** Recursively patch struct.new instructions in a body (handles nested if/block/loop). */
|
|
36
|
+
declare function patchStructNewInBody(body: Instr[], structTypeIdx: number, newFieldType: ValType): void;
|
|
37
|
+
/** Return instructions that produce a default value for a given type. */
|
|
38
|
+
declare function defaultValueInstrForType(type: ValType): Instr[];
|
|
39
|
+
/**
|
|
40
|
+
* Emit a null-guarded struct.get: if the object ref on the stack is null (e.g.
|
|
41
|
+
* from a failed ref.cast that returned ref.null), produce a default value
|
|
42
|
+
* instead of trapping. This handles wrong-type-but-not-truly-null cases. If the
|
|
43
|
+
* source value is truly null/undefined, the TypeError is thrown on the
|
|
44
|
+
* externref __extern_get path instead.
|
|
45
|
+
* push a default value instead of trapping.
|
|
46
|
+
*
|
|
47
|
+
* Expects the object ref to be on the Wasm stack. Emits:
|
|
48
|
+
* local.tee $tmp
|
|
49
|
+
* ref.is_null
|
|
50
|
+
* if (result fieldType)
|
|
51
|
+
* <default_value>
|
|
52
|
+
* else
|
|
53
|
+
* local.get $tmp
|
|
54
|
+
* struct.get typeIdx fieldIdx
|
|
55
|
+
* end
|
|
56
|
+
*
|
|
57
|
+
* Returns the field's ValType.
|
|
58
|
+
*/
|
|
59
|
+
/**
|
|
60
|
+
* Emit instructions that throw a TypeError via the Wasm exception tag.
|
|
61
|
+
* Pushes a null externref as the exception payload and then emits `throw`.
|
|
62
|
+
* This is used for null/undefined property access, calling non-functions, etc.
|
|
63
|
+
*
|
|
64
|
+
* Returns an array of instructions (for use inside if-then blocks).
|
|
65
|
+
*/
|
|
66
|
+
declare function compileSpreadCallArgs(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, funcIdx: number, restInfo: RestParamInfo | undefined): void;
|
|
67
|
+
export { compileExternMethodCall, compileSpreadCallArgs, defaultValueInstrForType, patchStructNewForDynamicField, patchStructNewInBody, };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Resolve a property-access/assignment receiver to a user-fnctor key (the
|
|
6
|
+
* resolved symbol name), or `undefined` when it is not a user function
|
|
7
|
+
* constructor. Mirrors the recognition `analyzeFnctorEscapeGate` /
|
|
8
|
+
* `compileNewFunctionDeclaration` use, so the read/write key agrees with the
|
|
9
|
+
* `new F()` lowering. Classes, builtins, arrows, and non-identifier receivers
|
|
10
|
+
* return `undefined`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveUserFnctorName(ctx: CodegenContext, expr: ts.Expression): string | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* True when `target` is a `F.prototype = …` (whole reassign) or `F.prototype.p =
|
|
15
|
+
* …` (per-prop) assignment LHS for a user function constructor `F`. Used by the
|
|
16
|
+
* module-init collection (declarations.ts) to KEEP such a top-level statement in
|
|
17
|
+
* `__module_init`: its root identifier `F` is a function (not a module global),
|
|
18
|
+
* so the generic "assignment to a module global" check drops it, and the write
|
|
19
|
+
* never reaches `compilePropertyAssignment`/the S2 interception. Mirrors the
|
|
20
|
+
* `Array.prototype` CPR keep-in-init case. Element-access (`F.prototype[i]=v`) is
|
|
21
|
+
* not matched (the S2 cluster uses whole-literal / named-prop writes).
|
|
22
|
+
*/
|
|
23
|
+
export declare function isFnctorPrototypeAssignTarget(ctx: CodegenContext, target: ts.Expression): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Emit the lazy-initialized prototype `$Object` get: `if (g == null) g =
|
|
26
|
+
* __new_plain_object(); return g`. Leaves an externref (`$Object`) on the stack.
|
|
27
|
+
* Returns false (emitting nothing) when `__new_plain_object` is unavailable, so
|
|
28
|
+
* the caller declines and falls through to the legacy path.
|
|
29
|
+
*
|
|
30
|
+
* Exported for #2660 S3: the `new F()` reconstruct lowering (new-super.ts) seeds
|
|
31
|
+
* the instance's `$proto` from this SAME per-fnctor prototype `$Object`, so the
|
|
32
|
+
* inherited-read walk and the `F.prototype` read/write share ONE link location
|
|
33
|
+
* (`$Object.$proto`) and ONE object identity (`Object.getPrototypeOf(new F()) ===
|
|
34
|
+
* F.prototype`). The lazy-init guarantees the proto is always a real `$Object`
|
|
35
|
+
* even when `F.prototype` was never explicitly assigned.
|
|
36
|
+
*/
|
|
37
|
+
export declare function emitFnctorProtoGet(ctx: CodegenContext, fctx: FunctionContext, fnctorName: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* READ interception for `F.prototype` (F a user fnctor, standalone). Returns the
|
|
40
|
+
* per-fnctor prototype `$Object` as an externref, or `undefined` to decline (the
|
|
41
|
+
* caller continues its normal dispatch).
|
|
42
|
+
*/
|
|
43
|
+
export declare function tryEmitFnctorPrototypeRead(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression, propName: string): ValType | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* WHOLE-REASSIGN interception for `F.prototype = rhs` (F a user fnctor,
|
|
46
|
+
* standalone). Builds `rhs` as a native `$Object` (plain object literal) or an
|
|
47
|
+
* externref, stores it into the per-fnctor prototype global, and leaves the
|
|
48
|
+
* assigned value on the stack (assignment-expression semantics). Returns
|
|
49
|
+
* `undefined` to decline. Per-prop writes (`F.prototype.p = v`) are NOT handled
|
|
50
|
+
* here — they ride the READ interception above.
|
|
51
|
+
*/
|
|
52
|
+
export declare function tryCompileFnctorPrototypeAssign(ctx: CodegenContext, fctx: FunctionContext, target: ts.PropertyAccessExpression, value: ts.Expression): ValType | undefined;
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* #1473 — No-JS-host predicate. Both `--target wasi` and `--target standalone`
|
|
6
|
+
* run without a JS runtime, so neither can rely on host imports such as
|
|
7
|
+
* `__throw_type_error` / `__new_TypeError` resolving to JS constructors. In
|
|
8
|
+
* these modes the compiler emits Wasm-native Error constructors instead.
|
|
9
|
+
*/
|
|
10
|
+
export declare function noJsHost(ctx: CodegenContext): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Emit a Wasm throw instruction with a string error message.
|
|
13
|
+
* This replaces `unreachable` traps so that JS try/catch (and assert.throws)
|
|
14
|
+
* can catch the error instead of getting an uncatchable RuntimeError.
|
|
15
|
+
*/
|
|
16
|
+
export declare function emitThrowString(ctx: CodegenContext, fctx: FunctionContext, message: string): void;
|
|
17
|
+
/**
|
|
18
|
+
* #1365 — Resolve the class struct that declared a `#name` PrivateIdentifier.
|
|
19
|
+
*
|
|
20
|
+
* Per ES2022 §15.7, a private name is lexically scoped to the class body that
|
|
21
|
+
* declares it. To brand-check `obj.#x`, we need to know which class struct
|
|
22
|
+
* to test the receiver against.
|
|
23
|
+
*
|
|
24
|
+
* Strategy: walk up `node.parent` from the PrivateIdentifier to find the
|
|
25
|
+
* enclosing class declaration whose body declared `#x`. The TS parser
|
|
26
|
+
* preserves `parent` links via `setParentNodes`. If multiple nested classes
|
|
27
|
+
* each declare `#x`, the innermost wins (lexical shadowing — same as
|
|
28
|
+
* regular variable scope).
|
|
29
|
+
*
|
|
30
|
+
* Returns `undefined` when:
|
|
31
|
+
* - The PrivateIdentifier isn't lexically inside any class (parser will
|
|
32
|
+
* have already caught this as a syntax error, but defensive).
|
|
33
|
+
* - The class hasn't been registered with a struct (e.g. external class,
|
|
34
|
+
* or compilation order issue).
|
|
35
|
+
*
|
|
36
|
+
* Returns the matched class's struct typeIdx and the legacy field name
|
|
37
|
+
* (`__priv_<text>`) so the caller can emit `ref.test` / `ref.cast` /
|
|
38
|
+
* `struct.get` against the right slot.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveDeclaringClassForPrivateName(ctx: CodegenContext, node: ts.PrivateIdentifier): {
|
|
41
|
+
className: string;
|
|
42
|
+
structTypeIdx: number;
|
|
43
|
+
fieldName: string;
|
|
44
|
+
} | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Emit the runtime private-brand predicate for a receiver saved as anyref.
|
|
47
|
+
*
|
|
48
|
+
* `ref.test $DeclaringClass` alone is not a full brand check in this compiler:
|
|
49
|
+
* unrelated classes with identical private-field layout may canonicalize to the
|
|
50
|
+
* same WasmGC shape. The hidden class tag distinguishes declarations, while
|
|
51
|
+
* descendant tags remain valid for private names initialized by an ancestor.
|
|
52
|
+
*/
|
|
53
|
+
export declare function emitPrivateBrandPredicate(ctx: CodegenContext, fctx: FunctionContext, receiverLocal: number, className: string, structTypeIdx: number): void;
|
|
54
|
+
/**
|
|
55
|
+
* (#2102) Error constructors {@link emitThrowJsError} can build. Each maps to a
|
|
56
|
+
* `__new_<Kind>(message)` host import in JS-host mode and to the in-module WASI
|
|
57
|
+
* Error constructor under `--target standalone`/`wasi`. The set is the spec's
|
|
58
|
+
* runtime-check error family (the §10/§22/§23 bounds/integrity/callable checks).
|
|
59
|
+
*/
|
|
60
|
+
export type JsErrorKind = "TypeError" | "RangeError" | "ReferenceError" | "SyntaxError" | "Error";
|
|
61
|
+
/**
|
|
62
|
+
* (#2102) THE shared "throw a real JS Error instance" lowering. Runtime checks
|
|
63
|
+
* (bounds / integrity / callable / [[Set]] failures) that the spec requires to
|
|
64
|
+
* raise a catchable `TypeError`/`RangeError`/… must route through here instead
|
|
65
|
+
* of emitting an uncatchable Wasm `unreachable`/`ref.cast` trap or a bare string
|
|
66
|
+
* throw. The thrown ref is a real `<Kind>`-tagged externref (`e instanceof
|
|
67
|
+
* <Kind>` holds), produced by the same `__new_<Kind>(message)` path `new
|
|
68
|
+
* <Kind>(msg)` uses, and dispatched through the shared `$exc` tag so the user's
|
|
69
|
+
* try/catch (and test262 `assert.throws`) catches it.
|
|
70
|
+
*
|
|
71
|
+
* Dual-mode: in no-JS-host mode (`--target standalone`/`wasi`) the constructor
|
|
72
|
+
* is the in-module `emitWasiErrorConstructor` function, so no unsatisfiable
|
|
73
|
+
* `env::__new_<Kind>` host import is requested. The constructor is registered
|
|
74
|
+
* BEFORE the funcIdx is resolved so `ensureLateImport` finds the in-module
|
|
75
|
+
* function in funcMap and does NOT add an `env::__new_<Kind>` host import.
|
|
76
|
+
* (Consolidates the previously-duplicated #1365 TypeError / #1473
|
|
77
|
+
* ReferenceError / #2164 RangeError lowerings.)
|
|
78
|
+
*
|
|
79
|
+
* Leaves nothing on the value stack (the `throw` is terminal / stack-polymorphic).
|
|
80
|
+
*/
|
|
81
|
+
export declare function emitThrowJsError(ctx: CodegenContext, fctx: FunctionContext, kind: JsErrorKind, message: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* #1365 — Emit a Wasm throw of a real TypeError INSTANCE (not a bare string).
|
|
84
|
+
* Thin wrapper over {@link emitThrowJsError}; retained as the canonical call
|
|
85
|
+
* site name (many uses). Required for spec-compliant `assert.throws(TypeError,
|
|
86
|
+
* fn)` test262 cases — those check `e instanceof TypeError` on the caught value.
|
|
87
|
+
*/
|
|
88
|
+
export declare function emitThrowTypeError(ctx: CodegenContext, fctx: FunctionContext, message: string): void;
|
|
89
|
+
/**
|
|
90
|
+
* #1473 — Emit a throw of a ReferenceError INSTANCE for TDZ / unresolved
|
|
91
|
+
* identifier references. Mirrors `emitThrowTypeError`.
|
|
92
|
+
*
|
|
93
|
+
* In no-JS-host mode (`--target wasi` / `--target standalone`), the
|
|
94
|
+
* ReferenceError is built via the in-module `__new_ReferenceError` function
|
|
95
|
+
* (emitted by `emitWasiErrorConstructor`), so no `env::__new_ReferenceError`
|
|
96
|
+
* host import is required. In JS-host mode the same import name resolves to
|
|
97
|
+
* the JS `ReferenceError` constructor.
|
|
98
|
+
*
|
|
99
|
+
* Either way the throw is observable in the user's catch block via the
|
|
100
|
+
* shared `$exc` tag, and `e instanceof ReferenceError` works through the
|
|
101
|
+
* `$Error_struct` `$tag` field discrimination.
|
|
102
|
+
*/
|
|
103
|
+
export declare function emitThrowReferenceError(ctx: CodegenContext, fctx: FunctionContext, message: string): void;
|
|
104
|
+
/**
|
|
105
|
+
* #2164 — Emit a throw of a RangeError INSTANCE. Mirrors `emitThrowTypeError`.
|
|
106
|
+
* Used by `Date.prototype.toISOString` on an Invalid Date receiver
|
|
107
|
+
* (ECMA-262 §21.4.4.36 — RangeError "Invalid time value"). In no-JS-host mode
|
|
108
|
+
* the RangeError is built via the in-module `__new_RangeError` constructor; in
|
|
109
|
+
* JS-host mode the import resolves to the JS `RangeError`.
|
|
110
|
+
*/
|
|
111
|
+
export declare function emitThrowRangeError(ctx: CodegenContext, fctx: FunctionContext, message: string): void;
|
|
112
|
+
/**
|
|
113
|
+
* (#2709) Uninitialized-`this` guard for a `super[key]` SuperProperty WRITE /
|
|
114
|
+
* UPDATE (`super[key] = v`, `super[key]++`) in a *derived* constructor whose
|
|
115
|
+
* `key` itself contains a `super(...)` call — i.e. the `super[super()] = 0` /
|
|
116
|
+
* `super[super()]++` shape.
|
|
117
|
+
*
|
|
118
|
+
* Per ECMA-262 §13.3.7.1 (Evaluation of SuperProperty), reference resolution
|
|
119
|
+
* performs `GetThisBinding()` FIRST (step 2), BEFORE the key Expression (step 3)
|
|
120
|
+
* and the RHS. In a derived class `this` is *uninitialized* until `super(...)`
|
|
121
|
+
* returns, so `GetThisBinding()` throws a `ReferenceError`. For the
|
|
122
|
+
* `super[super()]` shape this is provably the outcome in EVERY execution:
|
|
123
|
+
* - if `super()` has not yet run, `this` is uninitialized → GetThisBinding
|
|
124
|
+
* throws ReferenceError before the key is evaluated;
|
|
125
|
+
* - if `super()` HAS already run, the key's inner `super()` is a second
|
|
126
|
+
* SuperCall → "Super constructor may only be called once" ReferenceError.
|
|
127
|
+
* Either way the statement throws a ReferenceError and never completes, so
|
|
128
|
+
* emitting an unconditional ReferenceError here is spec-correct. The shape
|
|
129
|
+
* `super[super()] = …` never appears in valid programs, so this is ZERO
|
|
130
|
+
* regression risk (no currently-passing path reaches it).
|
|
131
|
+
*
|
|
132
|
+
* Call at the TOP of the super-element write / update path, before any key/RHS
|
|
133
|
+
* is emitted. Returns `true` when it emitted the throw (the caller should stop —
|
|
134
|
+
* the inner `super()` and RHS must NOT be evaluated). Returns `false` (a no-op)
|
|
135
|
+
* for every other shape, leaving existing behavior byte-identical.
|
|
136
|
+
*/
|
|
137
|
+
export declare function emitSuperUninitializedThisGuard(ctx: CodegenContext, fctx: FunctionContext, keyExpr: ts.Expression | undefined): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* #1456 — Classify a private property reference for assignment/compound-assignment.
|
|
140
|
+
*
|
|
141
|
+
* Per ES2022 §7.3.18 (PrivateElementSet) and §13.15.2
|
|
142
|
+
* (AssignmentExpression : LHS op= AssignmentExpression):
|
|
143
|
+
*
|
|
144
|
+
* - Private *methods* throw TypeError on any write (`=`, `+=`, …).
|
|
145
|
+
* - Private *accessor* with no setter throws TypeError on write.
|
|
146
|
+
* - Private *accessor* with no getter throws TypeError on read (matters
|
|
147
|
+
* for compound: the read step happens first).
|
|
148
|
+
* - Plain private fields read/write through the brand slot as usual.
|
|
149
|
+
*
|
|
150
|
+
* We classify the LHS at compile time by looking up the brand-table proxies
|
|
151
|
+
* we've already populated when the class was registered:
|
|
152
|
+
* - `ctx.classMethodSet` — `<Class>_<__priv_name>` for private methods
|
|
153
|
+
* (both static and instance share the same `__priv_X` name space; that's
|
|
154
|
+
* consistent with how `resolveClassMemberName` mangles them).
|
|
155
|
+
* - `ctx.classAccessorSet` — `<Class>_<__priv_name>` for accessors;
|
|
156
|
+
* existence of `<Class>_get_<__priv_name>` / `<Class>_set_<__priv_name>`
|
|
157
|
+
* in `ctx.funcMap` distinguishes getter-only / setter-only / pair.
|
|
158
|
+
*
|
|
159
|
+
* Returns `undefined` if the receiver class cannot be resolved (defensive —
|
|
160
|
+
* the caller falls back to existing behavior).
|
|
161
|
+
*/
|
|
162
|
+
export type PrivateMemberKind = "method" | "accessor-readonly" | "accessor-writeonly" | "accessor" | "field";
|
|
163
|
+
export declare function classifyPrivateMember(ctx: CodegenContext, name: ts.PrivateIdentifier): {
|
|
164
|
+
className: string;
|
|
165
|
+
fieldName: string;
|
|
166
|
+
kind: PrivateMemberKind;
|
|
167
|
+
} | undefined;
|
|
168
|
+
/**
|
|
169
|
+
* Check if a TS return type is effectively void for Wasm purposes.
|
|
170
|
+
* For async functions, the TS checker reports `Promise<void>` which is not
|
|
171
|
+
* caught by `isVoidType`. This helper unwraps Promise types for async
|
|
172
|
+
* functions before checking.
|
|
173
|
+
*
|
|
174
|
+
* Use this instead of bare `isVoidType(retType)` at all call-return-type
|
|
175
|
+
* resolution points to prevent emitting `drop` on an empty stack.
|
|
176
|
+
*/
|
|
177
|
+
export declare function isEffectivelyVoidReturn(ctx: CodegenContext, retType: ts.Type, funcName?: string): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Get parameter types of a Wasm function by its index.
|
|
180
|
+
* Handles both imported functions (index < numImportFuncs) and local functions.
|
|
181
|
+
*/
|
|
182
|
+
export declare function getFuncParamTypes(ctx: CodegenContext, funcIdx: number): ValType[] | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* Check if a Wasm function (by index) has a void return type by inspecting
|
|
185
|
+
* the actual function type in the module. This is the ground truth for whether
|
|
186
|
+
* a `call` instruction pushes a value onto the stack.
|
|
187
|
+
*/
|
|
188
|
+
export declare function wasmFuncReturnsVoid(ctx: CodegenContext, funcIdx: number): boolean;
|
|
189
|
+
/** Check whether a function *type* (by type index) has zero results. */
|
|
190
|
+
export declare function wasmFuncTypeReturnsVoid(ctx: CodegenContext, typeIdx: number): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Get the actual Wasm return type of a function by inspecting its type definition.
|
|
193
|
+
* Returns undefined if the function has void return or is not found.
|
|
194
|
+
* Use this instead of resolveWasmType(retType) at call sites to avoid mismatches
|
|
195
|
+
* when TS type says 'any' (→ externref) but the Wasm function returns f64/i32.
|
|
196
|
+
*/
|
|
197
|
+
export declare function getWasmFuncReturnType(ctx: CodegenContext, funcIdx: number): ValType | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* Update a local's declared type to a new type.
|
|
200
|
+
* Used when a variable is reassigned to a value of a different struct type.
|
|
201
|
+
*/
|
|
202
|
+
export declare function updateLocalType(fctx: FunctionContext, localIdx: number, newType: ValType): void;
|
|
203
|
+
/**
|
|
204
|
+
* Widen a local's declared type from ref $X to ref_null $X.
|
|
205
|
+
*/
|
|
206
|
+
export declare function widenLocalToNullable(fctx: FunctionContext, localIdx: number): void;
|
|
207
|
+
/**
|
|
208
|
+
* Emit a local.set with automatic type coercion.
|
|
209
|
+
* If the value on the stack (stackType) doesn't match the local's declared type,
|
|
210
|
+
* inserts coercion instructions before the local.set.
|
|
211
|
+
*/
|
|
212
|
+
export declare function emitCoercedLocalSet(ctx: CodegenContext, fctx: FunctionContext, localIdx: number, stackType: ValType): void;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
export declare function emitLocalTdzCheck(ctx: CodegenContext, fctx: FunctionContext, name: string, flagIdx: number): void;
|
|
5
|
+
/**
|
|
6
|
+
* Compile-time TDZ elision for top-level let/const variables (#906).
|
|
7
|
+
*
|
|
8
|
+
* Returns the subset of `candidates` for which TDZ tracking can be statically
|
|
9
|
+
* compiled away — i.e. every identifier reference in the source file that
|
|
10
|
+
* resolves to the candidate's declaration is provably after initialization
|
|
11
|
+
* (analyzeTdzAccess returns "skip"). For these names, the caller can skip
|
|
12
|
+
* emitting the `__tdz_<name>` global, the `global.set __tdz_<name>` writes
|
|
13
|
+
* in the module init body, and the runtime check at every read.
|
|
14
|
+
*
|
|
15
|
+
* If a candidate has *any* reference that yields "throw" or "check", it stays
|
|
16
|
+
* tracked at runtime. This preserves observable semantics for genuinely
|
|
17
|
+
* dynamic or ambiguous cases (e.g. a function declaration that reads the
|
|
18
|
+
* variable, since hoisted functions could be called before the variable's
|
|
19
|
+
* initializer runs).
|
|
20
|
+
*/
|
|
21
|
+
export declare function computeElidableTopLevelTdzNames(ctx: CodegenContext, sourceFile: ts.SourceFile, candidates: Set<string>): Set<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Position-based TDZ analysis for call-site capture checks.
|
|
24
|
+
* Used when we know the variable name and the call expression position,
|
|
25
|
+
* but don't have an identifier with a resolved symbol (e.g., pushing
|
|
26
|
+
* closure captures at a nested function call site).
|
|
27
|
+
*/
|
|
28
|
+
declare function analyzeTdzAccessByPos(ctx: CodegenContext, varName: string, callNode: ts.Node): "skip" | "throw" | "check";
|
|
29
|
+
/** Emit a static TDZ throw (guaranteed violation — no flag check needed). */
|
|
30
|
+
export declare function emitStaticTdzThrow(ctx: CodegenContext, fctx: FunctionContext, name: string): void;
|
|
31
|
+
declare function compileIdentifier(ctx: CodegenContext, fctx: FunctionContext, id: ts.Identifier): ValType | null;
|
|
32
|
+
/**
|
|
33
|
+
* If the narrowed TS type indicates a concrete primitive, emit an unbox call
|
|
34
|
+
* and return the unboxed ValType. The externref value must already be on stack.
|
|
35
|
+
* Returns null if no unboxing is needed (type is still a union or externref).
|
|
36
|
+
*/
|
|
37
|
+
declare function narrowTypeToUnbox(ctx: CodegenContext, fctx: FunctionContext, narrowedType: ts.Type): ValType | null;
|
|
38
|
+
/**
|
|
39
|
+
* Try to resolve the right-hand side of an instanceof expression to a known
|
|
40
|
+
* class in our struct system. Returns the class name if found, undefined otherwise.
|
|
41
|
+
* This mirrors resolveInstanceOfClassName in typeof-delete.ts but is used to
|
|
42
|
+
* decide whether to use the host fallback.
|
|
43
|
+
*/
|
|
44
|
+
declare function resolveInstanceOfRHS(ctx: CodegenContext, rightExpr: ts.Expression): string | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Compile `expr instanceof RHS` using a host import when the RHS class is not
|
|
47
|
+
* in our struct system (e.g., TypeError, Array, Function, Promise). (#738)
|
|
48
|
+
* Passes the value as externref and the constructor name as a string constant,
|
|
49
|
+
* delegating to `__instanceof(value, ctorName) -> i32` host import which
|
|
50
|
+
* looks up the constructor on the global object.
|
|
51
|
+
*
|
|
52
|
+
* For built-in RHS (Array, Error, *Error, Map, ...), tries `tryStaticInstanceOf`
|
|
53
|
+
* first to short-circuit when the LHS TS type makes the answer compile-time
|
|
54
|
+
* obvious — important for standalone/WASI mode (#1325).
|
|
55
|
+
*/
|
|
56
|
+
declare function compileHostInstanceOf(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType;
|
|
57
|
+
export { analyzeTdzAccessByPos, compileHostInstanceOf, compileIdentifier, narrowTypeToUnbox, resolveInstanceOfRHS };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ValType } from '../../ir/types.js';
|
|
2
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Shift function indices after a late import addition. This must update all
|
|
5
|
+
* already-compiled function bodies, the current function body, any saved bodies
|
|
6
|
+
* from the savedBody swap pattern, and export descriptors.
|
|
7
|
+
*/
|
|
8
|
+
export declare function shiftLateImportIndices(ctx: CodegenContext, fctx: FunctionContext | null, importsBefore: number, added: number): void;
|
|
9
|
+
/**
|
|
10
|
+
* Add a late import if it does not already exist, deferring the index shift.
|
|
11
|
+
* Records ctx.pendingLateImportShift.importsBefore on the first deferred addition
|
|
12
|
+
* so that flushLateImportShifts() can do a single O(B) traversal for all imports
|
|
13
|
+
* added in the batch, instead of O(I*B) for I individual additions.
|
|
14
|
+
* Returns the funcIdx of the import (looked up after addImport).
|
|
15
|
+
*/
|
|
16
|
+
export declare function ensureLateImport(ctx: CodegenContext, name: string, paramTypes: ValType[], resultTypes: ValType[]): number | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* #1677: reconcile native-string helper function indices at the end of the
|
|
19
|
+
* import-collection finalize phase.
|
|
20
|
+
*
|
|
21
|
+
* The native-string runtime helpers (`__str_flatten` & co.) are emitted as
|
|
22
|
+
* DEFINED functions *mid-finalize* (the first `ensureNativeStringHelpers`
|
|
23
|
+
* call), recording `ctx.nativeStrHelperImportBase` = the import count at that
|
|
24
|
+
* instant. Finalize then continues and adds more imports via raw `addImport`
|
|
25
|
+
* (string methods, parseInt, Promise statics, iterator/generator bridges, …).
|
|
26
|
+
* Raw `addImport` does NOT shift defined-function indices (the #618 revert
|
|
27
|
+
* deliberately removed that), so every helper body's internal `call` to a
|
|
28
|
+
* sibling helper — and every `nativeStrHelpers` map entry — is now stale-low by
|
|
29
|
+
* exactly `(numImportFuncs - base)`.
|
|
30
|
+
*
|
|
31
|
+
* This reconciliation runs once, after finalize is otherwise complete, and
|
|
32
|
+
* applies that single uniform delta via the same `shiftLateImportIndices`
|
|
33
|
+
* walker the compilation-phase late-import path uses — unifying the two shift
|
|
34
|
+
* regimes (#1666 root cause). It is a no-op unless native-string helpers were
|
|
35
|
+
* emitted, so the default GC path is never touched; and because it shifts
|
|
36
|
+
* `funcIdx >= base` (sibling-helper calls) but not `funcIdx < base` (calls to
|
|
37
|
+
* imports added before the helpers), it cannot corrupt the Math.* host
|
|
38
|
+
* trampoline path that the #618 naive `addImport` shift broke.
|
|
39
|
+
*/
|
|
40
|
+
export declare function reconcileNativeStrFinalizeShift(ctx: CodegenContext): void;
|
|
41
|
+
/**
|
|
42
|
+
* Flush any pending late import shifts. Performs a single traversal of all
|
|
43
|
+
* function bodies to shift indices, instead of one traversal per import.
|
|
44
|
+
* Must be called after a batch of ensureLateImport() calls before any
|
|
45
|
+
* funcIdx values are used in emitted instructions.
|
|
46
|
+
*/
|
|
47
|
+
export declare function flushLateImportShifts(ctx: CodegenContext, fctx: FunctionContext | null): void;
|
|
48
|
+
/**
|
|
49
|
+
* Ensure the __get_undefined host import exists, returning its funcIdx.
|
|
50
|
+
* This import returns the actual JS `undefined` value as externref,
|
|
51
|
+
* allowing Wasm to distinguish null from undefined at runtime.
|
|
52
|
+
*
|
|
53
|
+
* Under native-strings mode (auto-on for `--target standalone`/`wasi`) there is
|
|
54
|
+
* no JS host to satisfy this import, and undefined is conflated with null (same
|
|
55
|
+
* convention as `__extern_is_undefined` → bare `ref.is_null`). Returning
|
|
56
|
+
* `undefined` here makes callers fall back to the native `ref.null.extern`
|
|
57
|
+
* sentinel via `emitUndefined`, which (a) keeps standalone host-import-free and
|
|
58
|
+
* (b) avoids adding a late import *after* the native-string helpers were emitted
|
|
59
|
+
* — that post-helper import otherwise drives `reconcileNativeStrFinalizeShift`
|
|
60
|
+
* an extra time and off-by-ones the baked `__str_flatten`→`__str_copy_tree`
|
|
61
|
+
* call (#329: `let g: any; g = function(){…}; g()` invalid wasm).
|
|
62
|
+
*/
|
|
63
|
+
export declare function ensureGetUndefined(ctx: CodegenContext): number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Emit instructions that push the JS `undefined` value onto the stack.
|
|
66
|
+
* Uses the __get_undefined host import when available; falls back to
|
|
67
|
+
* ref.null.extern (indistinguishable from null) in standalone mode.
|
|
68
|
+
*/
|
|
69
|
+
export declare function emitUndefined(ctx: CodegenContext, fctx: FunctionContext): void;
|
|
70
|
+
/**
|
|
71
|
+
* Ensure the __extern_is_undefined host import exists, returning its funcIdx.
|
|
72
|
+
* This import checks if an externref value is JS `undefined` (not null).
|
|
73
|
+
*/
|
|
74
|
+
export declare function ensureExternIsUndefinedImport(ctx: CodegenContext): number | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* After dynamically adding a field to a struct type, patch all existing
|
|
77
|
+
* struct.new instructions for that type by inserting a default value
|
|
78
|
+
* instruction immediately before each struct.new. This ensures the
|
|
79
|
+
* operand count matches the (now larger) field list.
|
|
80
|
+
*/
|
|
81
|
+
export declare function patchStructNewForAddedField(ctx: CodegenContext, fctx: FunctionContext, typeIdx: number, fieldType: ValType): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
export declare function compileLogicalAnd(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType;
|
|
5
|
+
export declare function compileLogicalOr(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType;
|
|
6
|
+
export declare function compileNullishCoalescing(ctx: CodegenContext, fctx: FunctionContext, expr: ts.BinaryExpression): ValType;
|
|
7
|
+
/**
|
|
8
|
+
* Emit code to sync a parameter local's value into the mapped arguments array (#849).
|
|
9
|
+
* Called after local.tee for parameter assignments in functions with mapped arguments.
|
|
10
|
+
* The expression result is on the stack; we save it, do the sync, then restore it.
|
|
11
|
+
*/
|
|
12
|
+
declare function emitMappedArgParamSync(ctx: CodegenContext, fctx: FunctionContext, paramIdx: number, resultType: ValType): void;
|
|
13
|
+
/**
|
|
14
|
+
* Emit code to sync an arguments element write back to the parameter local (#849).
|
|
15
|
+
* Called after array.set in compileElementAssignment when target is the arguments object.
|
|
16
|
+
*/
|
|
17
|
+
declare function emitMappedArgReverseSync(ctx: CodegenContext, fctx: FunctionContext, idxLocal: number, valLocal: number): void;
|
|
18
|
+
export { emitMappedArgParamSync, emitMappedArgReverseSync };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { ValType } from '../../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from '../context/types.js';
|
|
4
|
+
import { getIteratorResultValueType, isGeneratorIteratorResultLike, resolveStructName, resolveStructNameForExpr } from '../property-access.js';
|
|
5
|
+
import { InnerResult } from '../shared.js';
|
|
6
|
+
export { getIteratorResultValueType, isGeneratorIteratorResultLike, resolveStructName, resolveStructNameForExpr };
|
|
7
|
+
declare function compileConditionalExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.ConditionalExpression): ValType | null;
|
|
8
|
+
/**
|
|
9
|
+
* Optional property access: obj?.prop
|
|
10
|
+
* Compiles obj, checks if null → returns null, else accesses property normally.
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Compile a `yield expr` expression inside a generator function.
|
|
14
|
+
* Pushes the yielded value into the __gen_buffer (a JS array managed by the host).
|
|
15
|
+
* The yield expression itself evaluates to void (we don't support receiving
|
|
16
|
+
* values via yield in this initial implementation).
|
|
17
|
+
*/
|
|
18
|
+
declare function compileYieldExpression(ctx: CodegenContext, fctx: FunctionContext, expr: ts.YieldExpression): InnerResult;
|
|
19
|
+
/** Check if an expression is statically known to be NaN at compile time */
|
|
20
|
+
/**
|
|
21
|
+
* Try to statically determine the numeric value of an expression.
|
|
22
|
+
* Handles: numeric literals, NaN, Infinity, -Infinity, object-with-valueOf, {}.
|
|
23
|
+
* Returns undefined if the value cannot be determined at compile time.
|
|
24
|
+
*/
|
|
25
|
+
export declare function tryStaticToNumber(ctx: CodegenContext, expr: ts.Expression, visitedDecls?: Set<ts.Node>): number | undefined;
|
|
26
|
+
declare function isStaticNaN(ctx: CodegenContext, expr: ts.Expression): boolean;
|
|
27
|
+
export { compileConditionalExpression, compileYieldExpression, isStaticNaN };
|