@srcmap/sourcemap-wasm 0.1.2 → 0.2.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 ADDED
@@ -0,0 +1,118 @@
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
+ | `hasRangeMappings` | `boolean` | Whether any range mappings exist |
72
+ | `rangeMappingCount` | `number` | Number of range mappings |
73
+ | `sources` | `string[]` | All source filenames |
74
+ | `names` | `string[]` | All names |
75
+
76
+ ## Performance
77
+
78
+ ### Batch API vs trace-mapping
79
+
80
+ The batch API (`originalPositionsFor`) returns a flat `Int32Array`, avoiding per-lookup object allocation. This makes it **faster than pure JS** for bulk operations.
81
+
82
+ | Operation | @srcmap/sourcemap-wasm | @jridgewell/trace-mapping | Speedup |
83
+ |-----------|----------------------|---------------------------|---------|
84
+ | 1000x lookup (medium map) | 12.9 us | 14.9 us | **1.15x faster** |
85
+ | 1000x lookup (large map) | 14.8 us | 22.0 us | **1.49x faster** |
86
+ | Per lookup (amortized) | 13-15 ns | 15-22 ns | **~1.3x faster** |
87
+
88
+ ### When to use which
89
+
90
+ | Use case | Recommended package |
91
+ |----------|-------------------|
92
+ | Batch lookups (error stacks, coverage) | **@srcmap/sourcemap-wasm** (batch API) |
93
+ | Few individual lookups | `@jridgewell/trace-mapping` (lower per-call overhead) |
94
+ | Native Node.js addons | `@srcmap/sourcemap` (NAPI) |
95
+ | Browser environments | **@srcmap/sourcemap-wasm** |
96
+
97
+ ## Build targets
98
+
99
+ ```bash
100
+ # Node.js (default)
101
+ npm run build
102
+
103
+ # Browser (ES module + .wasm)
104
+ npm run build:web
105
+
106
+ # Bundler (e.g. webpack, vite)
107
+ npm run build:bundler
108
+ ```
109
+
110
+ ## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
111
+
112
+ High-performance source map tooling written in Rust. See also:
113
+ - [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) - VLQ codec (NAPI)
114
+ - [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) - Source map parser (NAPI)
115
+
116
+ ## License
117
+
118
+ MIT
package/package.json CHANGED
@@ -1,22 +1,36 @@
1
1
  {
2
2
  "name": "@srcmap/sourcemap-wasm",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
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
+ "browser": "web/srcmap_sourcemap_wasm.js",
9
+ "module": "web/srcmap_sourcemap_wasm.js",
10
+ "exports": {
11
+ ".": {
12
+ "node": "./pkg/srcmap_sourcemap_wasm.js",
13
+ "browser": "./web/srcmap_sourcemap_wasm.js",
14
+ "default": "./pkg/srcmap_sourcemap_wasm.js"
15
+ }
16
+ },
8
17
  "license": "MIT",
9
18
  "files": [
10
- "pkg/"
19
+ "pkg/",
20
+ "web/",
21
+ "README.md"
11
22
  ],
12
23
  "scripts": {
13
- "build": "wasm-pack build --target nodejs",
14
- "build:web": "wasm-pack build --target web",
15
- "build:bundler": "wasm-pack build --target bundler"
24
+ "build": "wasm-pack build --target nodejs --out-dir pkg",
25
+ "build:web": "wasm-pack build --target web --out-dir web",
26
+ "build:bundler": "wasm-pack build --target bundler --out-dir bundler",
27
+ "build:all": "npm run build && npm run build:web",
28
+ "test": "node --test __tests__/sourcemap-wasm.test.mjs",
29
+ "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
30
  },
17
31
  "repository": {
18
32
  "type": "git",
19
- "url": "https://github.com/BartWaardenburg/srcmap"
33
+ "url": "git+https://github.com/BartWaardenburg/srcmap.git"
20
34
  },
21
35
  "keywords": [
22
36
  "sourcemap",
@@ -27,6 +41,7 @@
27
41
  "rust",
28
42
  "wasm",
29
43
  "webassembly",
30
- "performance"
44
+ "performance",
45
+ "browser"
31
46
  ]
32
47
  }
