@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,161 @@
|
|
|
1
|
+
import { WasmModule } from '../ir/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Options for the linear-memory bump/arena allocator (#1856).
|
|
4
|
+
*
|
|
5
|
+
* The linear backend owns allocation. Its allocator is a **bump/arena**:
|
|
6
|
+
* each `__malloc` advances a single heap pointer and **nothing is ever
|
|
7
|
+
* freed** — reclamation happens implicitly when the Wasm instance is
|
|
8
|
+
* dropped (process exit, for standalone/WASI CLI-style programs). This is
|
|
9
|
+
* the smallest-binary, fastest path and is exactly the "allocate-and-exit"
|
|
10
|
+
* mode recommended in R10 of `docs/architecture/compiler-design-lessons.md`.
|
|
11
|
+
*
|
|
12
|
+
* There is intentionally **no pluggable GC abstraction** (see ADR-0017):
|
|
13
|
+
* supporting tracing and reference-counting as swappable strategies is a
|
|
14
|
+
* documented trap. When reclamation is genuinely needed it will be a single
|
|
15
|
+
* fixed strategy added later; the bump arena is the default and only mode
|
|
16
|
+
* today.
|
|
17
|
+
*/
|
|
18
|
+
export interface ArenaOptions {
|
|
19
|
+
/**
|
|
20
|
+
* Emit the explicit arena-management exports `__arena_reset` and
|
|
21
|
+
* `__arena_used` (#1856). A host/embedder that reuses one instance across
|
|
22
|
+
* many short-lived tasks can call `__arena_reset()` to reclaim the whole
|
|
23
|
+
* arena in O(1) between tasks (it rewinds the bump pointer to
|
|
24
|
+
* `HEAP_START`). Off by default — most programs allocate and exit, so the
|
|
25
|
+
* exports are dead weight and are omitted to keep the binary minimal.
|
|
26
|
+
*/
|
|
27
|
+
exposeArenaReset?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Add linear-memory runtime functions to the module.
|
|
31
|
+
* - memory starts at 1 page (64 KiB) and grows on demand up to 256 pages
|
|
32
|
+
* - `__heap_ptr` global (mutable i32, starts at `HEAP_START`)
|
|
33
|
+
* - `__malloc(size: i32) → i32`: bump allocator, 8-byte aligned, grows
|
|
34
|
+
* memory automatically when the request would overflow the current pages
|
|
35
|
+
* (#1856 — previously it silently advanced the pointer past the addressable
|
|
36
|
+
* region, corrupting memory for programs larger than one page)
|
|
37
|
+
* - optionally (`exposeArenaReset`) `__arena_reset()` / `__arena_used() → i32`
|
|
38
|
+
*
|
|
39
|
+
* This is the bump/arena "allocate-and-never-free" allocator — the single
|
|
40
|
+
* fixed strategy for the linear backend. See {@link ArenaOptions} and
|
|
41
|
+
* ADR-0017.
|
|
42
|
+
*/
|
|
43
|
+
export declare function addRuntime(mod: WasmModule, opts?: ArenaOptions): void;
|
|
44
|
+
/**
|
|
45
|
+
* Add Uint8Array runtime functions to the module.
|
|
46
|
+
* Layout: [header 8B][len:u32 at +8][bytes at +12...]
|
|
47
|
+
*
|
|
48
|
+
* Functions added:
|
|
49
|
+
* - __u8arr_new(len: i32) → i32 (pointer)
|
|
50
|
+
* - __u8arr_get(ptr: i32, idx: i32) → i32
|
|
51
|
+
* - __u8arr_set(ptr: i32, idx: i32, val: i32) → void
|
|
52
|
+
* - __u8arr_len(ptr: i32) → i32
|
|
53
|
+
*/
|
|
54
|
+
export declare function addUint8ArrayRuntime(mod: WasmModule): void;
|
|
55
|
+
/**
|
|
56
|
+
* Add Array runtime functions to the module.
|
|
57
|
+
* Layout: [header 8B][len:u32 at +8][cap:u32 at +12][elements: 8B×cap at +16...]
|
|
58
|
+
*
|
|
59
|
+
* #1938: element slots are 8 bytes (stride 8), holding a raw bit pattern the
|
|
60
|
+
* runtime never interprets. The runtime element boundary is typed **f64**:
|
|
61
|
+
* a numeric element flows in/out as its IEEE-754 f64 value (zero conversions),
|
|
62
|
+
* while a reference/boolean i32 is shuffled into the low 4 bytes of the slot by
|
|
63
|
+
* codegen (`i64.extend_i32_u` → `f64.reinterpret_i64` on store, inverse on
|
|
64
|
+
* load). Storing f64 slots fixes `[1.5][0]` → 1.5 (was truncated to i32).
|
|
65
|
+
*
|
|
66
|
+
* Functions added:
|
|
67
|
+
* - __arr_new(cap: i32) → i32 (pointer)
|
|
68
|
+
* - __arr_grow(ptr: i32, minCap: i32) → i32 (relocated pointer; forwards old header)
|
|
69
|
+
* - __arr_push(ptr: i32, val: f64) → void
|
|
70
|
+
* - __arr_get(ptr: i32, idx: i32) → f64
|
|
71
|
+
* - __arr_set(ptr: i32, idx: i32, val: f64) → void
|
|
72
|
+
* - __arr_len(ptr: i32) → i32
|
|
73
|
+
* - __arr_from_data(dataPtr: i32, len: i32) → i32 (header ptr)
|
|
74
|
+
*/
|
|
75
|
+
export declare function addArrayRuntime(mod: WasmModule): void;
|
|
76
|
+
/**
|
|
77
|
+
* Add String runtime functions to the module.
|
|
78
|
+
* Layout: [header 8B][len:u32 at +8][utf8 bytes at +12...]
|
|
79
|
+
*
|
|
80
|
+
* Functions added:
|
|
81
|
+
* - __str_from_data(offset: i32, len: i32) → i32 (pointer)
|
|
82
|
+
* - __str_eq(a: i32, b: i32) → i32 (boolean)
|
|
83
|
+
* - __str_hash(ptr: i32) → i32 (FNV-1a hash)
|
|
84
|
+
* - __str_len(ptr: i32) → i32
|
|
85
|
+
* - __str_concat(a: i32, b: i32) → i32 (new string pointer)
|
|
86
|
+
*/
|
|
87
|
+
export declare function addStringRuntime(mod: WasmModule): void;
|
|
88
|
+
/**
|
|
89
|
+
* Add Map runtime functions (open-addressing hash table with string keys).
|
|
90
|
+
* Layout: [header 8B][count:u32 at +8][cap:u32 at +12][entries at +16...]
|
|
91
|
+
* Entry: [hash:u32][key:i32][val:i32] = 12 bytes each
|
|
92
|
+
* Empty entry: hash=0
|
|
93
|
+
*
|
|
94
|
+
* Functions added:
|
|
95
|
+
* - __map_new(cap: i32) → i32
|
|
96
|
+
* - __map_set(map: i32, key: i32, val: i32) → void
|
|
97
|
+
* - __map_get(map: i32, key: i32) → i32
|
|
98
|
+
* - __map_has(map: i32, key: i32) → i32
|
|
99
|
+
* - __map_size(map: i32) → i32
|
|
100
|
+
*/
|
|
101
|
+
export declare function addMapRuntime(mod: WasmModule): void;
|
|
102
|
+
/**
|
|
103
|
+
* Add Set runtime functions (open-addressing hash set with string keys).
|
|
104
|
+
* Layout: [header 8B][count:u32 at +8][cap:u32 at +12][entries at +16...]
|
|
105
|
+
* Entry: [hash:u32][key:i32] = 8 bytes each
|
|
106
|
+
*
|
|
107
|
+
* Functions added:
|
|
108
|
+
* - __set_new(cap: i32) → i32
|
|
109
|
+
* - __set_add(set: i32, key: i32) → void
|
|
110
|
+
* - __set_has(set: i32, key: i32) → i32
|
|
111
|
+
* - __set_size(set: i32) → i32
|
|
112
|
+
*/
|
|
113
|
+
export declare function addSetRuntime(mod: WasmModule): void;
|
|
114
|
+
/**
|
|
115
|
+
* Add numeric-key Map runtime functions (open-addressing hash table with i32 keys).
|
|
116
|
+
* Layout: [header 8B][count:u32 at +8][cap:u32 at +12][entries at +16...]
|
|
117
|
+
* Entry: [hash:u32][key:i32][val:i32] = 12 bytes each
|
|
118
|
+
* Empty entry: hash=0, key uses (key | 1) as hash to avoid zero sentinel.
|
|
119
|
+
*
|
|
120
|
+
* Functions added:
|
|
121
|
+
* - __nmap_new(cap: i32) → i32
|
|
122
|
+
* - __nmap_set(map: i32, key: i32, val: i32) → void
|
|
123
|
+
* - __nmap_get(map: i32, key: i32) → i32
|
|
124
|
+
* - __nmap_has(map: i32, key: i32) → i32
|
|
125
|
+
* - __nmap_size(map: i32) → i32
|
|
126
|
+
*/
|
|
127
|
+
export declare function addNumericMapRuntime(mod: WasmModule): void;
|
|
128
|
+
/**
|
|
129
|
+
* Add numeric-key Set runtime functions (open-addressing hash set with i32 keys).
|
|
130
|
+
* Layout: [header 8B][count:u32 at +8][cap:u32 at +12][entries at +16...]
|
|
131
|
+
* Entry: [hash:u32][key:i32] = 8 bytes each
|
|
132
|
+
*
|
|
133
|
+
* Functions added:
|
|
134
|
+
* - __nset_new(cap: i32) → i32
|
|
135
|
+
* - __nset_add(set: i32, key: i32) → void
|
|
136
|
+
* - __nset_has(set: i32, key: i32) → i32
|
|
137
|
+
* - __nset_size(set: i32) → i32
|
|
138
|
+
*/
|
|
139
|
+
export declare function addNumericSetRuntime(mod: WasmModule): void;
|
|
140
|
+
/** Reserved name for the linear-backend f64 remainder helper (#2144). */
|
|
141
|
+
export declare const FMOD_FN = "__fmod";
|
|
142
|
+
/**
|
|
143
|
+
* (#2144) Add the Wasm-native IEEE-754 remainder (`fmod`) helper to the linear
|
|
144
|
+
* backend, mirroring the WasmGC `src/codegen/fmod.ts` work (#2056).
|
|
145
|
+
*
|
|
146
|
+
* The linear `%` arm previously emitted the naive `a - trunc(a/b)*b` formula
|
|
147
|
+
* that the GC backend explicitly retired: it drifts by ULPs, collapses to 0
|
|
148
|
+
* when `trunc(a/b)*b` rounds back to `a`, and produces `±Infinity` when `a/b`
|
|
149
|
+
* overflows f64 (ratio ≳ 1e308). This is the textbook cross-backend divergence
|
|
150
|
+
* flagged in docs/architecture/codegen-axes.md — both backends must agree on
|
|
151
|
+
* `%`.
|
|
152
|
+
*
|
|
153
|
+
* Algorithm (exact, no host import — dual-mode standalone): classic binary
|
|
154
|
+
* long-division remainder operating purely in f64. All intermediates stay
|
|
155
|
+
* ≤ |a|, so nothing overflows, and every step is an exact f64 op, so there is
|
|
156
|
+
* zero rounding drift. See fmod.ts for the full derivation and the verified
|
|
157
|
+
* edge-case set (`x % Inf`, `-0 % x`, `Inf % x`, `x % 0`, `NaN % x`, …).
|
|
158
|
+
*
|
|
159
|
+
* Signature: `(f64 a, f64 b) -> f64`. Idempotent — a second call is a no-op.
|
|
160
|
+
*/
|
|
161
|
+
export declare function addFmodRuntime(mod: WasmModule): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WasmModule } from '../ir/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Add SIMD-accelerated string and array runtime functions.
|
|
4
|
+
* Call this AFTER addStringRuntime / addArrayRuntime so the scalar
|
|
5
|
+
* versions are available as fallbacks and for index lookups.
|
|
6
|
+
*/
|
|
7
|
+
export declare function addSimdRuntime(mod: WasmModule): void;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PositionMap } from '../position-map.js';
|
|
2
|
+
/**
|
|
3
|
+
* Apply compile-time define substitutions to source text.
|
|
4
|
+
*
|
|
5
|
+
* @param source - Original TypeScript/JavaScript source
|
|
6
|
+
* @param defines - Map of dotted paths to replacement literals.
|
|
7
|
+
* Example: `{ "process.env.NODE_ENV": '"production"' }`
|
|
8
|
+
* @returns Source with substitutions applied
|
|
9
|
+
*/
|
|
10
|
+
export declare function applyDefineSubstitutions(source: string, defines: Record<string, string>): string;
|
|
11
|
+
/**
|
|
12
|
+
* #1928 — like {@link applyDefineSubstitutions} but also returns a `PositionMap`
|
|
13
|
+
* from the substituted output back to the input. Define replacements
|
|
14
|
+
* (`process.env.NODE_ENV` → `"production"`) change length, so positions after a
|
|
15
|
+
* match on the same line shift; multi-line replacements shift lines below.
|
|
16
|
+
* Tracking the exact match spans keeps diagnostics anchored to the user's
|
|
17
|
+
* original positions.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyDefineSubstitutionsWithMap(source: string, defines: Record<string, string>): {
|
|
20
|
+
source: string;
|
|
21
|
+
positionMap: PositionMap;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Build the default define map for a given production/development mode.
|
|
25
|
+
* This is the convenience path — users can also pass explicit defines.
|
|
26
|
+
*/
|
|
27
|
+
export declare function buildDefaultDefines(mode: "production" | "development"): Record<string, string>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { EarlyErrorContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Validate an ArrayLiteralExpression used as an assignment pattern (LHS of =, for-of, for-in).
|
|
5
|
+
* ES spec: ArrayAssignmentPattern restrictions:
|
|
6
|
+
* - Rest element (...x) must be last — no elements may follow
|
|
7
|
+
* - No trailing comma after rest (treated as elision after rest = error)
|
|
8
|
+
* - Rest element may not have an initializer (= default) — e.g. [...x = 1] = []
|
|
9
|
+
* - Each element must be a valid DestructuringAssignmentTarget
|
|
10
|
+
* - Comma expressions (x, y) are not valid element targets
|
|
11
|
+
* Strict mode: eval/arguments cannot appear as identifiers in assignment targets
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateArrayAssignmentPattern(ctx: EarlyErrorContext, arr: ts.ArrayLiteralExpression, strict: boolean): void;
|
|
14
|
+
/**
|
|
15
|
+
* Validate an ObjectLiteralExpression used as an assignment pattern.
|
|
16
|
+
* ES spec: ObjectAssignmentPattern restrictions:
|
|
17
|
+
* - Methods (shorthand methods, getters, setters) are not valid property values
|
|
18
|
+
* - Each property value must be a valid assignment target
|
|
19
|
+
* Strict mode: eval/arguments as shorthand names are errors
|
|
20
|
+
*/
|
|
21
|
+
export declare function validateObjectAssignmentPattern(ctx: EarlyErrorContext, obj: ts.ObjectLiteralExpression, strict: boolean): void;
|
|
22
|
+
/**
|
|
23
|
+
* Validate a single assignment target in a destructuring position.
|
|
24
|
+
* Flags: comma expressions, getter/setter as targets, invalid simple targets.
|
|
25
|
+
*/
|
|
26
|
+
export declare function validateAssignmentTarget(ctx: EarlyErrorContext, expr: ts.Expression, strict: boolean): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CompileError } from '../../index.js';
|
|
3
|
+
export interface EarlyErrorContext {
|
|
4
|
+
/** The source file being validated. */
|
|
5
|
+
readonly sourceFile: ts.SourceFile;
|
|
6
|
+
/** Accumulated errors (rules may push warnings/errors directly). */
|
|
7
|
+
readonly errors: CompileError[];
|
|
8
|
+
/** 1-based line/column for a node. */
|
|
9
|
+
pos(node: ts.Node): {
|
|
10
|
+
line: number;
|
|
11
|
+
column: number;
|
|
12
|
+
};
|
|
13
|
+
/** Push an error (severity "error") anchored at `node`. */
|
|
14
|
+
addError(node: ts.Node, message: string): void;
|
|
15
|
+
}
|
|
16
|
+
/** Build an EarlyErrorContext for a source file, with a fresh error array. */
|
|
17
|
+
export declare function createEarlyErrorContext(sourceFile: ts.SourceFile): EarlyErrorContext;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { EarlyErrorContext } from './context.js';
|
|
3
|
+
export declare function checkDuplicateParams(ctx: EarlyErrorContext, params: ts.NodeArray<ts.ParameterDeclaration>, node: ts.Node): void;
|
|
4
|
+
/** Check for duplicate lexical declarations (let, const, class, function) in a block. */
|
|
5
|
+
export declare function checkDuplicateLexicalDeclarations(ctx: EarlyErrorContext, block: ts.Block | ts.SourceFile): void;
|
|
6
|
+
/** Check duplicate lexical declarations across switch case clauses. */
|
|
7
|
+
export declare function checkSwitchCaseLexicalDuplicates(ctx: EarlyErrorContext, caseBlock: ts.CaseBlock): void;
|
|
8
|
+
/**
|
|
9
|
+
* Flag references to a switch CaseBlock's lexically-declared names that
|
|
10
|
+
* appear in sibling statements *after* the switch in the same statement
|
|
11
|
+
* list (#1805). Such a reference resolves to no runtime binding and throws
|
|
12
|
+
* a ReferenceError. Emitted as a warning so compilation continues; the
|
|
13
|
+
* test262 runtime-negative path treats any warning as the expected error.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkSwitchLexicalLeak(ctx: EarlyErrorContext, stmts: ts.NodeArray<ts.Statement>): void;
|
|
16
|
+
/** Check for duplicate private names in a class body. */
|
|
17
|
+
export declare function checkDuplicatePrivateNames(ctx: EarlyErrorContext, classNode: ts.ClassDeclaration | ts.ClassExpression): void;
|
|
18
|
+
/** Check for var/lexical declaration conflicts in a block or source file. */
|
|
19
|
+
export declare function checkVarLexicalConflicts(ctx: EarlyErrorContext, block: ts.Block | ts.SourceFile): void;
|
|
20
|
+
export declare function collectVarDeclaredNamesInBlock(ctx: EarlyErrorContext, node: ts.Node, lexicalNames: Set<string>): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { CompileError } from '../../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Detect ECMA-262 early errors (SyntaxErrors that TypeScript's parser misses)
|
|
5
|
+
* in a parsed source file. Returns a list of errors/warnings; an empty list
|
|
6
|
+
* means the source has no detectable early errors.
|
|
7
|
+
*
|
|
8
|
+
* The order of the passes below is preserved exactly from the original
|
|
9
|
+
* monolithic implementation.
|
|
10
|
+
*/
|
|
11
|
+
export declare function detectEarlyErrors(sourceFile: ts.SourceFile): CompileError[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { EarlyErrorContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Check for duplicate label names in a block (for class static block bodies).
|
|
5
|
+
* ES spec: ContainsDuplicateLabels must be false.
|
|
6
|
+
* Does not cross function boundaries.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkDuplicateLabelsInBlock(ctx: EarlyErrorContext, block: ts.Block): void;
|
|
9
|
+
/**
|
|
10
|
+
* Check for duplicate (nested, not sibling) label names — always a SyntaxError.
|
|
11
|
+
* ES spec: ContainsDuplicateLabels of StatementList must be false.
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkDuplicateLabels(ctx: EarlyErrorContext, node: ts.Node, activeLabels: Set<string>): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EarlyErrorContext } from './context.js';
|
|
2
|
+
/**
|
|
3
|
+
* `export default const/var/let` — always a SyntaxError.
|
|
4
|
+
* ES spec: ExportDeclaration : export default HoistableDeclaration |
|
|
5
|
+
* export default ClassDeclaration | export default [LAE] AssignmentExpression ;
|
|
6
|
+
* VariableStatement and LexicalDeclaration are not valid after export default.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkExportDefaultDeclaration(ctx: EarlyErrorContext): void;
|
|
9
|
+
/**
|
|
10
|
+
* Duplicate export names (source-file level check).
|
|
11
|
+
* ES spec: It is a Syntax Error if ExportedNames contains any duplicate entries.
|
|
12
|
+
*/
|
|
13
|
+
export declare function checkDuplicateExportNames(ctx: EarlyErrorContext): void;
|
|
14
|
+
/**
|
|
15
|
+
* Import/Export declaration position (ES static semantics).
|
|
16
|
+
* ImportDeclaration / ExportDeclaration / ExportAssignment are ModuleItems —
|
|
17
|
+
* they may only appear at the top level of a Module.
|
|
18
|
+
*/
|
|
19
|
+
export declare function checkModuleItemPosition(ctx: EarlyErrorContext): void;
|
|
20
|
+
/**
|
|
21
|
+
* Reserved words `yield` / `await` used as an identifier.
|
|
22
|
+
* `yield` is reserved in strict-mode code and inside generator bodies;
|
|
23
|
+
* `await` is reserved in module code and inside async function bodies.
|
|
24
|
+
*/
|
|
25
|
+
export declare function checkReservedIdentifiers(ctx: EarlyErrorContext): void;
|
|
26
|
+
/**
|
|
27
|
+
* HTML close comment (-->) in module code.
|
|
28
|
+
* HTML-like comments are allowed in scripts but not in modules.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkHtmlCloseComment(ctx: EarlyErrorContext): void;
|
|
31
|
+
/**
|
|
32
|
+
* Duplicate class constructors.
|
|
33
|
+
* ES spec: It is a Syntax Error if PrototypePropertyNameList of ClassElementList
|
|
34
|
+
* contains more than one occurrence of "constructor".
|
|
35
|
+
*/
|
|
36
|
+
export declare function checkDuplicateConstructors(ctx: EarlyErrorContext): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { EarlyErrorContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Run all per-node early-error checks rooted at `node`, recursing into its
|
|
5
|
+
* descendants. Equivalent to the original detectEarlyErrors `visit` closure.
|
|
6
|
+
*/
|
|
7
|
+
export declare function runNodeChecks(ctx: EarlyErrorContext, node: ts.Node): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
export declare function findInnermostNodeAtPosition(node: ts.Node, position: number): ts.Node;
|
|
3
|
+
/**
|
|
4
|
+
* Check if a node is in strict mode context.
|
|
5
|
+
* A node is in strict mode if:
|
|
6
|
+
* - The source file has a "use strict" directive prologue
|
|
7
|
+
* - It's inside a class body (class bodies are always strict)
|
|
8
|
+
* - It's inside a function with a "use strict" directive prologue
|
|
9
|
+
*
|
|
10
|
+
* Note: being a module does NOT imply strict here. test262 `noStrict` tests are
|
|
11
|
+
* sloppy-mode scripts, so we deliberately do not treat module = strict (see the
|
|
12
|
+
* SourceFile branch below, which returns false).
|
|
13
|
+
*/
|
|
14
|
+
export declare function isStrictMode(node: ts.Node): boolean;
|
|
15
|
+
export declare function isArgumentsOrEval(node: ts.Node): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Check if an expression is a "simple assignment target" per ES spec.
|
|
18
|
+
* Only identifiers and property accesses are valid assignment targets.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isSimpleAssignmentTarget(node: ts.Node): boolean;
|
|
21
|
+
/** Collect binding names and report duplicates. */
|
|
22
|
+
export declare function collectBindingNamesWithDuplicateCheck(name: ts.BindingName, out: Set<string>, dupes: Set<string>): void;
|
|
23
|
+
/** Collect all identifier names from a binding pattern (identifier, array, object destructuring). */
|
|
24
|
+
export declare function collectBindingNames(name: ts.BindingName, out: Set<string>): void;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an expression is NOT a valid assignment target per ES spec.
|
|
27
|
+
* For simple assignment (=): identifiers, property/element access, and
|
|
28
|
+
* destructuring patterns (object/array literals) are valid.
|
|
29
|
+
* For update (++/--) and compound (+=, etc.): only identifiers and
|
|
30
|
+
* property/element access are valid — no destructuring patterns.
|
|
31
|
+
*/
|
|
32
|
+
export declare function isInvalidAssignmentTarget(node: ts.Expression, allowDestructuring?: boolean): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if an expression is a call expression (not a valid simple assignment target).
|
|
35
|
+
* CallExpression assignment targets are SyntaxErrors in strict mode per ES spec.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isCallExpressionTarget(node: ts.Node): boolean;
|
|
38
|
+
/** Check if an expression involves optional chaining (?.) */
|
|
39
|
+
export declare function hasOptionalChain(node: ts.Expression): boolean;
|
|
40
|
+
export declare function isUsingDeclarationStatement(node: ts.Node): node is ts.VariableStatement;
|
|
41
|
+
/** Check if a node is inside a class static initializer block. */
|
|
42
|
+
export declare function isInsideClassStaticBlock(node: ts.Node): boolean;
|
|
43
|
+
/** Check if a node is inside any function (for return statement validation). */
|
|
44
|
+
export declare function isInsideFunction(node: ts.Node): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Check if a node is inside any function (sync or async, including arrow, method, etc.)
|
|
47
|
+
* Used to detect AwaitExpression in non-async function (a SyntaxError in module context).
|
|
48
|
+
*/
|
|
49
|
+
export declare function isInsideAnyFunction(node: ts.Node): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Returns true if the node is inside a function that is itself inside another function
|
|
52
|
+
* (i.e., the function depth is >= 2 from SourceFile).
|
|
53
|
+
*
|
|
54
|
+
* Used instead of isInsideAnyFunction for the await-in-non-async-function check because
|
|
55
|
+
* the test262 runner wraps all module code in `export function test() { ... }`.
|
|
56
|
+
* Top-level-await tests have `await` directly inside test() (depth 1) — these should
|
|
57
|
+
* not be flagged. Negative tests like `function fn() { await 0; }` have `await` inside
|
|
58
|
+
* fn() inside test() (depth 2) — these should be flagged.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isInsideNestedFunction(node: ts.Node): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Check if an expression tree contains `arguments` identifier reference.
|
|
63
|
+
* Used for ES spec ContainsArguments check in class field initializers.
|
|
64
|
+
* Does NOT cross function boundaries (arguments is valid inside nested functions).
|
|
65
|
+
*/
|
|
66
|
+
export declare function containsArguments(node: ts.Node): boolean;
|
|
67
|
+
/** Get the computed name of a class member, if it's a simple string. */
|
|
68
|
+
export declare function getMemberName(member: ts.ClassElement): string | null;
|
|
69
|
+
/** Check if a node is inside a class constructor. Arrow functions inherit super() context. */
|
|
70
|
+
export declare function isInsideClassConstructor(node: ts.Node): boolean;
|
|
71
|
+
/** Check if a node is inside a method (class or object). Arrow functions inherit super property context. */
|
|
72
|
+
export declare function isInsideMethod(node: ts.Node): boolean;
|
|
73
|
+
/** Check if a node is an iteration statement. */
|
|
74
|
+
export declare function isIterationStatement(node: ts.Node): boolean;
|
|
75
|
+
/** Check if `continue` is inside a valid iteration statement. Respects labels and function boundaries. */
|
|
76
|
+
export declare function isInsideIteration(node: ts.Node, label?: string): boolean;
|
|
77
|
+
/** Check if `break` is inside a valid breakable statement. Respects labels and function boundaries. */
|
|
78
|
+
export declare function isInsideBreakable(node: ts.Node, label?: string): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Collect the lexically-declared names of a switch CaseBlock (#1805).
|
|
81
|
+
* Per ES spec, the LexicallyDeclaredNames of a CaseBlock are the let/const,
|
|
82
|
+
* class, and function declarations directly inside its case/default clauses.
|
|
83
|
+
* These names are scoped to the switch block and must not leak to the
|
|
84
|
+
* enclosing scope. We do not descend into nested blocks/functions — only the
|
|
85
|
+
* top level of each clause contributes to the CaseBlock's lexical scope.
|
|
86
|
+
*/
|
|
87
|
+
export declare function collectSwitchClauseLexicalNames(caseBlock: ts.CaseBlock): Set<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Collect names bound in the enclosing statement list (var/let/const,
|
|
90
|
+
* function, class, import). Used to decide whether a reference to a
|
|
91
|
+
* switch-scoped name is actually shadowed by an outer binding (in which
|
|
92
|
+
* case the reference is legal and must not be flagged).
|
|
93
|
+
*/
|
|
94
|
+
export declare function collectStatementListBoundNames(stmts: ts.NodeArray<ts.Statement>): Set<string>;
|
|
95
|
+
/**
|
|
96
|
+
* Detect a reference to a name within `node` (and its descendants),
|
|
97
|
+
* not crossing nested function/class scopes. Returns the first matching
|
|
98
|
+
* identifier reference, or undefined.
|
|
99
|
+
*/
|
|
100
|
+
export declare function findNameReference(node: ts.Node, name: string): ts.Identifier | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Check if a node is inside the formal parameters of a generator function.
|
|
103
|
+
* ES spec: FormalParameters of generators use [+Yield] but YieldExpression
|
|
104
|
+
* is forbidden — "It is a Syntax Error if FormalParameters Contains YieldExpression".
|
|
105
|
+
*/
|
|
106
|
+
export declare function isInsideGeneratorParams(node: ts.Node): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Check if a node is inside the formal parameters of an async function.
|
|
109
|
+
* ES spec: "It is a Syntax Error if FormalParameters Contains AwaitExpression".
|
|
110
|
+
*/
|
|
111
|
+
export declare function isInsideAsyncParams(node: ts.Node): boolean;
|
|
112
|
+
/** Check if a node is inside an async function (including async generators). */
|
|
113
|
+
export declare function isInsideAsyncFunction(node: ts.Node): boolean;
|
|
114
|
+
/** Check if a node is inside a generator function (including async generators). */
|
|
115
|
+
export declare function isInsideGeneratorFunction(node: ts.Node): boolean;
|
|
116
|
+
/** Check if a function declaration is in a single-statement position (not a block). */
|
|
117
|
+
export declare function isStatementPosition(parent: ts.Node, child: ts.Node): boolean;
|
|
118
|
+
/** Check if a node has the 'async' modifier. */
|
|
119
|
+
export declare function hasAsyncModifier(node: ts.FunctionDeclaration): boolean;
|
|
120
|
+
/** Check if a private identifier is inside a class that declares it. */
|
|
121
|
+
export declare function isInsideClassWithPrivateName(node: ts.Node, privateName: string): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Check if an object literal is in a destructuring assignment context.
|
|
124
|
+
* In that context, CoverInitializedName ({ x = 1 }) is valid.
|
|
125
|
+
*/
|
|
126
|
+
export declare function isAssignmentPatternContext(objLit: ts.ObjectLiteralExpression): boolean;
|
|
127
|
+
export declare function isAssignmentPatternContext_expr(arrLit: ts.ArrayLiteralExpression): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* TypeScript parses `let` followed by a LineTerminator and then an identifier
|
|
130
|
+
* or `{` (e.g. `if (false) let\nx = 1;`) as a LexicalDeclaration, but per
|
|
131
|
+
* ECMA-262 the ExpressionStatement lookahead restriction is only `let [`
|
|
132
|
+
* (with NO `[no LineTerminator here]`). So `let` + newline + (anything but
|
|
133
|
+
* `[`) is actually an ExpressionStatement (`let` identifier reference) closed
|
|
134
|
+
* by ASI, which is valid in single-statement position. `let [` stays a
|
|
135
|
+
* lexical declaration even across a newline, and `const` is always a reserved
|
|
136
|
+
* word so it is never an expression statement.
|
|
137
|
+
*
|
|
138
|
+
* Takes the SourceFile explicitly (the original closed over it).
|
|
139
|
+
*/
|
|
140
|
+
export declare function isAsiLetExpressionStatement(sourceFile: ts.SourceFile, node: ts.VariableStatement, flags: ts.NodeFlags): boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ts } from '../../ts-api.js';
|
|
2
|
+
import { EarlyErrorContext } from './context.js';
|
|
3
|
+
/**
|
|
4
|
+
* Check for temporal dead zone (TDZ) violations in a list of statements.
|
|
5
|
+
* A TDZ violation occurs when a let/const variable is referenced before
|
|
6
|
+
* its declaration in the same scope.
|
|
7
|
+
*
|
|
8
|
+
* Handles two patterns:
|
|
9
|
+
* 1. Use in a prior statement: `x; let x;`
|
|
10
|
+
* 2. Use in the initializer of the declaration itself: `let x = x + 1;`
|
|
11
|
+
*/
|
|
12
|
+
export declare function checkTDZInStatements(ctx: EarlyErrorContext, stmts: ts.NodeArray<ts.Statement>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a node tree references an identifier by name.
|
|
15
|
+
* Used to detect TDZ violations.
|
|
16
|
+
*/
|
|
17
|
+
export declare function checkForTDZRef(ctx: EarlyErrorContext, node: ts.Node, name: string): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { TypedAST } from '../checker/index.js';
|
|
3
|
+
import { CompileError, ImportDescriptor, ImportIntent } from '../index.js';
|
|
4
|
+
import { WasmModule } from '../ir/types.js';
|
|
5
|
+
declare function classifyImport(name: string, mod: WasmModule): ImportIntent;
|
|
6
|
+
declare function buildImportManifest(mod: WasmModule): ImportDescriptor[];
|
|
7
|
+
/** Check if TS syntax errors look like the source is plain JavaScript (no type annotations). */
|
|
8
|
+
declare function looksLikeTsSyntaxOnJs(diagnostics: readonly {
|
|
9
|
+
code: number;
|
|
10
|
+
messageText: string | ts.DiagnosticMessageChain;
|
|
11
|
+
}[]): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Detect untyped parameters in JS mode and add helpful warnings suggesting JSDoc annotations.
|
|
14
|
+
* Returns warning CompileErrors for each function parameter that resolved to 'any'.
|
|
15
|
+
*/
|
|
16
|
+
declare function checkJsTypeCoverage(ast: TypedAST): CompileError[];
|
|
17
|
+
declare const DOWNGRADE_DIAG_CODES: Set<number>;
|
|
18
|
+
export { buildImportManifest, checkJsTypeCoverage, classifyImport, DOWNGRADE_DIAG_CODES, looksLikeTsSyntaxOnJs };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TypedAST } from '../checker/index.js';
|
|
2
|
+
import { CompileError, CompileOptions } from '../index.js';
|
|
3
|
+
import { Instr, ValType, WasmModule } from '../ir/types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Apply C ABI transformation to a compiled WasmModule.
|
|
6
|
+
* Rewrites exported function signatures for C compatibility and generates a C header.
|
|
7
|
+
*/
|
|
8
|
+
declare function applyCabiTransform(mod: WasmModule, moduleName: string, ast?: TypedAST): {
|
|
9
|
+
cHeader: string;
|
|
10
|
+
};
|
|
11
|
+
declare function generateDts(ast: TypedAST, mod: WasmModule): string;
|
|
12
|
+
declare function generateImportsHelper(mod: WasmModule): string;
|
|
13
|
+
export interface ObjectCompileResult {
|
|
14
|
+
/** Relocatable Wasm object file (.o) */
|
|
15
|
+
object: Uint8Array;
|
|
16
|
+
/** true if compilation was successful */
|
|
17
|
+
success: boolean;
|
|
18
|
+
/** Error messages with line numbers */
|
|
19
|
+
errors: CompileError[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Compile TypeScript source to a relocatable Wasm object file (.o).
|
|
23
|
+
* Uses the same pipeline as compileSource but emits LLVM-style
|
|
24
|
+
* linking metadata instead of a final executable module.
|
|
25
|
+
*/
|
|
26
|
+
export declare function compileToObjectSource(source: string, options?: CompileOptions): ObjectCompileResult;
|
|
27
|
+
/**
|
|
28
|
+
* Post-processing pass: widen all non-defaultable `ref` types to `ref_null`
|
|
29
|
+
* throughout the module. This fixes two classes of Wasm validation errors:
|
|
30
|
+
*
|
|
31
|
+
* 1. "uninitialized non-defaultable local" -- locals with `ref $T` type have
|
|
32
|
+
* no implicit default value, so any code path that reads them before writing
|
|
33
|
+
* causes a validation error. Widening to `ref null $T` gives them a null default.
|
|
34
|
+
*
|
|
35
|
+
* 2. "struct.get/set expected type (ref null N), found ..." -- when function
|
|
36
|
+
* signatures use `ref` but callers/callees produce `ref_null` (or vice versa),
|
|
37
|
+
* the Wasm validator rejects the type mismatch. Consistently using `ref_null`
|
|
38
|
+
* in function types, locals, and globals avoids this.
|
|
39
|
+
*/
|
|
40
|
+
declare function widenNonDefaultableTypes(mod: WasmModule): void;
|
|
41
|
+
/**
|
|
42
|
+
* Recursively walk an instruction body and widen block types (if/block/loop/try)
|
|
43
|
+
* from `ref` to `ref_null`, matching the widened function type signatures.
|
|
44
|
+
*/
|
|
45
|
+
declare function widenBlockTypesInBody(body: Instr[], widenValType: (t: ValType) => ValType): void;
|
|
46
|
+
export { applyCabiTransform, generateDts, generateImportsHelper, widenBlockTypesInBody, widenNonDefaultableTypes };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { CompileError, CompileOptions } from '../index.js';
|
|
2
|
+
import { ts } from '../ts-api.js';
|
|
3
|
+
import { detectEarlyErrors } from './early-errors/index.js';
|
|
4
|
+
declare const DEFAULT_BLOCKED_MEMBERS: Set<string>;
|
|
5
|
+
declare function getApproxSourceLocation(sourceFile: ts.SourceFile): {
|
|
6
|
+
line: number;
|
|
7
|
+
column: number;
|
|
8
|
+
};
|
|
9
|
+
declare function pushSourceAnchoredDiagnostic(errors: CompileError[], sourceFile: ts.SourceFile, message: string, severity: "error" | "warning"): void;
|
|
10
|
+
/** Validate source against safe mode restrictions. Returns errors for violations. */
|
|
11
|
+
declare function validateSafeMode(sourceFile: ts.SourceFile, checker: ts.TypeChecker, options: CompileOptions): CompileError[];
|
|
12
|
+
declare function hasExportModifier(node: ts.Node): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Hardened mode: walk AST and reject dangerous patterns.
|
|
15
|
+
* Inspired by Endo/SES — compile-time rejection of insecure features.
|
|
16
|
+
*/
|
|
17
|
+
declare function validateHardenedMode(sourceFile: ts.SourceFile): Array<{
|
|
18
|
+
message: string;
|
|
19
|
+
line: number;
|
|
20
|
+
column: number;
|
|
21
|
+
severity: "error";
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* ES spec: PerformEval runs early-error checks on the eval'd source.
|
|
25
|
+
* `super()` is a SyntaxError unless the eval is a *direct* eval in a
|
|
26
|
+
* context where a SuperCall is allowed (i.e. inside a derived class
|
|
27
|
+
* constructor body). Indirect eval (`(0, eval)(...)`, `var e = eval; e(...)`)
|
|
28
|
+
* always rejects super(), as does direct eval outside the constructor
|
|
29
|
+
* (e.g. inside a class field initializer).
|
|
30
|
+
*
|
|
31
|
+
* Since #1054, if we see an `eval(<literal>)` or `(0, eval)(<literal>)`
|
|
32
|
+
* whose literal contains `super(`, we rewrite the call to a throwing IIFE
|
|
33
|
+
* so the SyntaxError fires at runtime when the surrounding expression runs
|
|
34
|
+
* (e.g. when a field initializer is evaluated during `new C()`).
|
|
35
|
+
*
|
|
36
|
+
* Narrowing:
|
|
37
|
+
* - Only string-literal arg is examined (single/double quoted). Template
|
|
38
|
+
* literals are not test262-tested in this pattern.
|
|
39
|
+
* - Only `super(` in the string triggers rewrite — `super.x` / `super[x]`
|
|
40
|
+
* are legal in eval-from-field-initializer and must not be rewritten.
|
|
41
|
+
* - Direct eval from a derived constructor would legitimately allow
|
|
42
|
+
* super(), but test262 has no passing tests covering that pattern.
|
|
43
|
+
*/
|
|
44
|
+
declare function rewriteEvalSuperCall(source: string): string;
|
|
45
|
+
export { DEFAULT_BLOCKED_MEMBERS, detectEarlyErrors, getApproxSourceLocation, hasExportModifier, pushSourceAnchoredDiagnostic, rewriteEvalSuperCall, validateHardenedMode, validateSafeMode, };
|