@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,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #2720 — non-Unicode (legacy) case folding for the standalone regex engine.
|
|
3
|
+
*
|
|
4
|
+
* The pure-WasmGC matcher works on UTF-16 code units. Under the `i` flag WITHOUT
|
|
5
|
+
* `u`/`v`, §22.2.2.9.3 Canonicalize folds each code unit through the Unicode
|
|
6
|
+
* default UPPERCASE mapping — not ASCII-only — so `/Ä/i` matches `ä`, `/Σ/i`
|
|
7
|
+
* matches `σ`/`ς`, Cyrillic case pairs match, etc. (`u`/`v` mode uses simple
|
|
8
|
+
* case folding and is already handled at parse time by the host-oracle in
|
|
9
|
+
* `unicode.ts`; this module is the NON-unicode arm only.)
|
|
10
|
+
*
|
|
11
|
+
* Following the same "host as spec oracle" pattern as #1911/#1912, the
|
|
12
|
+
* canonicalization equivalence classes are computed ONCE AT COMPILE TIME from
|
|
13
|
+
* the host's `String.prototype.toUpperCase` (whose Unicode tables the spec
|
|
14
|
+
* Canonicalize is defined against) and the fold is desugared into plain unit
|
|
15
|
+
* CLASS ranges. The emitted module stays pure Wasm with zero runtime tables.
|
|
16
|
+
*
|
|
17
|
+
* Legacy Canonicalize(ch), ch a UTF-16 code unit (§22.2.2.9.3, IgnoreCase,
|
|
18
|
+
* non-Unicode):
|
|
19
|
+
* 1. let u = the uppercase mapping of the single-code-unit string of `ch`.
|
|
20
|
+
* 2. if u is not a single code unit, return ch. (e.g. ß → "SS")
|
|
21
|
+
* 3. let cu = u's single code unit.
|
|
22
|
+
* 4. if ch ≥ 128 and cu < 128, return ch. (ASCII-guard: ſ→S, K→K stay)
|
|
23
|
+
* 5. return cu.
|
|
24
|
+
* Two code units are `i`-equivalent iff they Canonicalize to the same value.
|
|
25
|
+
*/
|
|
26
|
+
/** Sorted, de-duplicated code-unit list → coalesced inclusive ranges. */
|
|
27
|
+
export declare function unitsToRanges(units: number[]): Array<[number, number]>;
|
|
28
|
+
/**
|
|
29
|
+
* The legacy-canonicalization equivalence class of a single code unit (always
|
|
30
|
+
* includes `code` itself). Size 1 ⇒ no case partners (emit a plain CHAR);
|
|
31
|
+
* size > 1 ⇒ desugar to a CLASS over the returned units.
|
|
32
|
+
*/
|
|
33
|
+
export declare function foldCharUnitsLegacy(code: number): number[];
|
|
34
|
+
/**
|
|
35
|
+
* Expand a class's inclusive ranges with every legacy-canonicalization case
|
|
36
|
+
* partner of any member, then coalesce. For each cased unit that falls inside
|
|
37
|
+
* the input ranges, its whole equivalence set is added (so `[À-Ý]/i` also
|
|
38
|
+
* matches `à-ý`, `[Σ]/i` also matches `σ`/`ς`, …). Folding happens BEFORE the
|
|
39
|
+
* CLASS op applies negation, so `[^a]/i` correctly excludes both `a` and `A`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function foldClassRangesLegacy(ranges: Array<[number, number]>): Array<[number, number]>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { CompiledRegex } from './bytecode.js';
|
|
2
|
+
import { ParsedRegex, ReNode } from './parse.js';
|
|
3
|
+
/**
|
|
4
|
+
* Conservative nullability test (#1959): can `node` match the empty string?
|
|
5
|
+
* Used to decide whether a star/plus loop needs the empty-iteration PROGRESS
|
|
6
|
+
* guard. Over-approximating (returning true when unsure) only adds a cheap
|
|
7
|
+
* guard; under-approximating would risk the silent-no-match bug, so unknown
|
|
8
|
+
* shapes default to nullable. Zero-width assertions (`^`, `$`, `\b`,
|
|
9
|
+
* lookaround) are nullable; consuming atoms (char/class/any) are not.
|
|
10
|
+
*/
|
|
11
|
+
export declare function canMatchEmpty(node: ReNode): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Capture-group index span of a subtree (#1960): `[min, max]` of every group's
|
|
14
|
+
* `capIndex` reachable inside `node`, or null when it contains no captures.
|
|
15
|
+
* Used to emit a `CLEAR` at each quantifier-iteration head so stale captures
|
|
16
|
+
* from an earlier iteration don't leak (§22.2.2.3.1 RepeatMatcher). Lookaround
|
|
17
|
+
* bodies are NOT descended into — their captures live in separate sub-programs
|
|
18
|
+
* governed by the lookaround's own atomic attempt, not the outer loop.
|
|
19
|
+
*/
|
|
20
|
+
export declare function captureSpan(node: ReNode): [number, number] | null;
|
|
21
|
+
/** Thrown when `{n,m}` expansion would blow past the size cap. */
|
|
22
|
+
export declare class RepeatTooLargeError extends Error {
|
|
23
|
+
constructor(detail: string);
|
|
24
|
+
}
|
|
25
|
+
/** ASCII-only case fold (uppercase → lowercase). Phase 2a `i` is ASCII; full
|
|
26
|
+
* Unicode case folding is deferred (documented in the issue + test file). */
|
|
27
|
+
export declare function asciiFold(code: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* For the `i` flag (ASCII), augment class ranges with their case counterparts
|
|
30
|
+
* so a CLASS op stays a plain range-membership test (no per-op fold). For each
|
|
31
|
+
* range overlapping `A-Z` we add the matching lowercase span and vice versa.
|
|
32
|
+
* Letters only; non-letters are unaffected (ASCII case folding).
|
|
33
|
+
*/
|
|
34
|
+
export declare function foldClassRangesAscii(ranges: Array<[number, number]>): Array<[number, number]>;
|
|
35
|
+
/**
|
|
36
|
+
* Structurally reverse an AST for lookbehind compilation (#1911): concat order
|
|
37
|
+
* flips recursively so the body matches right-to-left when the VM runs with
|
|
38
|
+
* direction -1. Alternative ORDER is preserved (only each option's contents
|
|
39
|
+
* reverse). Lookaround nodes are leaves — their bodies are separate
|
|
40
|
+
* sub-programs compiled in their own direction.
|
|
41
|
+
*/
|
|
42
|
+
export declare function reverseNode(node: ReNode): ReNode;
|
|
43
|
+
/**
|
|
44
|
+
* Compile a parsed pattern + flag bits into a runnable program. Wraps the body
|
|
45
|
+
* in SAVE 0 … SAVE 1 (whole match) and a trailing MATCH, then appends the
|
|
46
|
+
* queued lookaround sub-programs.
|
|
47
|
+
*/
|
|
48
|
+
export declare function compileParsed(parsed: ParsedRegex, flags: number): CompiledRegex;
|
|
49
|
+
/** Convenience: parse + compile in one step. Throws RegexUnsupportedError /
|
|
50
|
+
* RepeatTooLargeError for out-of-subset patterns. */
|
|
51
|
+
export declare function compilePattern(pattern: string, flags: number): CompiledRegex;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export type ReNode = {
|
|
2
|
+
kind: "char";
|
|
3
|
+
code: number;
|
|
4
|
+
} | {
|
|
5
|
+
kind: "any";
|
|
6
|
+
} | {
|
|
7
|
+
kind: "class";
|
|
8
|
+
ranges: Array<[number, number]>;
|
|
9
|
+
negated: boolean;
|
|
10
|
+
} | {
|
|
11
|
+
kind: "bol";
|
|
12
|
+
} | {
|
|
13
|
+
kind: "eol";
|
|
14
|
+
} | {
|
|
15
|
+
kind: "wordBoundary";
|
|
16
|
+
negated: boolean;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "backref";
|
|
19
|
+
index: number;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "lookaround";
|
|
22
|
+
node: ReNode;
|
|
23
|
+
negated: boolean;
|
|
24
|
+
behind: boolean;
|
|
25
|
+
} | {
|
|
26
|
+
kind: "modGroup";
|
|
27
|
+
add: number;
|
|
28
|
+
remove: number;
|
|
29
|
+
node: ReNode;
|
|
30
|
+
} | {
|
|
31
|
+
kind: "udot";
|
|
32
|
+
} | {
|
|
33
|
+
kind: "concat";
|
|
34
|
+
parts: ReNode[];
|
|
35
|
+
} | {
|
|
36
|
+
kind: "alt";
|
|
37
|
+
options: ReNode[];
|
|
38
|
+
} | {
|
|
39
|
+
kind: "star";
|
|
40
|
+
node: ReNode;
|
|
41
|
+
greedy: boolean;
|
|
42
|
+
} | {
|
|
43
|
+
kind: "plus";
|
|
44
|
+
node: ReNode;
|
|
45
|
+
greedy: boolean;
|
|
46
|
+
} | {
|
|
47
|
+
kind: "opt";
|
|
48
|
+
node: ReNode;
|
|
49
|
+
greedy: boolean;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "repeat";
|
|
52
|
+
node: ReNode;
|
|
53
|
+
min: number;
|
|
54
|
+
max: number;
|
|
55
|
+
greedy: boolean;
|
|
56
|
+
} | {
|
|
57
|
+
kind: "group";
|
|
58
|
+
node: ReNode;
|
|
59
|
+
capIndex: number;
|
|
60
|
+
name: string | null;
|
|
61
|
+
};
|
|
62
|
+
export interface ParsedRegex {
|
|
63
|
+
root: ReNode;
|
|
64
|
+
/** Number of capturing groups (group 0 / whole match NOT included). */
|
|
65
|
+
numCaptures: number;
|
|
66
|
+
/** Capture name → 1-based group index for named groups. */
|
|
67
|
+
groupNames: Map<string, number>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Complement a range list over the full UTF-16 code-unit space [0, 0xFFFF].
|
|
71
|
+
* Used to lower negated shorthands *inside* a class (`[\D]`) to plain ranges,
|
|
72
|
+
* since a class is the union of its members and per-member negation cannot be
|
|
73
|
+
* expressed in the run-length class table. #1912.
|
|
74
|
+
*/
|
|
75
|
+
export declare function complementRanges(ranges: Array<[number, number]>): Array<[number, number]>;
|
|
76
|
+
export declare function parsePattern(pattern: string, flags?: number): ParsedRegex;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ReNode } from './parse.js';
|
|
2
|
+
/** Inclusive code-point ranges, sorted and coalesced. */
|
|
3
|
+
export type CpRanges = Array<[number, number]>;
|
|
4
|
+
/**
|
|
5
|
+
* Enumerate the exact code-point membership of a class-like atom under the
|
|
6
|
+
* given flag string (must include `u` or `v`; may include `i`). `source` is
|
|
7
|
+
* the literal pattern text of the atom: `[...]` (negation included), a
|
|
8
|
+
* `\p{…}`/`\P{…}` escape, or a single (escaped) character.
|
|
9
|
+
*
|
|
10
|
+
* Throws `RegexUnsupportedError` when the host rejects the source (the
|
|
11
|
+
* caller's host-oracle pass should have caught genuinely invalid patterns
|
|
12
|
+
* already) or when the atom can match strings (`\q{…}`).
|
|
13
|
+
*/
|
|
14
|
+
export declare function enumerateClassRanges(source: string, flagStr: string): CpRanges;
|
|
15
|
+
/**
|
|
16
|
+
* Parse the body of a v-mode `\q{…}` string disjunction (§22.2.1
|
|
17
|
+
* ClassStringDisjunction) into its `|`-separated operands, each resolved to its
|
|
18
|
+
* sequence of code points. `qBody` is the text BETWEEN the braces (the caller
|
|
19
|
+
* has already stripped `\q{` and the closing `}`).
|
|
20
|
+
*
|
|
21
|
+
* Each operand is a `ClassString` = a list of `ClassSetCharacter`s. Inside the
|
|
22
|
+
* disjunction the only structural metacharacters are `|` (operand separator)
|
|
23
|
+
* and `\` (escape); every other source character — including `.`, `*`, `(`,
|
|
24
|
+
* `[`, `{` — is a LITERAL code point. The empty operand (`\q{}` or an empty arm
|
|
25
|
+
* of `\q{|a}`) yields a zero-length code-point array (matches the empty
|
|
26
|
+
* string).
|
|
27
|
+
*
|
|
28
|
+
* Returns one `number[]` (code points) per operand. Throws
|
|
29
|
+
* `RegexUnsupportedError` on a malformed escape so the caller's refusal stays
|
|
30
|
+
* loud rather than emitting a wrong node.
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseStringDisjunction(qBody: string): number[][];
|
|
33
|
+
/**
|
|
34
|
+
* Desugar a code-point range set into the unit-level AST (see module doc).
|
|
35
|
+
* The result consumes exactly one CODE POINT (1 or 2 units) per match, so
|
|
36
|
+
* quantifiers wrapped around it iterate by code point as `u` requires.
|
|
37
|
+
*/
|
|
38
|
+
export declare function cpRangesToNode(ranges: CpRanges): ReNode;
|
|
39
|
+
/** Code-point ranges for `.` in u/v mode (static — no host needed). */
|
|
40
|
+
export declare function dotCpRanges(dotAll: boolean): CpRanges;
|
|
41
|
+
/** Escape a code point as a class-safe `\u{…}` source fragment. */
|
|
42
|
+
export declare function codePointSource(cp: number): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Matches the Wasm VM's step cap. Tunable; documented in the issue. */
|
|
2
|
+
export declare const REGEX_STEP_CAP = 1000000;
|
|
3
|
+
export interface VmMatch {
|
|
4
|
+
/** Capture slots: `[g0start,g0end,g1start,g1end,…]`; -1 = unset. */
|
|
5
|
+
caps: Int32Array;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Run `prog` against `input` starting at `startIdx`. Returns the filled
|
|
9
|
+
* capture array on a match (anchored at `startIdx`), or null on no match /
|
|
10
|
+
* step-cap exceeded. This is a single anchored attempt — callers (test/exec/
|
|
11
|
+
* match) drive the start position scan.
|
|
12
|
+
*
|
|
13
|
+
* #1911: `entryPc` selects the (sub-)program to run, `dir` the scan direction
|
|
14
|
+
* (-1 for lookbehind bodies), and `capsIn` seeds the capture state for
|
|
15
|
+
* recursive lookaround attempts (copy-on-write — the caller's array is never
|
|
16
|
+
* mutated; adopt the RETURNED array to observe sub-captures).
|
|
17
|
+
*/
|
|
18
|
+
export declare function runAt(prog: number[], classTable: number[], nGroups: number, input: string, startIdx: number, entryPc?: number, dir?: number, capsIn?: Int32Array, nScratch?: number): Int32Array | null;
|
|
19
|
+
/**
|
|
20
|
+
* Full search: scan start positions `startIdx..len` (sticky callers pass a
|
|
21
|
+
* pre-clamped range via a single `runAt`). Returns the first match's caps or
|
|
22
|
+
* null.
|
|
23
|
+
*/
|
|
24
|
+
export declare function search(prog: number[], classTable: number[], nGroups: number, input: string, startIdx: number, sticky: boolean, nScratch?: number): Int32Array | null;
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import { ts } from '../ts-api.js';
|
|
2
|
+
import { ValType } from '../ir/types.js';
|
|
3
|
+
import { CodegenContext, FunctionContext } from './context/types.js';
|
|
4
|
+
import { InnerResult } from './shared.js';
|
|
5
|
+
export declare const STANDALONE_REGEXP_ABI_VERSION = 1;
|
|
6
|
+
export declare const STANDALONE_REGEXP_ENGINE_KIND: "quickjs-libregexp";
|
|
7
|
+
export declare const STANDALONE_REGEXP_SUBSET_ENGINE_KIND: "native-literal-substring";
|
|
8
|
+
export type StandaloneRegExpEngineKind = typeof STANDALONE_REGEXP_ENGINE_KIND | typeof STANDALONE_REGEXP_SUBSET_ENGINE_KIND;
|
|
9
|
+
export interface StandaloneRegExpAbiFunction {
|
|
10
|
+
/**
|
|
11
|
+
* Function name expected in the generated module. These are in-module
|
|
12
|
+
* symbols, not `env` JS-host imports.
|
|
13
|
+
*/
|
|
14
|
+
name: string;
|
|
15
|
+
params: readonly ValType[];
|
|
16
|
+
results: readonly ValType[];
|
|
17
|
+
}
|
|
18
|
+
export interface StandaloneRegExpEngineConfig {
|
|
19
|
+
kind: StandaloneRegExpEngineKind;
|
|
20
|
+
abiVersion: typeof STANDALONE_REGEXP_ABI_VERSION;
|
|
21
|
+
functions: typeof STANDALONE_REGEXP_ABI;
|
|
22
|
+
}
|
|
23
|
+
export interface StandaloneRegExpEngineState {
|
|
24
|
+
standaloneRegExpEngine?: StandaloneRegExpEngineConfig | null;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Minimal ABI boundary for the first native engine slice. Lowering code should
|
|
28
|
+
* only query this contract after #1474's refusal gate is opened.
|
|
29
|
+
*/
|
|
30
|
+
export declare const STANDALONE_REGEXP_ABI: {
|
|
31
|
+
readonly compile: {
|
|
32
|
+
readonly name: "__re_compile";
|
|
33
|
+
readonly params: readonly [{
|
|
34
|
+
readonly kind: "i32";
|
|
35
|
+
}, {
|
|
36
|
+
readonly kind: "i32";
|
|
37
|
+
}, {
|
|
38
|
+
readonly kind: "i32";
|
|
39
|
+
}];
|
|
40
|
+
readonly results: readonly [{
|
|
41
|
+
readonly kind: "i32";
|
|
42
|
+
}];
|
|
43
|
+
};
|
|
44
|
+
readonly exec: {
|
|
45
|
+
readonly name: "__re_exec";
|
|
46
|
+
readonly params: readonly [{
|
|
47
|
+
readonly kind: "i32";
|
|
48
|
+
}, {
|
|
49
|
+
readonly kind: "i32";
|
|
50
|
+
}, {
|
|
51
|
+
readonly kind: "i32";
|
|
52
|
+
}, {
|
|
53
|
+
readonly kind: "i32";
|
|
54
|
+
}];
|
|
55
|
+
readonly results: readonly [{
|
|
56
|
+
readonly kind: "i32";
|
|
57
|
+
}];
|
|
58
|
+
};
|
|
59
|
+
readonly free: {
|
|
60
|
+
readonly name: "__re_free";
|
|
61
|
+
readonly params: readonly [{
|
|
62
|
+
readonly kind: "i32";
|
|
63
|
+
}];
|
|
64
|
+
readonly results: readonly [];
|
|
65
|
+
};
|
|
66
|
+
readonly groupStart: {
|
|
67
|
+
readonly name: "__re_group_start";
|
|
68
|
+
readonly params: readonly [{
|
|
69
|
+
readonly kind: "i32";
|
|
70
|
+
}, {
|
|
71
|
+
readonly kind: "i32";
|
|
72
|
+
}];
|
|
73
|
+
readonly results: readonly [{
|
|
74
|
+
readonly kind: "i32";
|
|
75
|
+
}];
|
|
76
|
+
};
|
|
77
|
+
readonly groupEnd: {
|
|
78
|
+
readonly name: "__re_group_end";
|
|
79
|
+
readonly params: readonly [{
|
|
80
|
+
readonly kind: "i32";
|
|
81
|
+
}, {
|
|
82
|
+
readonly kind: "i32";
|
|
83
|
+
}];
|
|
84
|
+
readonly results: readonly [{
|
|
85
|
+
readonly kind: "i32";
|
|
86
|
+
}];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export declare function quickJsLibRegexpEngineConfig(): StandaloneRegExpEngineConfig;
|
|
90
|
+
export declare function nativeLiteralRegExpEngineConfig(): StandaloneRegExpEngineConfig;
|
|
91
|
+
export declare function getStandaloneRegExpEngine(state: StandaloneRegExpEngineState): StandaloneRegExpEngineConfig | null;
|
|
92
|
+
export declare function hasStandaloneRegExpEngine(state: StandaloneRegExpEngineState): boolean;
|
|
93
|
+
export declare function isGlobalRegExpIdentifier(ctx: CodegenContext, ident: ts.Identifier): boolean;
|
|
94
|
+
export declare function isGlobalRegExpType(type: ts.Type): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* EscapeRegExpPattern (ECMA-262 §22.2.6.13.1), computed at compile time —
|
|
97
|
+
* standalone patterns are always static. The escaped form must let
|
|
98
|
+
* `"/" + escaped + "/" + flags` reparse as an equivalent
|
|
99
|
+
* RegularExpressionLiteral:
|
|
100
|
+
* - empty pattern → `"(?:)"` (a bare `//` would lex as a comment);
|
|
101
|
+
* - unescaped `/` outside a class → `\/` (escaped or in-class occurrences
|
|
102
|
+
* already reparse);
|
|
103
|
+
* - LineTerminators → their escape sequences (they can enter via
|
|
104
|
+
* `new RegExp("\n")` and would terminate the literal otherwise).
|
|
105
|
+
*/
|
|
106
|
+
export declare function escapeRegExpPattern(pattern: string): string;
|
|
107
|
+
export declare function compileStandaloneRegExpLiteral(ctx: CodegenContext, fctx: FunctionContext, pattern: string, flags: string, node: ts.Node): ValType | null;
|
|
108
|
+
export declare function compileStandaloneRegExpConstructor(ctx: CodegenContext, fctx: FunctionContext, args: readonly ts.Expression[], node: ts.Node): ValType | null;
|
|
109
|
+
/**
|
|
110
|
+
* (#2175 S1) Brand-recovery prologue for a *dynamic* (externref) RegExp `this`.
|
|
111
|
+
*
|
|
112
|
+
* The reflective forms — `RegExp.prototype.test.call(re, s)`,
|
|
113
|
+
* `re[Symbol.match](s)`, the `flags`-getter via a property descriptor — receive
|
|
114
|
+
* the receiver as an opaque externref through a closure call, so there is no
|
|
115
|
+
* receiver *expression* to brand-narrow at a syntactic site. This helper does
|
|
116
|
+
* the identical externref→`$NativeRegExp` narrowing that the static fast path's
|
|
117
|
+
* `loadStandaloneRegExpStruct` performs on an expression (the
|
|
118
|
+
* `any.convert_extern` + `ref.test` + `ref.cast` body), but driven from a local
|
|
119
|
+
* holding the externref `this`. On a non-RegExp `this` it throws a **catchable
|
|
120
|
+
* `TypeError`** (§22.2.6.4.1 RegExpHasFlag step 2) via the shared exception-tag
|
|
121
|
+
* path — never a raw `ref.cast` trap (mirrors #2100 M2).
|
|
122
|
+
*
|
|
123
|
+
* Leaves nothing on the stack; returns the local holding the cast struct and the
|
|
124
|
+
* struct type index for the caller's field reads / engine calls. Returns `null`
|
|
125
|
+
* only if the standalone RegExp struct can't be registered (defensive — it
|
|
126
|
+
* always can under standalone).
|
|
127
|
+
*/
|
|
128
|
+
export declare function recoverRegExpStructFromExternref(ctx: CodegenContext, fctx: FunctionContext, thisExternLocal: number): {
|
|
129
|
+
regexpLocal: number;
|
|
130
|
+
structTypeIdx: number;
|
|
131
|
+
} | null;
|
|
132
|
+
export declare function tryCompileStandaloneRegExpTest(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): InnerResult | undefined;
|
|
133
|
+
/**
|
|
134
|
+
* `RegExp.prototype.exec(str)` in standalone mode (#1539 Phase 2b).
|
|
135
|
+
*
|
|
136
|
+
* This slice materializes the capture array for backend-created static RegExp
|
|
137
|
+
* values with non-global/non-sticky flags. `g`/`y` require observable
|
|
138
|
+
* `lastIndex` mutation and stay refused until the dedicated lastIndex slice.
|
|
139
|
+
*/
|
|
140
|
+
export declare function tryCompileStandaloneRegExpExec(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): InnerResult | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* `String.prototype.search(regexp)` in standalone mode (#1539 Phase 2b).
|
|
143
|
+
*
|
|
144
|
+
* Per ECMA-262 §22.1.3.13 + §22.2.6.13 (`RegExp.prototype[@@search]`): search
|
|
145
|
+
* sets `lastIndex` to 0, runs `RegExpExec`, then restores `lastIndex`, returning
|
|
146
|
+
* the match's `.index` or `-1` on no match. It is unaffected by the `g` flag and
|
|
147
|
+
* never advances. Here the subject (string) is the receiver and the RegExp is
|
|
148
|
+
* the argument: `"abc".search(/b/)`. The argument must be a backend-created
|
|
149
|
+
* static RegExp; a string argument (which the spec coerces to `new RegExp(arg)`)
|
|
150
|
+
* stays a narrowed refusal in standalone for this slice.
|
|
151
|
+
*
|
|
152
|
+
* Returns f64 (the index, or -1). `caps[0]` holds the whole-match start.
|
|
153
|
+
* Never returns `VOID_RESULT`, so the type stays `ValType | null | undefined`
|
|
154
|
+
* to match the `compileNativeStringMethodCall` caller contract.
|
|
155
|
+
*/
|
|
156
|
+
export declare function tryCompileStandaloneStringSearch(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
157
|
+
/**
|
|
158
|
+
* `String.prototype.match(regexp)` in standalone mode (#1539 Phase 2b).
|
|
159
|
+
*
|
|
160
|
+
* Non-global static RegExp arguments share the same result shape as `.exec`.
|
|
161
|
+
* Global `match` returns an all-matches array and sticky/global lastIndex
|
|
162
|
+
* details are intentionally left to the next capture-array slice.
|
|
163
|
+
*/
|
|
164
|
+
export declare function tryCompileStandaloneStringMatch(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* `String.prototype.matchAll(/re/g)` in standalone mode (#2161).
|
|
167
|
+
*
|
|
168
|
+
* §22.1.3.13 / §22.2.6.9: returns a RegExpStringIterator yielding the **full
|
|
169
|
+
* match array** (with capture groups, `.index`, `.input`) for every match. The
|
|
170
|
+
* native engine already builds per-match arrays via `__regex_capture_array`
|
|
171
|
+
* (used by `exec` / non-global `match`); `__regex_match_all_arrays` drives the
|
|
172
|
+
* eager AdvanceStringIndex loop collecting those capture-arrays into a vec. The
|
|
173
|
+
* vec is iterable by the native-vec for-of / spread consumers (#2169), so
|
|
174
|
+
* `for (const m of s.matchAll(re))` and `[...s.matchAll(re)]` both work without
|
|
175
|
+
* a JS host.
|
|
176
|
+
*
|
|
177
|
+
* Narrowed slice: requires a static global (`g`) RegExp value. matchAll on a
|
|
178
|
+
* non-global regex is a runtime TypeError (§22.1.3.13 step 4.a) — left to the
|
|
179
|
+
* host/refusal path rather than mis-modelled. String-arg coercion
|
|
180
|
+
* (`s.matchAll("x")` → `new RegExp("x","g")`) and dynamic flags fall through.
|
|
181
|
+
*/
|
|
182
|
+
export declare function tryCompileStandaloneStringMatchAll(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
183
|
+
/**
|
|
184
|
+
* `String.prototype.replace(re, "str")` / `String.prototype.replaceAll(re,
|
|
185
|
+
* "str")` in standalone mode (#1539 Phase 2c) — **literal replacement string
|
|
186
|
+
* only**.
|
|
187
|
+
*
|
|
188
|
+
* Per ECMA-262 §22.1.3.19 / §22.2.6.11 (`RegExp.prototype[@@replace]`): walk
|
|
189
|
+
* the subject, replacing each match (all matches when the regex has the `g`
|
|
190
|
+
* flag or the method is `replaceAll`; otherwise just the first) with the
|
|
191
|
+
* replacement string, returning the rebuilt string. The result is a
|
|
192
|
+
* `$NativeString` — no array boundary, no host import.
|
|
193
|
+
*
|
|
194
|
+
* Refused (left to the narrowed gate): `$n`/`$&`/`$\``/`$'`/`$<name>`
|
|
195
|
+
* substitution patterns and function replacers (Phase 2c follow-up — they need
|
|
196
|
+
* capture-group materialization / closure dispatch), and `replaceAll` with a
|
|
197
|
+
* non-global regex (which is a runtime `TypeError` per spec; let the host path
|
|
198
|
+
* handle that diagnostic rather than mis-modelling it here).
|
|
199
|
+
*/
|
|
200
|
+
export declare function tryCompileStandaloneStringReplace(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
201
|
+
/**
|
|
202
|
+
* `String.prototype.split(re)` in standalone mode (#1539 Phase 2c) —
|
|
203
|
+
* non-capturing, non-nullable static RegExp separator only.
|
|
204
|
+
*
|
|
205
|
+
* Capturing-group split has extra result interleaving semantics, and nullable
|
|
206
|
+
* separators need the full SplitMatch/AdvanceStringIndex edge-case handling.
|
|
207
|
+
* Both stay narrowed refusals until the capture-array/string-method follow-up.
|
|
208
|
+
*/
|
|
209
|
+
export declare function tryCompileStandaloneStringSplit(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
210
|
+
/**
|
|
211
|
+
* `re[Symbol.match](str)` / `re[Symbol.matchAll](str)` / `re[Symbol.search](str)`
|
|
212
|
+
* — the explicit well-known-symbol protocol forms (§22.2.6) — in standalone
|
|
213
|
+
* mode (#2161).
|
|
214
|
+
*
|
|
215
|
+
* These are the operand-swapped duals of `String.prototype.match/matchAll/
|
|
216
|
+
* search`: the RegExp is the **receiver** and the string is the **argument**.
|
|
217
|
+
* The native engine is operand-order agnostic (the lower-level emitters take an
|
|
218
|
+
* explicit regex expression + subject expression), so each method reuses the
|
|
219
|
+
* exact same core that backs the corresponding String.prototype method — there
|
|
220
|
+
* is no separate engine path and no host import.
|
|
221
|
+
*
|
|
222
|
+
* Gating mirrors the String.prototype path: the receiver must be a static /
|
|
223
|
+
* backend-created RegExp value (so the pattern + flags are known at compile
|
|
224
|
+
* time) and the (first) argument must be string-like. Dynamic-flag receivers
|
|
225
|
+
* and string-coercion arguments return `undefined`, so the caller falls through
|
|
226
|
+
* to the existing `__regex_symbol_call` host import (JS-host mode) or the
|
|
227
|
+
* standalone refusal.
|
|
228
|
+
*
|
|
229
|
+
* `@@replace` / `@@split` carry a second operand (replacement / limit). They
|
|
230
|
+
* reuse the same operand-explicit cores as `String.prototype.replace`/`split`
|
|
231
|
+
* with the operands swapped (regex = receiver, subject = arg[0]).
|
|
232
|
+
*
|
|
233
|
+
* `methodName` is the `@@<id>` sentinel the element-access dispatcher resolved
|
|
234
|
+
* for the computed Symbol key (e.g. `"@@match"`).
|
|
235
|
+
*/
|
|
236
|
+
export declare function tryCompileStandaloneRegExpSymbolCall(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, regexExpr: ts.Expression, methodName: string): ValType | null | undefined;
|
|
237
|
+
/**
|
|
238
|
+
* The property names the standalone backend answers natively on RegExp
|
|
239
|
+
* receivers. The import scan in index.ts consults this set so it never
|
|
240
|
+
* registers an `env.RegExp_get_*` host import for these reads under
|
|
241
|
+
* `--target standalone` (the acceptance criterion of #1914: no `env.RegExp_*`
|
|
242
|
+
* leaks). Keep in sync with {@link tryCompileStandaloneRegExpPropertyRead}.
|
|
243
|
+
*/
|
|
244
|
+
export declare const STANDALONE_REGEXP_REFLECTION_PROPS: ReadonlySet<string>;
|
|
245
|
+
/**
|
|
246
|
+
* Property READS on standalone RegExp receivers (#1914).
|
|
247
|
+
*
|
|
248
|
+
* - `.source` → struct field 4 (stored pre-escaped per §22.2.6.13.1).
|
|
249
|
+
* - `.flags` → `__regex_flags_str(flags)` building the d-g-i-m-s-u-v-y string
|
|
250
|
+
* from the bitfield (§22.2.6.4).
|
|
251
|
+
* - flag booleans (`.global`, `.ignoreCase`, …) → `(flags & bit) != 0`
|
|
252
|
+
* (§22.2.6.5–.12 RegExpHasFlag).
|
|
253
|
+
* - `.lastIndex` → struct field 5 (f64).
|
|
254
|
+
*
|
|
255
|
+
* Returns `undefined` when the receiver/property is not a standalone RegExp
|
|
256
|
+
* reflection read (caller falls through), `null` after reporting a narrowed
|
|
257
|
+
* refusal, or the result ValType.
|
|
258
|
+
*/
|
|
259
|
+
export declare function tryCompileStandaloneRegExpPropertyRead(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Shared core for §22.2.6.14 `RegExp.prototype.toString()` rendering of a
|
|
262
|
+
* static / backend-created RegExp *receiver expression* — `"/" + source + "/" +
|
|
263
|
+
* flags` — emitting a native string with ZERO host imports.
|
|
264
|
+
*
|
|
265
|
+
* The spec result is `"/" + R.[[OriginalSource]] + "/" + R.[[OriginalFlags]]`,
|
|
266
|
+
* both of which the native backend already produces (the struct's `source`
|
|
267
|
+
* field is stored in the spec-escaped §22.2.6.13.1 form, and `__regex_flags_str`
|
|
268
|
+
* builds the d-g-i-m-s-u-v-y flag string). In standalone / nativeStrings mode
|
|
269
|
+
* there is no JS host, so the generic ref→string coercion path leaked
|
|
270
|
+
* `env::Object_toString` (or null-deref'd). This composes the two native field
|
|
271
|
+
* reads with `__str_concat`.
|
|
272
|
+
*
|
|
273
|
+
* Used by the `re.toString()` method dispatch (`tryCompileStandaloneRegExpToString`)
|
|
274
|
+
* AND by the value→string coercion paths (`String(re)`, `` `${re}` ``) which
|
|
275
|
+
* would otherwise null-deref or yield `"[object Object]"` (#2161).
|
|
276
|
+
*
|
|
277
|
+
* Returns the emitted native-string `ValType`, `null` after a reported refusal
|
|
278
|
+
* (e.g. a non-backend RegExp), or `undefined` when the expression is not a
|
|
279
|
+
* static / backend-created RegExp the caller should keep falling through for.
|
|
280
|
+
*/
|
|
281
|
+
export declare function emitStandaloneRegExpToStringFromExpr(ctx: CodegenContext, fctx: FunctionContext, regexpExpr: ts.Expression): ValType | null | undefined;
|
|
282
|
+
export declare function tryCompileStandaloneRegExpToString(ctx: CodegenContext, fctx: FunctionContext, expr: ts.CallExpression, propAccess: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
283
|
+
/**
|
|
284
|
+
* (#2175 S1) Shared RegExp reflection field-read sequence, factored out of
|
|
285
|
+
* `tryCompileStandaloneRegExpPropertyRead` so the native-method-getter closures
|
|
286
|
+
* (#2175) emit the *identical* getter body off a recovered struct local. The
|
|
287
|
+
* caller has already pushed nothing on the stack; this helper pushes the
|
|
288
|
+
* `local.get regexpLocal` itself and the field read, returning the getter's
|
|
289
|
+
* result ValType. Static path callers route through here byte-for-byte.
|
|
290
|
+
*/
|
|
291
|
+
export declare function emitRegExpReflectionFieldRead(ctx: CodegenContext, fctx: FunctionContext, propName: string, regexpLocal: number, structTypeIdx: number): ValType;
|
|
292
|
+
/**
|
|
293
|
+
* (#2175 S1) RegExp `.test` driven by a recovered struct local + a subject
|
|
294
|
+
* string local, for the native-method-closure body where there is no receiver
|
|
295
|
+
* *expression* (the reflective `RegExp.prototype.test.call(re, s)` /
|
|
296
|
+
* `re[Symbol.match]`-adjacent forms). Self-contained — does NOT route through
|
|
297
|
+
* `emitRegexSearchCall` (which is expression-driven) so the static fast path
|
|
298
|
+
* stays byte-identical. Returns the i32 match flag (1/0) on the stack.
|
|
299
|
+
*
|
|
300
|
+
* `subjStrLocal` holds a flattened native-string struct ref (the closure body
|
|
301
|
+
* flattens its externref arg before calling). The search starts at index 0 and
|
|
302
|
+
* honours stickiness like the non-g/y `.test` static path; lastIndex mutation
|
|
303
|
+
* for g/y reflective receivers is deferred (the dynamic receiver makes the
|
|
304
|
+
* static flag analysis unavailable — a conservative, spec-observable subset).
|
|
305
|
+
*/
|
|
306
|
+
export declare function emitRegExpTestFromLocals(ctx: CodegenContext, fctx: FunctionContext, regexpLocal: number, structTypeIdx: number, subjStrLocal: number): void;
|
|
307
|
+
/** (#2175 S1) The standalone-RegExp struct type index, for the proto populator. */
|
|
308
|
+
export declare function getStandaloneRegExpStructTypeIdx(ctx: CodegenContext): number;
|
|
309
|
+
/**
|
|
310
|
+
* (#2175 S1) Register the RegExp builtin-prototype glue with the shared
|
|
311
|
+
* `native-proto` core. Idempotent — safe to call from every reflective entry.
|
|
312
|
+
* Returns the RegExp brand, or `undefined` if the brand band isn't available
|
|
313
|
+
* (defensive — it always is).
|
|
314
|
+
*/
|
|
315
|
+
export declare function ensureRegExpNativeProtoGlue(ctx: CodegenContext): number | undefined;
|
|
316
|
+
/**
|
|
317
|
+
* `re.lastIndex = value` on a standalone RegExp receiver (#1914).
|
|
318
|
+
*
|
|
319
|
+
* [[LastIndex]] is a plain writable data property (§22.2.7.1); the struct
|
|
320
|
+
* stores it as f64. The spec defers coercion to exec's ToLength, so only
|
|
321
|
+
* numeric writes are accepted here — non-numeric RHS values are a narrowed
|
|
322
|
+
* refusal rather than a silently mis-modelled store. Leaves the RHS f64 on
|
|
323
|
+
* the stack (assignment-expression value).
|
|
324
|
+
*/
|
|
325
|
+
export declare function tryCompileStandaloneRegExpLastIndexWrite(ctx: CodegenContext, fctx: FunctionContext, target: ts.PropertyAccessExpression, value: ts.Expression): ValType | null | undefined;
|
|
326
|
+
/**
|
|
327
|
+
* `.index` / `.input` reads on standalone exec/match results (#1914).
|
|
328
|
+
*
|
|
329
|
+
* The receiver's static TS type (`RegExpExecArray` / `RegExpMatchArray`) is
|
|
330
|
+
* the routing signal; the runtime value is the `$__regexp_match_vec` subtype
|
|
331
|
+
* every standalone exec/match constructs (`__regex_capture_array`). Receivers
|
|
332
|
+
* statically typed as the base nstr vec are `ref.cast` down — construction
|
|
333
|
+
* provenance guarantees the cast succeeds; a null result traps, matching the
|
|
334
|
+
* TypeError a member read on `null` must produce.
|
|
335
|
+
*/
|
|
336
|
+
export declare function tryCompileStandaloneRegExpMatchResultRead(ctx: CodegenContext, fctx: FunctionContext, expr: ts.PropertyAccessExpression): ValType | null | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Module-global type inference for `var m = re.exec(s)` under standalone
|
|
339
|
+
* (#1914). Without this the global widens to externref and indexed reads
|
|
340
|
+
* route through the native `__extern_get_idx`, which only recognises the
|
|
341
|
+
* open-object `$ObjVec` — a typed match-vec read back from externref returns
|
|
342
|
+
* null and the comparison traps in `__str_flatten` (the
|
|
343
|
+
* `null_deref __str_flatten` test262 bucket).
|
|
344
|
+
*
|
|
345
|
+
* Returns `ref_null $__regexp_match_vec` only when the initializer is a
|
|
346
|
+
* backend exec/match call AND every other write to the var in the file is
|
|
347
|
+
* also one (or null/undefined) — any foreign write keeps the externref
|
|
348
|
+
* widening so the precise global type can never reject a store.
|
|
349
|
+
*/
|
|
350
|
+
export declare function inferStandaloneRegExpMatchGlobalType(ctx: CodegenContext, decl: ts.VariableDeclaration): ValType | null;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { CodegenContext } from '../context/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* The 8 built-in JS Error constructors that Phase 1 supports as Wasm-native
|
|
4
|
+
* struct construction in WASI mode. Order matches the order in which test262
|
|
5
|
+
* tests typically reference them.
|
|
6
|
+
*/
|
|
7
|
+
declare const WASI_ERROR_NAMES: readonly ["Error", "TypeError", "RangeError", "SyntaxError", "URIError", "EvalError", "ReferenceError", "AggregateError"];
|
|
8
|
+
export type WasiErrorName = (typeof WASI_ERROR_NAMES)[number];
|
|
9
|
+
/** Returns true if `name` is one of the 8 Error constructors handled by Phase 1. */
|
|
10
|
+
export declare function isWasiErrorName(name: string): name is WasiErrorName;
|
|
11
|
+
/**
|
|
12
|
+
* Get or register the `$Error_struct` WasmGC type. Idempotent — returns the
|
|
13
|
+
* cached type index on subsequent calls.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getOrRegisterErrorStructType(ctx: CodegenContext): number;
|
|
16
|
+
/**
|
|
17
|
+
* Emit an internal Wasm function `__new_<errorName>` that constructs a new
|
|
18
|
+
* `$Error_struct` and returns it as externref. The function takes `argCount`
|
|
19
|
+
* externref params (the constructor arguments seen at call sites — typically
|
|
20
|
+
* 0 or 1 for `new Error(msg)`).
|
|
21
|
+
*
|
|
22
|
+
* Idempotent — does nothing if `__new_<errorName>` is already registered
|
|
23
|
+
* (whether as a host import or a previously-emitted internal function).
|
|
24
|
+
*
|
|
25
|
+
* #1536 Phase 2 — the `$name` field is now materialized with the error
|
|
26
|
+
* class's name string ("Error" / "TypeError" / …) instead of the Phase-1
|
|
27
|
+
* `ref.null extern` placeholder, so `err.name` reads the correct value in
|
|
28
|
+
* standalone mode (the property-access fast path in `property-access.ts`
|
|
29
|
+
* already does `struct.get $Error_struct[2]` for `.name` under
|
|
30
|
+
* `ctx.wasi || ctx.standalone`). The constant is materialized via the
|
|
31
|
+
* shared `stringConstantExternrefInstrs` dual-mode helper: nativeStrings
|
|
32
|
+
* mode builds the FlatString struct inline + `extern.convert_any`;
|
|
33
|
+
* host-strings mode emits a `global.get` of the interned string constant.
|
|
34
|
+
* The string is registered via `addStringConstantGlobal` first so the
|
|
35
|
+
* helper finds it in `ctx.stringGlobalMap`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function emitWasiErrorConstructor(ctx: CodegenContext, errorName: WasiErrorName, argCount: number): void;
|
|
38
|
+
export {};
|