package/pkg/README.md ADDED
@@ -0,0 +1,118 @@
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
+ | `hasRangeMappings` | `boolean` | Whether any range mappings exist |
72
+ | `rangeMappingCount` | `number` | Number of range mappings |
73
+ | `sources` | `string[]` | All source filenames |
74
+ | `names` | `string[]` | All names |
75
+
76
+ ## Performance
77
+
78
+ ### Batch API vs trace-mapping
79
+
80
+ The batch API (`originalPositionsFor`) returns a flat `Int32Array`, avoiding per-lookup object allocation. This makes it **faster than pure JS** for bulk operations.
81
+
82
+ | Operation | @srcmap/sourcemap-wasm | @jridgewell/trace-mapping | Speedup |
83
+ |-----------|----------------------|---------------------------|---------|
84
+ | 1000x lookup (medium map) | 12.9 us | 14.9 us | **1.15x faster** |
85
+ | 1000x lookup (large map) | 14.8 us | 22.0 us | **1.49x faster** |
86
+ | Per lookup (amortized) | 13-15 ns | 15-22 ns | **~1.3x faster** |
87
+
88
+ ### When to use which
89
+
90
+ | Use case | Recommended package |
91
+ |----------|-------------------|
92
+ | Batch lookups (error stacks, coverage) | **@srcmap/sourcemap-wasm** (batch API) |
93
+ | Few individual lookups | `@jridgewell/trace-mapping` (lower per-call overhead) |
94
+ | Native Node.js addons | `@srcmap/sourcemap` (NAPI) |
95
+ | Browser environments | **@srcmap/sourcemap-wasm** |
96
+
97
+ ## Build targets
98
+
99
+ ```bash
100
+ # Node.js (default)
101
+ npm run build
102
+
103
+ # Browser (ES module + .wasm)
104
+ npm run build:web
105
+
106
+ # Bundler (e.g. webpack, vite)
107
+ npm run build:bundler
108
+ ```
109
+
110
+ ## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
111
+
112
+ High-performance source map tooling written in Rust. See also:
113
+ - [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) - VLQ codec (NAPI)
114
+ - [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) - Source map parser (NAPI)
115
+
116
+ ## License
117
+
118
+ MIT
package/pkg/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "srcmap-sourcemap-wasm",
3
3
  "description": "WebAssembly bindings for srcmap-sourcemap",
4
- "version": "0.1.2",
4
+ "version": "0.2.0",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
- "url": "https://github.com/bartwaardenburg/srcmap"
8
+ "url": "https://github.com/BartWaardenburg/srcmap"
9
9
  },
