@srcmap/sourcemap-wasm 0.1.2 → 0.1.3

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 ADDED
@@ -0,0 +1,116 @@
1
+ # @srcmap/sourcemap-wasm
2
+
3
+ [![npm](https://img.shields.io/npm/v/@srcmap/sourcemap-wasm.svg)](https://www.npmjs.com/package/@srcmap/sourcemap-wasm)
4
+ [![CI](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml/badge.svg)](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml)
5
+ [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/BartWaardenburg/srcmap/badges/coverage.json)](https://github.com/BartWaardenburg/srcmap/actions/workflows/coverage.yml)
6
+
7
+ High-performance source map parser and consumer powered by Rust via WebAssembly.
8
+
9
+ Parses source map JSON and provides position lookups. Implements [ECMA-426](https://tc39.es/ecma426/) (Source Map v3). The batch API is **faster than [`@jridgewell/trace-mapping`](https://github.com/jridgewell/trace-mapping)** for bulk lookups.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @srcmap/sourcemap-wasm
15
+ ```
16
+
17
+ Works in Node.js, browsers, and any WebAssembly-capable runtime. No native compilation required.
18
+
19
+ ## Usage
20
+
21
+ ```js
22
+ import { SourceMap } from '@srcmap/sourcemap-wasm';
23
+
24
+ const sm = new SourceMap(jsonString);
25
+
26
+ // Single lookup (0-based lines and columns)
27
+ const loc = sm.originalPositionFor(42, 10);
28
+ // { source: 'src/app.ts', line: 10, column: 4, name: 'handleClick' }
29
+
30
+ // Batch lookup — recommended for bulk operations
31
+ const positions = new Int32Array([42, 10, 43, 0, 44, 5]);
32
+ const results = sm.originalPositionsFor(positions);
33
+ // Int32Array [srcIdx, line, col, nameIdx, srcIdx, line, col, nameIdx, ...]
34
+ // -1 = no mapping / no name
35
+
36
+ // Resolve indices to strings
37
+ const source = sm.source(results[0]);
38
+ const name = results[3] >= 0 ? sm.name(results[3]) : null;
39
+
40
+ // Reverse lookup
41
+ const pos = sm.generatedPositionFor('src/app.ts', 10, 4);
42
+ // { line: 42, column: 10 }
43
+
44
+ // Cleanup (or use `using sm = new SourceMap(json)` with Symbol.dispose)
45
+ sm.free();
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### `new SourceMap(json: string)`
51
+
52
+ Parse a source map from a JSON string.
53
+
54
+ ### Instance methods
55
+
56
+ | Method | Returns | Description |
57
+ |--------|---------|-------------|
58
+ | `originalPositionFor(line, column)` | `{ source, line, column, name } \| null` | Forward lookup (0-based) |
59
+ | `generatedPositionFor(source, line, column)` | `{ line, column } \| null` | Reverse lookup (0-based) |
60
+ | `originalPositionsFor(positions: Int32Array)` | `Int32Array` | Batch forward lookup |
61
+ | `source(index)` | `string` | Resolve source index to filename |
62
+ | `name(index)` | `string` | Resolve name index to string |
63
+ | `free()` | `void` | Release WASM memory (also via `Symbol.dispose`) |
64
+
65
+ ### Instance properties
66
+
67
+ | Property | Type | Description |
68
+ |----------|------|-------------|
69
+ | `lineCount` | `number` | Number of generated lines |
70
+ | `mappingCount` | `number` | Total decoded mappings |
71
+ | `sources` | `string[]` | All source filenames |
72
+ | `names` | `string[]` | All names |
73
+
74
+ ## Performance
75
+
76
+ ### Batch API vs trace-mapping
77
+
78
+ The batch API (`originalPositionsFor`) returns a flat `Int32Array`, avoiding per-lookup object allocation. This makes it **faster than pure JS** for bulk operations.
79
+
80
+ | Operation | @srcmap/sourcemap-wasm | @jridgewell/trace-mapping | Speedup |
81
+ |-----------|----------------------|---------------------------|---------|
82
+ | 1000x lookup (medium map) | 12.9 us | 14.9 us | **1.15x faster** |
83
+ | 1000x lookup (large map) | 14.8 us | 22.0 us | **1.49x faster** |
84
+ | Per lookup (amortized) | 13-15 ns | 15-22 ns | **~1.3x faster** |
85
+
86
+ ### When to use which
87
+
88
+ | Use case | Recommended package |
89
+ |----------|-------------------|
90
+ | Batch lookups (error stacks, coverage) | **@srcmap/sourcemap-wasm** (batch API) |
91
+ | Few individual lookups | `@jridgewell/trace-mapping` (lower per-call overhead) |
92
+ | Native Node.js addons | `@srcmap/sourcemap` (NAPI) |
93
+ | Browser environments | **@srcmap/sourcemap-wasm** |
94
+
95
+ ## Build targets
96
+
97
+ ```bash
98
+ # Node.js (default)
99
+ npm run build
100
+
101
+ # Browser (ES module + .wasm)
102
+ npm run build:web
103
+
104
+ # Bundler (e.g. webpack, vite)
105
+ npm run build:bundler
106
+ ```
107
+
108
+ ## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
109
+
110
+ High-performance source map tooling written in Rust. See also:
111
+ - [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) - VLQ codec (NAPI)
112
+ - [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) - Source map parser (NAPI)
113
+
114
+ ## License
115
+
116
+ MIT
package/package.json CHANGED
@@ -1,22 +1,25 @@
1
1
  {
2
2
  "name": "@srcmap/sourcemap-wasm",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "High-performance source map parser and consumer powered by Rust (WebAssembly)",
5
5
  "type": "module",
6
6
  "main": "pkg/srcmap_sourcemap_wasm.js",
7
7
  "types": "pkg/srcmap_sourcemap_wasm.d.ts",
8
8
  "license": "MIT",
9
9
  "files": [
10
- "pkg/"
10
+ "pkg/",
11
+ "README.md"
11
12
  ],
12
13
  "scripts": {
13
14
  "build": "wasm-pack build --target nodejs",
14
15
  "build:web": "wasm-pack build --target web",
15
- "build:bundler": "wasm-pack build --target bundler"
16
+ "build:bundler": "wasm-pack build --target bundler",
17
+ "test": "node --test __tests__/sourcemap-wasm.test.mjs",
18
+ "test:coverage": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/lcov.info --test-reporter=spec --test-reporter-destination=stdout __tests__/sourcemap-wasm.test.mjs"
16
19
  },
17
20
  "repository": {
18
21
  "type": "git",
19
- "url": "https://github.com/BartWaardenburg/srcmap"
22
+ "url": "git+https://github.com/BartWaardenburg/srcmap.git"
20
23
  },
21
24
  "keywords": [
22
25
  "sourcemap",
package/pkg/README.md ADDED
@@ -0,0 +1,116 @@
1
+ # @srcmap/sourcemap-wasm
2
+
3
+ [![npm](https://img.shields.io/npm/v/@srcmap/sourcemap-wasm.svg)](https://www.npmjs.com/package/@srcmap/sourcemap-wasm)
4
+ [![CI](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml/badge.svg)](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml)
5
+ [![Coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/BartWaardenburg/srcmap/badges/coverage.json)](https://github.com/BartWaardenburg/srcmap/actions/workflows/coverage.yml)
6
+
7
+ High-performance source map parser and consumer powered by Rust via WebAssembly.
8
+
9
+ Parses source map JSON and provides position lookups. Implements [ECMA-426](https://tc39.es/ecma426/) (Source Map v3). The batch API is **faster than [`@jridgewell/trace-mapping`](https://github.com/jridgewell/trace-mapping)** for bulk lookups.
10
+
11
+ ## Install
12
+
13
+ ```bash
14
+ npm install @srcmap/sourcemap-wasm
15
+ ```
16
+
17
+ Works in Node.js, browsers, and any WebAssembly-capable runtime. No native compilation required.
18
+
19
+ ## Usage
20
+
21
+ ```js
22
+ import { SourceMap } from '@srcmap/sourcemap-wasm';
23
+
24
+ const sm = new SourceMap(jsonString);
25
+
26
+ // Single lookup (0-based lines and columns)
27
+ const loc = sm.originalPositionFor(42, 10);
28
+ // { source: 'src/app.ts', line: 10, column: 4, name: 'handleClick' }
29
+
30
+ // Batch lookup — recommended for bulk operations
31
+ const positions = new Int32Array([42, 10, 43, 0, 44, 5]);
32
+ const results = sm.originalPositionsFor(positions);
33
+ // Int32Array [srcIdx, line, col, nameIdx, srcIdx, line, col, nameIdx, ...]
34
+ // -1 = no mapping / no name
35
+
36
+ // Resolve indices to strings
37
+ const source = sm.source(results[0]);
38
+ const name = results[3] >= 0 ? sm.name(results[3]) : null;
39
+
40
+ // Reverse lookup
41
+ const pos = sm.generatedPositionFor('src/app.ts', 10, 4);
42
+ // { line: 42, column: 10 }
43
+
44
+ // Cleanup (or use `using sm = new SourceMap(json)` with Symbol.dispose)
45
+ sm.free();
46
+ ```
47
+
48
+ ## API
49
+
50
+ ### `new SourceMap(json: string)`
51
+
52
+ Parse a source map from a JSON string.
53
+
54
+ ### Instance methods
55
+
56
+ | Method | Returns | Description |
57
+ |--------|---------|-------------|
58
+ | `originalPositionFor(line, column)` | `{ source, line, column, name } \| null` | Forward lookup (0-based) |
59
+ | `generatedPositionFor(source, line, column)` | `{ line, column } \| null` | Reverse lookup (0-based) |
60
+ | `originalPositionsFor(positions: Int32Array)` | `Int32Array` | Batch forward lookup |
61
+ | `source(index)` | `string` | Resolve source index to filename |
62
+ | `name(index)` | `string` | Resolve name index to string |
63
+ | `free()` | `void` | Release WASM memory (also via `Symbol.dispose`) |
64
+
65
+ ### Instance properties
66
+
67
+ | Property | Type | Description |
68
+ |----------|------|-------------|
69
+ | `lineCount` | `number` | Number of generated lines |
70
+ | `mappingCount` | `number` | Total decoded mappings |
71
+ | `sources` | `string[]` | All source filenames |
72
+ | `names` | `string[]` | All names |
73
+
74
+ ## Performance
75
+
76
+ ### Batch API vs trace-mapping
77
+
78
+ The batch API (`originalPositionsFor`) returns a flat `Int32Array`, avoiding per-lookup object allocation. This makes it **faster than pure JS** for bulk operations.
79
+
80
+ | Operation | @srcmap/sourcemap-wasm | @jridgewell/trace-mapping | Speedup |
81
+ |-----------|----------------------|---------------------------|---------|
82
+ | 1000x lookup (medium map) | 12.9 us | 14.9 us | **1.15x faster** |
83
+ | 1000x lookup (large map) | 14.8 us | 22.0 us | **1.49x faster** |
84
+ | Per lookup (amortized) | 13-15 ns | 15-22 ns | **~1.3x faster** |
85
+
86
+ ### When to use which
87
+
88
+ | Use case | Recommended package |
89
+ |----------|-------------------|
90
+ | Batch lookups (error stacks, coverage) | **@srcmap/sourcemap-wasm** (batch API) |
91
+ | Few individual lookups | `@jridgewell/trace-mapping` (lower per-call overhead) |
92
+ | Native Node.js addons | `@srcmap/sourcemap` (NAPI) |
93
+ | Browser environments | **@srcmap/sourcemap-wasm** |
94
+
95
+ ## Build targets
96
+
97
+ ```bash
98
+ # Node.js (default)
99
+ npm run build
100
+
101
+ # Browser (ES module + .wasm)
102
+ npm run build:web
103
+
104
+ # Bundler (e.g. webpack, vite)
105
+ npm run build:bundler
106
+ ```
107
+
108
+ ## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
109
+
110
+ High-performance source map tooling written in Rust. See also:
111
+ - [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) - VLQ codec (NAPI)
112
+ - [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) - Source map parser (NAPI)
113
+
114
+ ## License
115
+
116
+ MIT
package/pkg/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "srcmap-sourcemap-wasm",
3
3
  "description": "WebAssembly bindings for srcmap-sourcemap",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -34,6 +34,10 @@ export class SourceMap {
34
34
  * Resolve a source index to its filename.
35
35
  */
36
36
  source(index: number): string;
37
+ /**
38
+ * Get the debug ID (UUID) if present.
39
+ */
40
+ readonly debugId: string | undefined;
37
41
  /**
38
42
  * Number of generated lines.
39
43
  */
@@ -11,6 +11,26 @@ class SourceMap {
11
11
  const ptr = this.__destroy_into_raw();
12
12
  wasm.__wbg_sourcemap_free(ptr, 0);
13
13
  }
14
+ /**
15
+ * Get the debug ID (UUID) if present.
16
+ * @returns {string | undefined}
17
+ */
18
+ get debugId() {
19
+ try {
20
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
21
+ wasm.sourcemap_debugId(retptr, this.__wbg_ptr);
22
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
23
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
24
+ let v1;
25
+ if (r0 !== 0) {
26
+ v1 = getStringFromWasm0(r0, r1).slice();
27
+ wasm.__wbindgen_export2(r0, r1 * 1, 1);
28
+ }
29
+ return v1;
30
+ } finally {
31
+ wasm.__wbindgen_add_to_stack_pointer(16);
32
+ }
33
+ }
14
34
  /**
15
35
  * Look up the generated position for an original source position.
16
36
  * Returns null if no mapping exists, or an object {line, column}.
@@ -20,7 +40,7 @@ class SourceMap {
20
40
  * @returns {any}
21
41
  */
22
42
  generatedPositionFor(source, line, column) {
23
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
43
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
24
44
  const len0 = WASM_VECTOR_LEN;
25
45
  const ret = wasm.sourcemap_generatedPositionFor(this.__wbg_ptr, ptr0, len0, line, column);
26
46
  return takeObject(ret);
@@ -59,7 +79,7 @@ class SourceMap {
59
79
  return getStringFromWasm0(r0, r1);
60
80
  } finally {
61
81
  wasm.__wbindgen_add_to_stack_pointer(16);
62
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
82
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
63
83
  }
64
84
  }
65
85
  /**
@@ -73,7 +93,7 @@ class SourceMap {
73
93
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
74
94
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
75
95
  var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
76
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
96
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
77
97
  return v1;
78
98
  } finally {
79
99
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -86,7 +106,7 @@ class SourceMap {
86
106
  constructor(json) {
87
107
  try {
88
108
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
89
- const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
109
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export3, wasm.__wbindgen_export4);
90
110
  const len0 = WASM_VECTOR_LEN;
91
111
  wasm.sourcemap_new(retptr, ptr0, len0);
92
112
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -125,13 +145,13 @@ class SourceMap {
125
145
  originalPositionsFor(positions) {
126
146
  try {
127
147
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
- const ptr0 = passArray32ToWasm0(positions, wasm.__wbindgen_export2);
148
+ const ptr0 = passArray32ToWasm0(positions, wasm.__wbindgen_export3);
129
149
  const len0 = WASM_VECTOR_LEN;
130
150
  wasm.sourcemap_originalPositionsFor(retptr, this.__wbg_ptr, ptr0, len0);
131
151
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
132
152
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
133
153
  var v2 = getArrayI32FromWasm0(r0, r1).slice();
134
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
154
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
135
155
  return v2;
136
156
  } finally {
137
157
  wasm.__wbindgen_add_to_stack_pointer(16);
@@ -155,7 +175,7 @@ class SourceMap {
155
175
  return getStringFromWasm0(r0, r1);
156
176
  } finally {
157
177
  wasm.__wbindgen_add_to_stack_pointer(16);
158
- wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
178
+ wasm.__wbindgen_export2(deferred1_0, deferred1_1, 1);
159
179
  }
160
180
  }
161
181
  /**
@@ -169,7 +189,7 @@ class SourceMap {
169
189
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
170
190
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
171
191
  var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
172
- wasm.__wbindgen_export4(r0, r1 * 4, 4);
192
+ wasm.__wbindgen_export2(r0, r1 * 4, 4);
173
193
  return v1;
174
194
  } finally {
175
195
  wasm.__wbindgen_add_to_stack_pointer(16);
Binary file
@@ -2,6 +2,7 @@
2
2
  /* eslint-disable */
3
3
  export const memory: WebAssembly.Memory;
4
4
  export const __wbg_sourcemap_free: (a: number, b: number) => void;
5
+ export const sourcemap_debugId: (a: number, b: number) => void;
5
6
  export const sourcemap_generatedPositionFor: (a: number, b: number, c: number, d: number, e: number) => number;
6
7
  export const sourcemap_lineCount: (a: number) => number;
7
8
  export const sourcemap_mappingCount: (a: number) => number;
@@ -13,7 +14,7 @@ export const sourcemap_originalPositionsFor: (a: number, b: number, c: number, d
13
14
  export const sourcemap_source: (a: number, b: number, c: number) => void;
14
15
  export const sourcemap_sources: (a: number, b: number) => void;
15
16
  export const __wbindgen_export: (a: number) => void;
16
- export const __wbindgen_export2: (a: number, b: number) => number;
17
- export const __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
18
17
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
19
- export const __wbindgen_export4: (a: number, b: number, c: number) => void;
18
+ export const __wbindgen_export2: (a: number, b: number, c: number) => void;
19
+ export const __wbindgen_export3: (a: number, b: number) => number;
20
+ export const __wbindgen_export4: (a: number, b: number, c: number, d: number) => number;