@tsrs/wasm 0.18.0-ts7.1.0-dev.20260929 → 0.20.1-ts7.1.0-beta

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 CHANGED
@@ -29,6 +29,11 @@ The command reads and writes the real file system, prints the compiler's output
29
29
  or trap (such as a stack overflow or running out of memory) exits with 5 and a message on stderr; ordinary compiler
30
30
  statuses are 0-4. Unsupported modes can also exit with 5.
31
31
 
32
+ Since 0.20.0, `@tsrs/wasm` supports `--fast` and `TSRS_FAST=1`, with the same
33
+ [diagnostic, counter and incremental-cache side effects](https://github.com/oxc-project/tsrs/blob/main/README.md#fast-mode)
34
+ as native tsrs. WebAssembly remains single-threaded in both modes. The CLI inherits the shell environment;
35
+ `--fast false` overrides the environment preset.
36
+
32
37
  ## API
33
38
 
34
39
  ```js
@@ -57,7 +62,8 @@ Options:
57
62
  - `cwd`: defaults to the process's current directory on Node's real file system, or `/` with in-memory files.
58
63
  - `files`: absolute paths to contents (`string` or `Uint8Array`), replacing access to the real file system.
59
64
  - `diagnostics`: `"text"` (default) or `"json"` (the TypeScript API's diagnostic shape, with UTF-16 positions).
60
- - `env`: environment variables visible to the compiler; none are passed by default.
65
+ - `env`: environment variables visible to the compiler; none are passed by default. For example,
66
+ `env: { TSRS_FAST: "1" }` enables the fast preset, or pass `"--fast"` in the argument array.
61
67
  - `tty`, `caseInsensitive`: control terminal formatting and file-system case sensitivity.
62
68
  - Node: `stdout` / `stderr` can be `"inherit"` to write to the process's fds; output is collected otherwise.
63
69
  `stackSizeMb` sets the worker's stack size (default 256 MB).
package/core.js CHANGED
@@ -50,7 +50,10 @@ function prepare(module, request, host, io) {
50
50
  let instance;
51
51
  let memory;
52
52
  const view = () => new DataView(memory.buffer);
53
- const bytes = () => new Uint8Array(memory.buffer);
53
+ const bytes = (ptr = 0, len) => new Uint8Array(memory.buffer, ptr >>> 0, len);
54
+ const getUint32 = (ptr) => view().getUint32(ptr >>> 0, true);
55
+ const setUint32 = (ptr, value) => view().setUint32(ptr >>> 0, value, true);
56
+ const setBigUint64 = (ptr, value) => view().setBigUint64(ptr >>> 0, value, true);
54
57
  const env = Object.entries(io.env ?? {}).map(([k, v]) => encoder.encode(`${k}=${v}\0`));
55
58
  const stdout = io.stdout ?? (() => {});
56
59
  const stderr = io.stderr ?? (() => {});
@@ -59,38 +62,38 @@ function prepare(module, request, host, io) {
59
62
 
60
63
  const wasi = {
61
64
  args_sizes_get(argc, size) {
62
- view().setUint32(argc, 0, true);
63
- view().setUint32(size, 0, true);
65
+ setUint32(argc, 0);
66
+ setUint32(size, 0);
64
67
  return ESUCCESS;
65
68
  },
66
69
  args_get() {
67
70
  return ESUCCESS;
68
71
  },
69
72
  environ_sizes_get(count, size) {
70
- view().setUint32(count, env.length, true);
71
- view().setUint32(size, env.reduce((n, e) => n + e.length, 0), true);
73
+ setUint32(count, env.length);
74
+ setUint32(size, env.reduce((n, e) => n + e.length, 0));
72
75
  return ESUCCESS;
73
76
  },
74
77
  environ_get(ptrs, buf) {
75
- let p = buf;
78
+ let p = buf >>> 0;
76
79
  env.forEach((e, i) => {
77
- view().setUint32(ptrs + i * 4, p, true);
78
- bytes().set(e, p);
80
+ setUint32(ptrs + i * 4, p);
81
+ bytes(p, e.length).set(e);
79
82
  p += e.length;
80
83
  });
81
84
  return ESUCCESS;
82
85
  },
83
86
  clock_time_get(id, _precision, out) {
84
- view().setBigUint64(out, nowNs(id === 0), true);
87
+ setBigUint64(out, nowNs(id === 0));
85
88
  return ESUCCESS;
86
89
  },
87
90
  clock_res_get(_id, out) {
88
- view().setBigUint64(out, 1000n, true);
91
+ setBigUint64(out, 1000n);
89
92
  return ESUCCESS;
90
93
  },
91
94
  random_get(ptr, len) {
92
95
  for (let off = 0; off < len; off += 65536) {
93
- crypto.getRandomValues(new Uint8Array(memory.buffer, ptr + off, Math.min(65536, len - off)));
96
+ crypto.getRandomValues(bytes(ptr + off, Math.min(65536, len - off)));
94
97
  }
95
98
  return ESUCCESS;
96
99
  },
@@ -100,13 +103,13 @@ function prepare(module, request, host, io) {
100
103
  }
101
104
  let total = 0;
102
105
  for (let i = 0; i < count; i++) {
103
- const ptr = view().getUint32(iovs + i * 8, true);
104
- const len = view().getUint32(iovs + i * 8 + 4, true);
105
- const chunk = bytes().slice(ptr, ptr + len);
106
+ const ptr = getUint32(iovs + i * 8);
107
+ const len = getUint32(iovs + i * 8 + 4);
108
+ const chunk = bytes(ptr, len).slice();
106
109
  (fd === 1 ? stdout : stderr)(chunk);
107
110
  total += len;
108
111
  }
109
- view().setUint32(written, total, true);
112
+ setUint32(written, total);
110
113
  return ESUCCESS;
111
114
  },
112
115
  fd_fdstat_get(fd, out) {
@@ -114,11 +117,9 @@ function prepare(module, request, host, io) {
114
117
  return EBADF;
115
118
  }
116
119
  // filetype: 2 = character device (a tty), 0 = unknown.
117
- const v = view();
118
- for (let i = 0; i < 24; i++) {
119
- v.setUint8(out + i, 0);
120
- }
121
- v.setUint8(out, fd === 1 && tty ? 2 : 0);
120
+ const stat = bytes(out, 24);
121
+ stat.fill(0);
122
+ stat[0] = fd === 1 && tty ? 2 : 0;
122
123
  return ESUCCESS;
123
124
  },
124
125
  fd_prestat_get() {
@@ -141,11 +142,12 @@ function prepare(module, request, host, io) {
141
142
  },
142
143
  };
143
144
 
144
- const text = (ptr, len) => decoder.decode(bytes().subarray(ptr, ptr + len));
145
+ // Workers can reject subarray's species construction above 128 MiB; direct views work at those offsets.
146
+ const text = (ptr, len) => decoder.decode(bytes(ptr, len));
145
147
  const splitNul = (ptr, len) => {
146
- const b = bytes().subarray(ptr, ptr + len);
148
+ const b = bytes(ptr, len);
147
149
  const i = b.indexOf(0);
148
- return [decoder.decode(b.subarray(0, i < 0 ? len : i)), b.slice(i < 0 ? len : i + 1)];
150
+ return [decoder.decode(bytes(ptr, i < 0 ? len : i)), b.slice(i < 0 ? len : i + 1)];
149
151
  };
150
152
  const stage = (data) => {
151
153
  staged = typeof data === "string" ? encoder.encode(data) : data;
@@ -190,7 +192,7 @@ function prepare(module, request, host, io) {
190
192
  }
191
193
  };
192
194
 
193
- const imports = { tsrs_host: { fs: fsCall, fs_take: (ptr) => bytes().set(staged, ptr) }, wasi_snapshot_preview1: {} };
195
+ const imports = { tsrs_host: { fs: fsCall, fs_take: (ptr) => bytes(ptr, staged.length).set(staged) }, wasi_snapshot_preview1: {} };
194
196
  for (const imp of WebAssembly.Module.imports(module)) {
195
197
  if (imp.module === "wasi_snapshot_preview1") {
196
198
  imports.wasi_snapshot_preview1[imp.name] = wasi[imp.name] ?? (() => ENOSYS);
@@ -211,11 +213,10 @@ function prepare(module, request, host, io) {
211
213
  const fields = [request.cwd, String(request.flags ?? 0), ...request.args];
212
214
  const req = encoder.encode(fields.join("\0"));
213
215
  const ptr = instance.exports.tsrs_input(req.length);
214
- bytes().set(req, ptr);
216
+ bytes(ptr, req.length).set(req);
215
217
  io.beforeRun?.(memory);
216
218
  exitCode = instance.exports.tsrs_run();
217
- const out = instance.exports.tsrs_output();
218
- reply = bytes().slice(out, out + instance.exports.tsrs_output_len());
219
+ reply = bytes(instance.exports.tsrs_output(), instance.exports.tsrs_output_len()).slice();
219
220
  } catch (e) {
220
221
  if (e instanceof WasiExit) {
221
222
  exitCode = e.code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsrs/wasm",
3
- "version": "0.18.0-ts7.1.0-dev.20260929",
3
+ "version": "0.20.1-ts7.1.0-beta",
4
4
  "license": "Apache-2.0",
5
5
  "description": "tsrs (a Rust port of the TypeScript 7 compiler) as a WebAssembly module: tsc for Node and browsers, single-threaded",
6
6
  "keywords": [
@@ -52,8 +52,8 @@
52
52
  "NOTICE.txt"
53
53
  ],
54
54
  "tsrs": {
55
- "typescriptVersion": "7.1.0-dev.20260929",
56
- "typescriptCommit": "b85298b6a81f772d080b0455de0ca9d744cd6fd6"
55
+ "typescriptVersion": "7.1.0-beta",
56
+ "typescriptCommit": "3e9236361fa97a9e6c685f4833ac457ae2d8c50a"
57
57
  },
58
58
  "scripts": {
59
59
  "test": "node --test test/*.test.mjs"
package/tsrs.wasm CHANGED
Binary file