@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.
@@ -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
- * #2625 / #2633 emit the per-module linkable `node:<mod>` shims instead of
319
- * inlining the host APIs. WASI-only (ignored for other targets). When set,
320
- * std-IO is routed through `node:fs`: the user module imports `readSync`/
321
- * `writeSync` plus its linear memory from `node:fs` and carries no
322
- * `wasi_snapshot_preview1` import for stream IO; console.log / process.std*.write
323
- * lower to `writeSync(1|2, …)` and synchronous stdin is `readSync(0, …)`. Link
324
- * against `node-fs.wasm` (or `--preload node:fs=node-fs.wasm` under wasmtime).
325
- * Default off the self-contained inline `fd_read`/`fd_write` path stays. The
326
- * bespoke `js2wasm:node-process` shim (`process.stdin.read`/`stdout_write`/…)
327
- * was retired in #2633; `process.stdin.read(buf, offset)` is no longer a
328
- * recognised API (it matched no real Node surface — use `node:fs` `readSync`).
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
- linkNodeShims?: boolean;
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 buildImports, d as compileFilesSource, e as compileMultiSource, h as compileToObjectSource } from "./runtime-C-4q_KwU.js";
3
- import { j, k, l, m, n, o, p, q, s } from "./runtime-C-4q_KwU.js";
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(t) {
553
- switch (t.kind) {
552
+ function typeDefName(t2) {
553
+ switch (t2.kind) {
554
554
  case "func":
555
555
  case "struct":
556
556
  case "array":
557
- return t.name;
557
+ return t2.name;
558
558
  case "sub":
559
- return t.name;
559
+ return t2.name;
560
560
  case "rec":
561
561
  return void 0;
562
562
  }
563
563
  }
564
- function valTypeToken(t, localOf) {
565
- switch (t.kind) {
564
+ function valTypeToken(t2, localOf) {
565
+ switch (t2.kind) {
566
566
  case "ref":
567
567
  case "ref_null": {
568
- const local = localOf(t.typeIdx);
569
- const nul = t.kind === "ref_null" ? "n" : "";
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 t.boolean ? "i32b" : "i32";
574
+ return t2.boolean ? "i32b" : "i32";
575
575
  case "i64":
576
- return t.bigint ? "i64big" : "i64";
576
+ return t2.bigint ? "i64big" : "i64";
577
577
  default:
578
- return t.kind;
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(t, localOf) {
585
- switch (t.kind) {
584
+ function structuralToken(t2, localOf) {
585
+ switch (t2.kind) {
586
586
  case "func": {
587
- const p2 = t.params.map((v) => valTypeToken(v, localOf)).join(",");
588
- const r = t.results.map((v) => valTypeToken(v, localOf)).join(",");
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 = t.superTypeIdx !== void 0 && t.superTypeIdx >= 0 ? (() => {
593
- const local = localOf(t.superTypeIdx);
594
- return local !== void 0 ? `sub r${local}${t.final ? "!" : ""} ` : `sub x${t.final ? "!" : ""} `;
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 = t.fields.map((f) => fieldToken(f, localOf)).join(";");
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<${t.mutable ? "m" : ""}${valTypeToken(t.element, localOf)}>`;
600
+ return `array<${t2.mutable ? "m" : ""}${valTypeToken(t2.element, localOf)}>`;
601
601
  case "sub": {
602
- const sup = t.superType !== null ? (() => {
603
- const local = localOf(t.superType);
604
- return local !== void 0 ? `sub r${local}${t.final ? "!" : ""} ` : `sub x${t.final ? "!" : ""} `;
605
- })() : t.final ? "final " : "";
606
- return `${sup}${structuralToken(t.type, localOf)}`;
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 t = types[i];
635
- if (t.kind === "rec") continue;
636
- const name = typeDefName(t);
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: t });
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
- j as buildStringConstants,
733
- k as buildWasiPolyfill,
732
+ k as buildStringConstants,
733
+ l as buildWasiPolyfill,
734
734
  canonicalHashOfTypeGroup,
735
- l as checkPolicy,
735
+ m as checkPolicy,
736
736
  compile,
737
- m as compileAndInstantiate,
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
- n as generateWit,
747
+ o as generateWit,
747
748
  getBarePackageName,
748
749
  getEntryExportNames,
749
- o as instantiateWasm,
750
- p as instantiateWasmStreaming,
751
- q as jsString,
752
- s as preloadLibFiles,
750
+ p as instantiateWasm,
751
+ q as instantiateWasmStreaming,
752
+ s as jsString,
753
+ t as preloadLibFiles,
753
754
  resolveAllImports,
754
755
  treeshake
755
756
  };
@@ -126,6 +126,7 @@ export interface FieldDef {
126
126
  export type ValType = {
127
127
  kind: "i32";
128
128
  boolean?: true;
129
+ symbol?: true;
129
130
  } | {
130
131
  kind: "i64";
131
132
  bigint?: boolean;