@tsrs/wasm 0.20.0-ts7.1.0-beta → 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,7 +29,7 @@ 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
- The unreleased source build supports `--fast` and `TSRS_FAST=1`, with the same
32
+ Since 0.20.0, `@tsrs/wasm` supports `--fast` and `TSRS_FAST=1`, with the same
33
33
  [diagnostic, counter and incremental-cache side effects](https://github.com/oxc-project/tsrs/blob/main/README.md#fast-mode)
34
34
  as native tsrs. WebAssembly remains single-threaded in both modes. The CLI inherits the shell environment;
35
35
  `--fast false` overrides the environment preset.
@@ -63,7 +63,7 @@ Options:
63
63
  - `files`: absolute paths to contents (`string` or `Uint8Array`), replacing access to the real file system.
64
64
  - `diagnostics`: `"text"` (default) or `"json"` (the TypeScript API's diagnostic shape, with UTF-16 positions).
65
65
  - `env`: environment variables visible to the compiler; none are passed by default. For example,
66
- `env: { TSRS_FAST: "1" }` enables the fast preset in source builds, or pass `"--fast"` in the argument array.
66
+ `env: { TSRS_FAST: "1" }` enables the fast preset, or pass `"--fast"` in the argument array.
67
67
  - `tty`, `caseInsensitive`: control terminal formatting and file-system case sensitivity.
68
68
  - Node: `stdout` / `stderr` can be `"inherit"` to write to the process's fds; output is collected otherwise.
69
69
  `stackSizeMb` sets the worker's stack size (default 256 MB).
package/core.js CHANGED
@@ -51,6 +51,9 @@ function prepare(module, request, host, io) {
51
51
  let memory;
52
52
  const view = () => new DataView(memory.buffer);
53
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() {
@@ -191,7 +192,7 @@ function prepare(module, request, host, io) {
191
192
  }
192
193
  };
193
194
 
194
- 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: {} };
195
196
  for (const imp of WebAssembly.Module.imports(module)) {
196
197
  if (imp.module === "wasi_snapshot_preview1") {
197
198
  imports.wasi_snapshot_preview1[imp.name] = wasi[imp.name] ?? (() => ENOSYS);
@@ -212,11 +213,10 @@ function prepare(module, request, host, io) {
212
213
  const fields = [request.cwd, String(request.flags ?? 0), ...request.args];
213
214
  const req = encoder.encode(fields.join("\0"));
214
215
  const ptr = instance.exports.tsrs_input(req.length);
215
- bytes().set(req, ptr);
216
+ bytes(ptr, req.length).set(req);
216
217
  io.beforeRun?.(memory);
217
218
  exitCode = instance.exports.tsrs_run();
218
- const out = instance.exports.tsrs_output();
219
- reply = bytes().slice(out, out + instance.exports.tsrs_output_len());
219
+ reply = bytes(instance.exports.tsrs_output(), instance.exports.tsrs_output_len()).slice();
220
220
  } catch (e) {
221
221
  if (e instanceof WasiExit) {
222
222
  exitCode = e.code;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tsrs/wasm",
3
- "version": "0.20.0-ts7.1.0-beta",
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": [
package/tsrs.wasm CHANGED
Binary file