@loopdive/js2 0.57.0 → 0.59.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/README.md +1 -1
- package/dist/cli.js +24 -14
- package/dist/codegen/array-element-typing.d.ts +28 -14
- package/dist/codegen/context/types.d.ts +68 -10
- package/dist/codegen/fnctor-escape-gate.d.ts +82 -0
- package/dist/codegen/host-import-allowlist.d.ts +2 -2
- package/dist/codegen/index.d.ts +53 -1
- package/dist/codegen/literals.d.ts +27 -0
- package/dist/codegen/member-set-dispatch.d.ts +2 -2
- package/dist/codegen/property-access.d.ts +2 -2
- package/dist/codegen/registry/imports.d.ts +19 -1
- package/dist/codegen/shared.d.ts +24 -0
- package/dist/codegen/statements/loops.d.ts +30 -0
- package/dist/compiler.d.ts +11 -0
- package/dist/index.d.ts +42 -12
- package/dist/index.js +41 -40
- package/dist/ir/types.d.ts +1 -0
- package/dist/{runtime-C-4q_KwU.js → runtime-UuI75J3h.js} +81892 -80429
- package/dist/runtime.js +9 -9
- package/package.json +45 -42
package/dist/compiler.d.ts
CHANGED
|
@@ -2,6 +2,17 @@ import { IncrementalLanguageService } from './checker/index.js';
|
|
|
2
2
|
import { CompileOptions, CompileResult } from './index.js';
|
|
3
3
|
export { compileToObjectSource } from './compiler/output.js';
|
|
4
4
|
export type { ObjectCompileResult } from './compiler/output.js';
|
|
5
|
+
/**
|
|
6
|
+
* #2771 — does the entry source statically import (or `require`) a RELATIVE
|
|
7
|
+
* module (`./x` / `../x`)? The single-source `compile()` path reads exactly one
|
|
8
|
+
* file and strips every import in `preprocessImports`, so a relative import is
|
|
9
|
+
* silently unresolved — its bindings lower to bogus `env.*` host imports (which
|
|
10
|
+
* the WASI strict-no-host gate then rejects). The CLI uses this to route such an
|
|
11
|
+
* entry to the multi-file bundler (`compileProject`), which resolves the
|
|
12
|
+
* relative deps through the TS program. Package / `node:` / bare-specifier
|
|
13
|
+
* imports are NOT relative and stay on the single-source path (byte-neutral).
|
|
14
|
+
*/
|
|
15
|
+
export declare function entryHasRelativeImports(source: string): boolean;
|
|
5
16
|
/**
|
|
6
17
|
* #2657 — the source-import module string for js2wasm's raw linear-memory access
|
|
7
18
|
* intrinsics (`store32`/`load32`/`store8`/`load8`). These are NOT WASI host
|
package/dist/index.d.ts
CHANGED
|
@@ -315,19 +315,48 @@ export interface CompileOptions {
|
|
|
315
315
|
* Default: false (calls to fs.readFileSync / fs.writeFileSync raise a compile error). */
|
|
316
316
|
allowFs?: boolean;
|
|
317
317
|
/**
|
|
318
|
-
* #
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
* `
|
|
322
|
-
* `
|
|
323
|
-
*
|
|
324
|
-
*
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
318
|
+
* (#2796) Differential-test-harness fidelity flag. In the default JS-host
|
|
319
|
+
* (WasmGC) target, top-level module code runs via the wasm `start` section —
|
|
320
|
+
* i.e. DURING `WebAssembly.instantiate`, BEFORE the host can call
|
|
321
|
+
* `setExports(instance.exports)`. Top-level code that introspects WasmGC
|
|
322
|
+
* structs (`for…in` / `Object.keys` over a runtime-shaped object) needs the
|
|
323
|
+
* `__struct_field_names` / `__sget_*` exports, which only exist once the
|
|
324
|
+
* instance is constructed — so during the start section they resolve to
|
|
325
|
+
* nothing and a `for…in` enumerates zero keys. The standalone/WASI path does
|
|
326
|
+
* NOT hit this: it runs top-level code via an explicitly-called `_start`
|
|
327
|
+
* export AFTER instantiation, when every export is reachable.
|
|
328
|
+
*
|
|
329
|
+
* When `true`, emit the top-level `__module_init` as an EXPORT and do NOT run
|
|
330
|
+
* it via the wasm `start` section, so the host can invoke
|
|
331
|
+
* `instance.exports.__module_init()` AFTER wiring `setExports` — symmetric
|
|
332
|
+
* with the standalone `_start` model. The differential-test harness
|
|
333
|
+
* (`scripts/diff-test.ts`) sets this so the HOST lane runs top-level code with
|
|
334
|
+
* the same fully-wired runtime the standalone lane uses, rather than tripping
|
|
335
|
+
* over an exports-timing artifact of the harness. Default `false` →
|
|
336
|
+
* byte-identical output (top-level runs in the wasm `start` section) for every
|
|
337
|
+
* other consumer (website, playground, test262, library users).
|
|
338
|
+
*/
|
|
339
|
+
deferTopLevelInit?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* #2783 — general `--link <namespace>` dynamic-linking axis (the ONLY
|
|
342
|
+
* link-vs-inline control; the old `linkNodeShims` boolean was removed). Each
|
|
343
|
+
* listed namespace is left as a **link-time import** (satisfied at
|
|
344
|
+
* instantiation by a preloaded provider module, e.g.
|
|
345
|
+
* `wasmtime --preload node:fs=node-fs.wasm`) instead of being inline-lowered to
|
|
346
|
+
* a self-contained module. "Leave-as-import" is the universal capability (any
|
|
347
|
+
* external namespace can be a wasm import); "inline-lower" is the special
|
|
348
|
+
* capability the compiler only has for a known few (`node:fs` fd IO). So for an
|
|
349
|
+
* arbitrary namespace `link: ["acme:telemetry"]` simply permits its imports
|
|
350
|
+
* past the strict `--no-host-imports` / WASI gate; for `node:fs` it
|
|
351
|
+
* additionally selects the import-and-link std-IO path (the user module imports
|
|
352
|
+
* `readSync`/`writeSync` + its linear memory from `node:fs` and carries no
|
|
353
|
+
* `wasi_snapshot_preview1` import for stream IO; console.log /
|
|
354
|
+
* process.std*.write lower to `writeSync(1|2, …)`, stdin is `readSync(0, …)`).
|
|
355
|
+
*
|
|
356
|
+
* WASI-gated: ignored for non-WASI targets. Default empty — every namespace
|
|
357
|
+
* stays standalone / inline-lowered. CLI: `--link <ns>` (repeatable).
|
|
329
358
|
*/
|
|
330
|
-
|
|
359
|
+
link?: string[];
|
|
331
360
|
/**
|
|
332
361
|
* Node API emulation (#2603). Opt-in via `--emulate node`. When set, the
|
|
333
362
|
* checker is given an ambient `process` declaration so Node globals js2wasm
|
|
@@ -476,6 +505,7 @@ export declare function createIncrementalCompiler(defaultOptions?: CompileOption
|
|
|
476
505
|
compile: (source: string, options?: CompileOptions) => Promise<CompileResult>;
|
|
477
506
|
dispose: () => void;
|
|
478
507
|
};
|
|
508
|
+
export { entryHasRelativeImports } from './compiler.js';
|
|
479
509
|
export { getBarePackageName, ModuleResolver, resolveAllImports } from './resolve.js';
|
|
480
510
|
export { preloadLibFiles } from './checker/index.js';
|
|
481
511
|
export { getEntryExportNames, treeshake } from './treeshake.js';
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import { i as isKnownLibName, g as getLibSourceFile, a as getDefaultEnvironment, r as rewriteCjsRequire, f as forEachChild, c as compileSource, b as
|
|
3
|
-
import {
|
|
2
|
+
import { i as isKnownLibName, g as getLibSourceFile, a as getDefaultEnvironment, r as rewriteCjsRequire, f as forEachChild, e as entryHasRelativeImports, c as compileSource, b as compileMultiSource, d as buildImports, h as compileFilesSource, j as compileToObjectSource } from "./runtime-UuI75J3h.js";
|
|
3
|
+
import { k, l, m, n, o, p, q, s, t } from "./runtime-UuI75J3h.js";
|
|
4
4
|
import ts from "typescript";
|
|
5
5
|
class IncrementalLanguageService {
|
|
6
6
|
currentSource = "";
|
|
@@ -549,61 +549,61 @@ const RUNTIME_RECGROUP_TYPE_NAMES = [
|
|
|
549
549
|
];
|
|
550
550
|
const RUNTIME_RECGROUP_ABI_VERSION = 1;
|
|
551
551
|
const RUNTIME_NAME_SET = new Set(RUNTIME_RECGROUP_TYPE_NAMES);
|
|
552
|
-
function typeDefName(
|
|
553
|
-
switch (
|
|
552
|
+
function typeDefName(t2) {
|
|
553
|
+
switch (t2.kind) {
|
|
554
554
|
case "func":
|
|
555
555
|
case "struct":
|
|
556
556
|
case "array":
|
|
557
|
-
return
|
|
557
|
+
return t2.name;
|
|
558
558
|
case "sub":
|
|
559
|
-
return
|
|
559
|
+
return t2.name;
|
|
560
560
|
case "rec":
|
|
561
561
|
return void 0;
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
|
-
function valTypeToken(
|
|
565
|
-
switch (
|
|
564
|
+
function valTypeToken(t2, localOf) {
|
|
565
|
+
switch (t2.kind) {
|
|
566
566
|
case "ref":
|
|
567
567
|
case "ref_null": {
|
|
568
|
-
const local = localOf(
|
|
569
|
-
const nul =
|
|
568
|
+
const local = localOf(t2.typeIdx);
|
|
569
|
+
const nul = t2.kind === "ref_null" ? "n" : "";
|
|
570
570
|
if (local !== void 0) return `${nul}r${local}`;
|
|
571
571
|
return `${nul}x`;
|
|
572
572
|
}
|
|
573
573
|
case "i32":
|
|
574
|
-
return
|
|
574
|
+
return t2.boolean ? "i32b" : "i32";
|
|
575
575
|
case "i64":
|
|
576
|
-
return
|
|
576
|
+
return t2.bigint ? "i64big" : "i64";
|
|
577
577
|
default:
|
|
578
|
-
return
|
|
578
|
+
return t2.kind;
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
581
|
function fieldToken(f, localOf) {
|
|
582
582
|
return `${f.mutable ? "m" : ""}${valTypeToken(f.type, localOf)}`;
|
|
583
583
|
}
|
|
584
|
-
function structuralToken(
|
|
585
|
-
switch (
|
|
584
|
+
function structuralToken(t2, localOf) {
|
|
585
|
+
switch (t2.kind) {
|
|
586
586
|
case "func": {
|
|
587
|
-
const p2 =
|
|
588
|
-
const r =
|
|
587
|
+
const p2 = t2.params.map((v) => valTypeToken(v, localOf)).join(",");
|
|
588
|
+
const r = t2.results.map((v) => valTypeToken(v, localOf)).join(",");
|
|
589
589
|
return `func(${p2})->(${r})`;
|
|
590
590
|
}
|
|
591
591
|
case "struct": {
|
|
592
|
-
const sup =
|
|
593
|
-
const local = localOf(
|
|
594
|
-
return local !== void 0 ? `sub r${local}${
|
|
592
|
+
const sup = t2.superTypeIdx !== void 0 && t2.superTypeIdx >= 0 ? (() => {
|
|
593
|
+
const local = localOf(t2.superTypeIdx);
|
|
594
|
+
return local !== void 0 ? `sub r${local}${t2.final ? "!" : ""} ` : `sub x${t2.final ? "!" : ""} `;
|
|
595
595
|
})() : "";
|
|
596
|
-
const fields =
|
|
596
|
+
const fields = t2.fields.map((f) => fieldToken(f, localOf)).join(";");
|
|
597
597
|
return `${sup}struct{${fields}}`;
|
|
598
598
|
}
|
|
599
599
|
case "array":
|
|
600
|
-
return `array<${
|
|
600
|
+
return `array<${t2.mutable ? "m" : ""}${valTypeToken(t2.element, localOf)}>`;
|
|
601
601
|
case "sub": {
|
|
602
|
-
const sup =
|
|
603
|
-
const local = localOf(
|
|
604
|
-
return local !== void 0 ? `sub r${local}${
|
|
605
|
-
})() :
|
|
606
|
-
return `${sup}${structuralToken(
|
|
602
|
+
const sup = t2.superType !== null ? (() => {
|
|
603
|
+
const local = localOf(t2.superType);
|
|
604
|
+
return local !== void 0 ? `sub r${local}${t2.final ? "!" : ""} ` : `sub x${t2.final ? "!" : ""} `;
|
|
605
|
+
})() : t2.final ? "final " : "";
|
|
606
|
+
return `${sup}${structuralToken(t2.type, localOf)}`;
|
|
607
607
|
}
|
|
608
608
|
}
|
|
609
609
|
}
|
|
@@ -631,11 +631,11 @@ function extractRuntimeGroup(mod) {
|
|
|
631
631
|
const out = [];
|
|
632
632
|
const types = mod.types;
|
|
633
633
|
for (let i = 0; i < types.length; i++) {
|
|
634
|
-
const
|
|
635
|
-
if (
|
|
636
|
-
const name = typeDefName(
|
|
634
|
+
const t2 = types[i];
|
|
635
|
+
if (t2.kind === "rec") continue;
|
|
636
|
+
const name = typeDefName(t2);
|
|
637
637
|
if (name !== void 0 && RUNTIME_NAME_SET.has(name)) {
|
|
638
|
-
out.push({ name, absIndex: i, def:
|
|
638
|
+
out.push({ name, absIndex: i, def: t2 });
|
|
639
639
|
}
|
|
640
640
|
}
|
|
641
641
|
return out;
|
|
@@ -729,27 +729,28 @@ export {
|
|
|
729
729
|
RUNTIME_RECGROUP_ABI_VERSION,
|
|
730
730
|
RUNTIME_RECGROUP_TYPE_NAMES,
|
|
731
731
|
buildImports,
|
|
732
|
-
|
|
733
|
-
|
|
732
|
+
k as buildStringConstants,
|
|
733
|
+
l as buildWasiPolyfill,
|
|
734
734
|
canonicalHashOfTypeGroup,
|
|
735
|
-
|
|
735
|
+
m as checkPolicy,
|
|
736
736
|
compile,
|
|
737
|
-
|
|
737
|
+
n as compileAndInstantiate,
|
|
738
738
|
compileFiles,
|
|
739
739
|
compileMulti,
|
|
740
740
|
compileProject,
|
|
741
741
|
compileToObject,
|
|
742
742
|
compileToWat,
|
|
743
743
|
createIncrementalCompiler,
|
|
744
|
+
entryHasRelativeImports,
|
|
744
745
|
extractRuntimeGroup,
|
|
745
746
|
fingerprintRuntimeGroup,
|
|
746
|
-
|
|
747
|
+
o as generateWit,
|
|
747
748
|
getBarePackageName,
|
|
748
749
|
getEntryExportNames,
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
750
|
+
p as instantiateWasm,
|
|
751
|
+
q as instantiateWasmStreaming,
|
|
752
|
+
s as jsString,
|
|
753
|
+
t as preloadLibFiles,
|
|
753
754
|
resolveAllImports,
|
|
754
755
|
treeshake
|
|
755
756
|
};
|