10
10
  "files": [
11
11
  "srcmap_sourcemap_wasm_bg.wasm",
@@ -4,11 +4,52 @@
4
4
  export class SourceMap {
5
5
  free(): void;
6
6
  [Symbol.dispose](): void;
7
+ /**
8
+ * Find all generated positions for an original source position.
9
+ * Returns an array of {line, column} objects.
10
+ */
11
+ allGeneratedPositionsFor(source: string, line: number, column: number): any[];
12
+ /**
13
+ * Get all mappings as a flat Int32Array.
14
+ * Format: [genLine, genCol, source, origLine, origCol, name, isRange, ...] per mapping.
15
+ * source = -1 means unmapped, name = -1 means no name, isRange = 1 if range mapping.
16
+ */
17
+ allMappingsFlat(): Int32Array;
18
+ /**
19
+ * Encode all mappings back to a VLQ mappings string.
20
+ */
21
+ encodedMappings(): string;
22
+ /**
23
+ * Encode the range mappings back to a VLQ string, or null if none exist.
24
+ */
25
+ encodedRangeMappings(): any;
26
+ /**
27
+ * Build a source map from pre-parsed components.
28
+ *
29
+ * This is the fast path: JS does JSON.parse() (V8-native speed),
30
+ * then only the VLQ mappings string is sent to WASM for decoding.
31
+ * Avoids copying large sourcesContent into WASM linear memory.
32
+ */
33
+ static fromVlq(mappings: string, sources: any[], names: any[], file: string | null | undefined, source_root: string | null | undefined, sources_content: any[], ignore_list: Uint32Array, debug_id?: string | null): SourceMap;
7
34
  /**
8
35
  * Look up the generated position for an original source position.
9
36
  * Returns null if no mapping exists, or an object {line, column}.
10
37
  */
11
38
  generatedPositionFor(source: string, line: number, column: number): any;
39
+ /**
40
+ * Look up the generated position with a bias.
41
+ * bias: 0 = default, -1 = LEAST_UPPER_BOUND, 1 = GREATEST_LOWER_BOUND
42
+ */
43
+ generatedPositionForWithBias(source: string, line: number, column: number, bias: number): any;
44
+ /**
45
+ * Check if a source index is in the ignore list.
46
+ */
47
+ isIgnoredIndex(index: number): boolean;
48
+ /**
49
+ * Map a generated range to its original range.
50
+ * Returns null if either endpoint has no mapping or endpoints map to different sources.
51
+ */
52
+ mapRange(start_line: number, start_column: number, end_line: number, end_column: number): any;
12
53
  /**
13
54
  * Resolve a name index to its string.
14
55
  */
@@ -17,12 +58,29 @@ export class SourceMap {
17
58
  * Parse a source map from a JSON string.
18
59
  */
19
60
  constructor(json: string);
61
+ /**
62
+ * Zero-allocation single lookup. Writes result to the static WASM buffer.
63
+ * Returns true if a mapping was found, false otherwise.
64
+ * Read results via an Int32Array view at resultPtr(): [sourceIdx, line, column, nameIdx].
65
+ */
66
+ originalPositionBuf(line: number, column: number): boolean;
67
+ /**
68
+ * Fast single lookup returning flat array [sourceIdx, line, column, nameIdx].
69
+ * Returns [-1, -1, -1, -1] for unmapped positions.
70
+ * Use source(idx) and name(idx) to resolve strings.
71
+ */
72
+ originalPositionFlat(line: number, column: number): Int32Array;
20
73
  /**
21
74
  * Look up the original source position for a generated position.
22
75
  * Both line and column are 0-based.
23
76
  * Returns null if no mapping exists, or an object {source, line, column, name}.
24
77
  */
25
78
  originalPositionFor(line: number, column: number): any;
79
+ /**
80
+ * Look up the original source position with a bias.
81
+ * bias: 0 = GREATEST_LOWER_BOUND (default), -1 = LEAST_UPPER_BOUND
82
+ */
83
+ originalPositionForWithBias(line: number, column: number, bias: number): any;
26
84
  /**
27
85
  * Batch lookup: find original positions for multiple generated positions.
28
86
  * Takes a flat array [line0, col0, line1, col1, ...].
@@ -34,6 +92,26 @@ export class SourceMap {
34
92
  * Resolve a source index to its filename.
35
93
  */
36
94
  source(index: number): string;
95
+ /**
96
+ * Get source content for a given source index.
97
+ */
98
+ sourceContentFor(index: number): any;
99
+ /**
100
+ * Get the debug ID (UUID) if present.
101
+ */
102
+ readonly debugId: string | undefined;
103
+ /**
104
+ * Get the file property.
105
+ */
106
+ readonly file: string | undefined;
107
+ /**
108
+ * Whether the source map has any range mappings (ECMA-426).
109
+ */
110
+ readonly hasRangeMappings: boolean;
111
+ /**
112
+ * Get the ignore list (array of source indices).
113
+ */
114
+ readonly ignoreList: Uint32Array;
37
115
  /**
38
116
  * Number of generated lines.
39
117
  */
@@ -46,8 +124,32 @@ export class SourceMap {
46
124
  * Get all names.
47
125
  */
48
126
  readonly names: any[];
127
+ /**
128
+ * Number of range mappings in the source map.
129
+ */
130
+ readonly rangeMappingCount: number;
131
+ /**
132
+ * Get the sourceRoot property.
133
+ */
134
+ readonly sourceRoot: string | undefined;
49
135
  /**
50
136
  * Get all source filenames.
51
137
  */
52
138
  readonly sources: any[];
139
+ /**
140
+ * Get all sources content (array of string|null).
141
+ */
142
+ readonly sourcesContent: any[];
53
143
  }
144
+
145
+ /**
146
+ * Get the pointer to the static result buffer in WASM linear memory.
147
+ * JS side creates an Int32Array view at this offset to read lookup results
148
+ * without any allocation or copying.
149
+ */
150
+ export function resultPtr(): number;
151
+
152
+ /**
153
+ * Expose WASM linear memory for direct buffer access from JS.
154
+ */
155
+ export function wasmMemory(): any;
@@ -1,6 +1,13 @@
1
1
  /* @ts-self-types="./srcmap_sourcemap_wasm.d.ts" */
2
2
 
3
3
  class SourceMap {
4
+ static __wrap(ptr) {
5
+ ptr = ptr >>> 0;
6
+ const obj = Object.create(SourceMap.prototype);
7
+ obj.__wbg_ptr = ptr;
8
+ SourceMapFinalization.register(obj, obj.__wbg_ptr, obj);
9
+ return obj;
10
+ }
4
11
  __destroy_into_raw() {
5
12
  const ptr = this.__wbg_ptr;
6
13
  this.__wbg_ptr = 0;
@@ -11,6 +18,163 @@ class SourceMap {
11
18
  const ptr = this.__destroy_into_raw();
12
19
  wasm.__wbg_sourcemap_free(ptr, 0);
13
20
  }
21
+ /**
22
+ * Find all generated positions for an original source position.
23
+ * Returns an array of {line, column} objects.
24
+ * @param {string} source
25
+ * @param {number} line
26
+ * @param {number} column
27
+ * @returns {any[]}
28
+ */
29
+ allGeneratedPositionsFor(source, line, column) {
30
+ try {
31
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
32
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
33
+ const len0 = WASM_VECTOR_LEN;
34
+ wasm.sourcemap_allGeneratedPositionsFor(retptr, this.__wbg_ptr, ptr0, len0, line, column);
35
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
36
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
37
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
38
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
39
+ return v2;
40
+ } finally {
41
+ wasm.__wbindgen_add_to_stack_pointer(16);
42
+ }
43
+ }
44
+ /**
45
+ * Get all mappings as a flat Int32Array.
46
+ * Format: [genLine, genCol, source, origLine, origCol, name, isRange, ...] per mapping.
47
+ * source = -1 means unmapped, name = -1 means no name, isRange = 1 if range mapping.
48
+ * @returns {Int32Array}
49
+ */
50
+ allMappingsFlat() {
51
+ try {
52
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
53
+ wasm.sourcemap_allMappingsFlat(retptr, this.__wbg_ptr);
54
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
55
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
56
+ var v1 = getArrayI32FromWasm0(r0, r1).slice();
57
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
58
+ return v1;
59
+ } finally {
60
+ wasm.__wbindgen_add_to_stack_pointer(16);
61
+ }
62
+ }
63
+ /**
64
+ * Get the debug ID (UUID) if present.
65
+ * @returns {string | undefined}
66
+ */
67
+ get debugId() {
68
+ try {
69
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
70
+ wasm.sourcemap_debugId(retptr, this.__wbg_ptr);
71
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
72
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
73
+ let v1;
74
+ if (r0 !== 0) {
75
+ v1 = getStringFromWasm0(r0, r1).slice();
76
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
77
+ }
78
+ return v1;
79
+ } finally {
80
+ wasm.__wbindgen_add_to_stack_pointer(16);
81
+ }
82
+ }
83
+ /**
84
+ * Encode all mappings back to a VLQ mappings string.
85
+ * @returns {string}
86
+ */
87
+ encodedMappings() {
88
+ let deferred1_0;
89
+ let deferred1_1;
90
+ try {
91
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
92
+ wasm.sourcemap_encodedMappings(retptr, this.__wbg_ptr);
93
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
94
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
95
+ deferred1_0 = r0;
96
+ deferred1_1 = r1;
97
+ return getStringFromWasm0(r0, r1);
98
+ } finally {
99
+ wasm.__wbindgen_add_to_stack_pointer(16);
100
+ wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
101
+ }
102
+ }
103
+ /**
104
+ * Encode the range mappings back to a VLQ string, or null if none exist.
105
+ * @returns {any}
106
+ */
107
+ encodedRangeMappings() {
108
+ const ret = wasm.sourcemap_encodedRangeMappings(this.__wbg_ptr);
109
+ return takeObject(ret);
110
+ }
111
+ /**
112
+ * Get the file property.
113
+ * @returns {string | undefined}
114
+ */
115
+ get file() {
116
+ try {
117
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
118
+ wasm.sourcemap_file(retptr, this.__wbg_ptr);
119
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
120
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
121
+ let v1;
122
+ if (r0 !== 0) {
123
+ v1 = getStringFromWasm0(r0, r1).slice();
124
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
125
+ }
126
+ return v1;
127
+ } finally {
128
+ wasm.__wbindgen_add_to_stack_pointer(16);
129
+ }
130
+ }
131
+ /**
132
+ * Build a source map from pre-parsed components.
133
+ *
134
+ * This is the fast path: JS does JSON.parse() (V8-native speed),
135
+ * then only the VLQ mappings string is sent to WASM for decoding.
136
+ * Avoids copying large sourcesContent into WASM linear memory.
137
+ * @param {string} mappings
138
+ * @param {any[]} sources
139
+ * @param {any[]} names
140
+ * @param {string | null | undefined} file
141
+ * @param {string | null | undefined} source_root
142
+ * @param {any[]} sources_content
143
+ * @param {Uint32Array} ignore_list
144
+ * @param {string | null} [debug_id]
145
+ * @returns {SourceMap}
146
+ */
147
+ static fromVlq(mappings, sources, names, file, source_root, sources_content, ignore_list, debug_id) {
148
+ try {
149
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
150
+ const ptr0 = passStringToWasm0(mappings, wasm.__wbindgen_export, wasm.__wbindgen_export2);
151
+ const len0 = WASM_VECTOR_LEN;
152
+ const ptr1 = passArrayJsValueToWasm0(sources, wasm.__wbindgen_export);
153
+ const len1 = WASM_VECTOR_LEN;
154
+ const ptr2 = passArrayJsValueToWasm0(names, wasm.__wbindgen_export);
155
+ const len2 = WASM_VECTOR_LEN;
156
+ var ptr3 = isLikeNone(file) ? 0 : passStringToWasm0(file, wasm.__wbindgen_export, wasm.__wbindgen_export2);
157
+ var len3 = WASM_VECTOR_LEN;
158
+ var ptr4 = isLikeNone(source_root) ? 0 : passStringToWasm0(source_root, wasm.__wbindgen_export, wasm.__wbindgen_export2);
159
+ var len4 = WASM_VECTOR_LEN;
160
+ const ptr5 = passArrayJsValueToWasm0(sources_content, wasm.__wbindgen_export);
161
+ const len5 = WASM_VECTOR_LEN;
162
+ const ptr6 = passArray32ToWasm0(ignore_list, wasm.__wbindgen_export);
163
+ const len6 = WASM_VECTOR_LEN;
164
+ var ptr7 = isLikeNone(debug_id) ? 0 : passStringToWasm0(debug_id, wasm.__wbindgen_export, wasm.__wbindgen_export2);
165
+ var len7 = WASM_VECTOR_LEN;
166
+ wasm.sourcemap_fromVlq(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7);
167
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
168
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
169
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
170
+ if (r2) {
171
+ throw takeObject(r1);
172
+ }
173
+ return SourceMap.__wrap(r0);
174
+ } finally {
175
+ wasm.__wbindgen_add_to_stack_pointer(16);
176
+ }
177
+ }
14
178
  /**
15
179
  * Look up the generated position for an original source position.
16
180
  * Returns null if no mapping exists, or an object {line, column}.
@@ -20,11 +184,60 @@ class SourceMap {
20
184
  * @returns {any}
21
185
  */
22
186
  generatedPositionFor(source, line, column) {
23
- const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
187
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
24
188
  const len0 = WASM_VECTOR_LEN;
25
189
  const ret = wasm.sourcemap_generatedPositionFor(this.__wbg_ptr, ptr0, len0, line, column);
26
190
  return takeObject(ret);
27
191
  }
192
+ /**
193
+ * Look up the generated position with a bias.
194
+ * bias: 0 = default, -1 = LEAST_UPPER_BOUND, 1 = GREATEST_LOWER_BOUND
195
+ * @param {string} source
196
+ * @param {number} line
197
+ * @param {number} column
198
+ * @param {number} bias
199
+ * @returns {any}
200
+ */
201
+ generatedPositionForWithBias(source, line, column, bias) {
202
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_export, wasm.__wbindgen_export2);
203
+ const len0 = WASM_VECTOR_LEN;
204
+ const ret = wasm.sourcemap_generatedPositionForWithBias(this.__wbg_ptr, ptr0, len0, line, column, bias);
205
+ return takeObject(ret);
206
+ }
207
+ /**
208
+ * Whether the source map has any range mappings (ECMA-426).
209
+ * @returns {boolean}
210
+ */
211
+ get hasRangeMappings() {
212
+ const ret = wasm.sourcemap_hasRangeMappings(this.__wbg_ptr);
213
+ return ret !== 0;
214
+ }
215
+ /**
216
+ * Get the ignore list (array of source indices).
217
+ * @returns {Uint32Array}
218
+ */
219
+ get ignoreList() {
220
+ try {
221
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
222
+ wasm.sourcemap_ignoreList(retptr, this.__wbg_ptr);
223
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
224
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
225
+ var v1 = getArrayU32FromWasm0(r0, r1).slice();
226
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
227
+ return v1;
228
+ } finally {
229
+ wasm.__wbindgen_add_to_stack_pointer(16);
230
+ }
231
+ }
232
+ /**
233
+ * Check if a source index is in the ignore list.
234
+ * @param {number} index
235
+ * @returns {boolean}
236
+ */
237
+ isIgnoredIndex(index) {
238
+ const ret = wasm.sourcemap_isIgnoredIndex(this.__wbg_ptr, index);
239
+ return ret !== 0;
240
+ }
28
241
  /**
29
242
  * Number of generated lines.
30
243
  * @returns {number}
@@ -33,6 +246,19 @@ class SourceMap {
33
246
  const ret = wasm.sourcemap_lineCount(this.__wbg_ptr);
34
247
  return ret >>> 0;
35
248
  }
249
+ /**
250
+ * Map a generated range to its original range.
251
+ * Returns null if either endpoint has no mapping or endpoints map to different sources.
252
+ * @param {number} start_line
253
+ * @param {number} start_column
254
+ * @param {number} end_line
255
+ * @param {number} end_column
256
+ * @returns {any}
257
+ */
258
+ mapRange(start_line, start_column, end_line, end_column) {
259
+ const ret = wasm.sourcemap_mapRange(this.__wbg_ptr, start_line, start_column, end_line, end_column);
260
+ return takeObject(ret);
261
+ }
36
262
  /**
37
263
  * Total number of decoded mappings.
38
264
  * @returns {number}
@@ -86,7 +312,7 @@ class SourceMap {
86
312
  constructor(json) {
87
313
  try {
88
314
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
89
- const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
315
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_export, wasm.__wbindgen_export2);
90
316
  const len0 = WASM_VECTOR_LEN;
91
317
  wasm.sourcemap_new(retptr, ptr0, len0);
92
318
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -102,6 +328,39 @@ class SourceMap {
102
328
  wasm.__wbindgen_add_to_stack_pointer(16);
103
329
  }
104
330
  }
331
+ /**
332
+ * Zero-allocation single lookup. Writes result to the static WASM buffer.
333
+ * Returns true if a mapping was found, false otherwise.
334
+ * Read results via an Int32Array view at resultPtr(): [sourceIdx, line, column, nameIdx].
335
+ * @param {number} line
336
+ * @param {number} column
337
+ * @returns {boolean}
338
+ */
339
+ originalPositionBuf(line, column) {
340
+ const ret = wasm.sourcemap_originalPositionBuf(this.__wbg_ptr, line, column);
341
+ return ret !== 0;
342
+ }
343
+ /**
344
+ * Fast single lookup returning flat array [sourceIdx, line, column, nameIdx].
345
+ * Returns [-1, -1, -1, -1] for unmapped positions.
346
+ * Use source(idx) and name(idx) to resolve strings.
347
+ * @param {number} line
348
+ * @param {number} column
349
+ * @returns {Int32Array}
350
+ */
351
+ originalPositionFlat(line, column) {
352
+ try {
353
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
354
+ wasm.sourcemap_originalPositionFlat(retptr, this.__wbg_ptr, line, column);
355
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
356
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
357
+ var v1 = getArrayI32FromWasm0(r0, r1).slice();
358
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
359
+ return v1;
360
+ } finally {
361
+ wasm.__wbindgen_add_to_stack_pointer(16);
362
+ }
363
+ }
105
364
  /**
106
365
  * Look up the original source position for a generated position.
107
366
  * Both line and column are 0-based.
@@ -114,6 +373,18 @@ class SourceMap {
114
373
  const ret = wasm.sourcemap_originalPositionFor(this.__wbg_ptr, line, column);
115
374
  return takeObject(ret);
116
375
  }
376
+ /**
377
+ * Look up the original source position with a bias.
378
+ * bias: 0 = GREATEST_LOWER_BOUND (default), -1 = LEAST_UPPER_BOUND
379
+ * @param {number} line
380
+ * @param {number} column
381
+ * @param {number} bias
382
+ * @returns {any}
383
+ */
384
+ originalPositionForWithBias(line, column, bias) {
385
+ const ret = wasm.sourcemap_originalPositionForWithBias(this.__wbg_ptr, line, column, bias);
386
+ return takeObject(ret);
387
+ }
117
388
  /**
118
389
  * Batch lookup: find original positions for multiple generated positions.
119
390
  * Takes a flat array [line0, col0, line1, col1, ...].
@@ -125,7 +396,7 @@ class SourceMap {
125
396
  originalPositionsFor(positions) {
126
397
  try {
127
398
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
128
- const ptr0 = passArray32ToWasm0(positions, wasm.__wbindgen_export2);
399
+ const ptr0 = passArray32ToWasm0(positions, wasm.__wbindgen_export);
129
400
  const len0 = WASM_VECTOR_LEN;
130
401
  wasm.sourcemap_originalPositionsFor(retptr, this.__wbg_ptr, ptr0, len0);
131
402
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
@@ -137,6 +408,14 @@ class SourceMap {
137
408
  wasm.__wbindgen_add_to_stack_pointer(16);
138
409
  }
139
410
  }
411
+ /**
412
+ * Number of range mappings in the source map.
413
+ * @returns {number}
414
+ */
415
+ get rangeMappingCount() {
416
+ const ret = wasm.sourcemap_rangeMappingCount(this.__wbg_ptr);
417
+ return ret >>> 0;
418
+ }
140
419
  /**
141
420
  * Resolve a source index to its filename.
142
421
  * @param {number} index
@@ -158,6 +437,35 @@ class SourceMap {
158
437
  wasm.__wbindgen_export4(deferred1_0, deferred1_1, 1);
159
438
  }
160
439
  }
440
+ /**
441
+ * Get source content for a given source index.
442
+ * @param {number} index
443
+ * @returns {any}
444
+ */
445
+ sourceContentFor(index) {
446
+ const ret = wasm.sourcemap_sourceContentFor(this.__wbg_ptr, index);
447
+ return takeObject(ret);
448
+ }
449
+ /**
450
+ * Get the sourceRoot property.
451
+ * @returns {string | undefined}
452
+ */
453
+ get sourceRoot() {
454
+ try {
455
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
456
+ wasm.sourcemap_sourceRoot(retptr, this.__wbg_ptr);
457
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
458
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
459
+ let v1;
460
+ if (r0 !== 0) {
461
+ v1 = getStringFromWasm0(r0, r1).slice();
462
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
463
+ }
464
+ return v1;
465
+ } finally {
466
+ wasm.__wbindgen_add_to_stack_pointer(16);
467
+ }
468
+ }
161
469
  /**
162
470
  * Get all source filenames.
163
471
  * @returns {any[]}
@@ -175,10 +483,49 @@ class SourceMap {
175
483
  wasm.__wbindgen_add_to_stack_pointer(16);
176
484
  }
177
485
  }
486
+ /**
487
+ * Get all sources content (array of string|null).
488
+ * @returns {any[]}
489
+ */
490
+ get sourcesContent() {
491
+ try {
492
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
493
+ wasm.sourcemap_sourcesContent(retptr, this.__wbg_ptr);
494
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
495
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
496
+ var v1 = getArrayJsValueFromWasm0(r0, r1).slice();
497
+ wasm.__wbindgen_export4(r0, r1 * 4, 4);
498
+ return v1;
499
+ } finally {
500
+ wasm.__wbindgen_add_to_stack_pointer(16);
501
+ }
502
+ }
178
503
  }
179
504
  if (Symbol.dispose) SourceMap.prototype[Symbol.dispose] = SourceMap.prototype.free;
180
505
  exports.SourceMap = SourceMap;
181
506
 
507
+ /**
508
+ * Get the pointer to the static result buffer in WASM linear memory.
509
+ * JS side creates an Int32Array view at this offset to read lookup results
510
+ * without any allocation or copying.
511
+ * @returns {number}
512
+ */
513
+ function resultPtr() {
514
+ const ret = wasm.resultPtr();
515
+ return ret >>> 0;
516
+ }
517
+ exports.resultPtr = resultPtr;
518
+
519
+ /**
520
+ * Expose WASM linear memory for direct buffer access from JS.
521
+ * @returns {any}
522
+ */
523
+ function wasmMemory() {
524
+ const ret = wasm.wasmMemory();
525
+ return takeObject(ret);
526
+ }
527
+ exports.wasmMemory = wasmMemory;
528
+
182
529
  function __wbg_get_imports() {
183
530
  const import0 = {
184
531
  __proto__: null,
@@ -186,6 +533,18 @@ function __wbg_get_imports() {
186
533
  const ret = Error(getStringFromWasm0(arg0, arg1));
187
534
  return addHeapObject(ret);
188
535
  },
536
+ __wbg___wbindgen_memory_edb3f01e3930bbf6: function() {
537
+ const ret = wasm.memory;
538
+ return addHeapObject(ret);
539
+ },
540
+ __wbg___wbindgen_string_get_395e606bd0ee4427: function(arg0, arg1) {
541
+ const obj = getObject(arg1);
542
+ const ret = typeof(obj) === 'string' ? obj : undefined;
543
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_export, wasm.__wbindgen_export2);
544
+ var len1 = WASM_VECTOR_LEN;
545
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
546
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
547
+ },
189
548
  __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
190
549
  throw new Error(getStringFromWasm0(arg0, arg1));
191
550
  },
@@ -251,6 +610,11 @@ function getArrayJsValueFromWasm0(ptr, len) {
251
610
  return result;
252
611
  }
253
612
 
613
+ function getArrayU32FromWasm0(ptr, len) {
614
+ ptr = ptr >>> 0;
615
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
616
+ }
617
+
254
618
  let cachedDataViewMemory0 = null;
255
619
  function getDataViewMemory0() {
256
620
  if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
@@ -294,7 +658,7 @@ function handleError(f, args) {
294
658
  try {
295
659
  return f.apply(this, args);
296
660
  } catch (e) {
297
- wasm.__wbindgen_export(addHeapObject(e));
661
+ wasm.__wbindgen_export3(addHeapObject(e));
298
662
  }
299
663
  }
300
664
 
@@ -303,6 +667,10 @@ heap.push(undefined, null, true, false);
303
667
 
304
668
  let heap_next = heap.length;
305
669
 
670
+ function isLikeNone(x) {
671
+ return x === undefined || x === null;
672
+ }
673
+
306
674
  function passArray32ToWasm0(arg, malloc) {
307
675
  const ptr = malloc(arg.length * 4, 4) >>> 0;
308
676
  getUint32ArrayMemory0().set(arg, ptr / 4);
@@ -310,6 +678,16 @@ function passArray32ToWasm0(arg, malloc) {
310
678
  return ptr;
311
679
  }
312
680
 
681
+ function passArrayJsValueToWasm0(array, malloc) {
682
+ const ptr = malloc(array.length * 4, 4) >>> 0;
683
+ const mem = getDataViewMemory0();
684
+ for (let i = 0; i < array.length; i++) {
685
+ mem.setUint32(ptr + 4 * i, addHeapObject(array[i]), true);
686
+ }
687
+ WASM_VECTOR_LEN = array.length;
688
+ return ptr;
689
+ }
690
+
313
691
  function passStringToWasm0(arg, malloc, realloc) {
314
692
  if (realloc === undefined) {
315
693
  const buf = cachedTextEncoder.encode(arg);
Binary file
@@ -2,18 +2,39 @@
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 resultPtr: () => number;
6
+ export const sourcemap_allGeneratedPositionsFor: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
7
+ export const sourcemap_allMappingsFlat: (a: number, b: number) => void;
8
+ export const sourcemap_debugId: (a: number, b: number) => void;
9
+ export const sourcemap_encodedMappings: (a: number, b: number) => void;
10
+ export const sourcemap_encodedRangeMappings: (a: number) => number;
11
+ export const sourcemap_file: (a: number, b: number) => void;
12
+ export const sourcemap_fromVlq: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number, m: number, n: number, o: number, p: number, q: number) => void;
5
13
  export const sourcemap_generatedPositionFor: (a: number, b: number, c: number, d: number, e: number) => number;
14
+ export const sourcemap_generatedPositionForWithBias: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
15
+ export const sourcemap_hasRangeMappings: (a: number) => number;
16
+ export const sourcemap_ignoreList: (a: number, b: number) => void;
17
+ export const sourcemap_isIgnoredIndex: (a: number, b: number) => number;
6
18
  export const sourcemap_lineCount: (a: number) => number;
19
+ export const sourcemap_mapRange: (a: number, b: number, c: number, d: number, e: number) => number;
7
20
  export const sourcemap_mappingCount: (a: number) => number;
8
21
  export const sourcemap_name: (a: number, b: number, c: number) => void;
9
22
  export const sourcemap_names: (a: number, b: number) => void;
10
23
  export const sourcemap_new: (a: number, b: number, c: number) => void;
24
+ export const sourcemap_originalPositionBuf: (a: number, b: number, c: number) => number;
25
+ export const sourcemap_originalPositionFlat: (a: number, b: number, c: number, d: number) => void;
11
26
  export const sourcemap_originalPositionFor: (a: number, b: number, c: number) => number;
27
+ export const sourcemap_originalPositionForWithBias: (a: number, b: number, c: number, d: number) => number;
12
28
  export const sourcemap_originalPositionsFor: (a: number, b: number, c: number, d: number) => void;
29
+ export const sourcemap_rangeMappingCount: (a: number) => number;
13
30
  export const sourcemap_source: (a: number, b: number, c: number) => void;
31
+ export const sourcemap_sourceContentFor: (a: number, b: number) => number;
32
+ export const sourcemap_sourceRoot: (a: number, b: number) => void;
14
33
  export const sourcemap_sources: (a: number, b: number) => void;
15
- 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;
34
+ export const sourcemap_sourcesContent: (a: number, b: number) => void;
35
+ export const wasmMemory: () => number;
36
+ export const __wbindgen_export: (a: number, b: number) => number;
37
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
38
+ export const __wbindgen_export3: (a: number) => void;
18
39
  export const __wbindgen_add_to_stack_pointer: (a: number) => number;
19
40
  export const __wbindgen_export4: (a: number, b: number, c: number) => void;