@srcmap/sourcemap 0.1.1 → 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 +93 -0
- package/package.json +14 -11
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @srcmap/sourcemap
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@srcmap/sourcemap)
|
|
4
|
+
[](https://github.com/BartWaardenburg/srcmap/actions/workflows/ci.yml)
|
|
5
|
+
[](https://github.com/BartWaardenburg/srcmap/actions/workflows/coverage.yml)
|
|
6
|
+
|
|
7
|
+
High-performance source map parser and consumer powered by Rust via [NAPI](https://napi.rs).
|
|
8
|
+
|
|
9
|
+
Parses source map JSON and provides position lookups. Implements [ECMA-426](https://tc39.es/ecma426/) (Source Map v3). Alternative to [`@jridgewell/trace-mapping`](https://github.com/jridgewell/trace-mapping).
|
|
10
|
+
|
|
11
|
+
> For batch lookups in Node.js, consider [`@srcmap/sourcemap-wasm`](https://www.npmjs.com/package/@srcmap/sourcemap-wasm) which avoids NAPI per-call overhead and is faster for bulk operations.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @srcmap/sourcemap
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Prebuilt binaries are available for:
|
|
20
|
+
- macOS (x64, arm64)
|
|
21
|
+
- Linux (x64, arm64, glibc + musl)
|
|
22
|
+
- Windows (x64)
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
import { SourceMap } from '@srcmap/sourcemap';
|
|
28
|
+
|
|
29
|
+
const sm = new SourceMap(jsonString);
|
|
30
|
+
|
|
31
|
+
// Forward lookup: generated -> original (0-based lines and columns)
|
|
32
|
+
const loc = sm.originalPositionFor(42, 10);
|
|
33
|
+
// { source: 'src/app.ts', line: 10, column: 4, name: 'handleClick' }
|
|
34
|
+
// Returns null if no mapping exists
|
|
35
|
+
|
|
36
|
+
// Reverse lookup: original -> generated
|
|
37
|
+
const pos = sm.generatedPositionFor('src/app.ts', 10, 4);
|
|
38
|
+
// { line: 42, column: 10 }
|
|
39
|
+
|
|
40
|
+
// Batch lookup — amortizes NAPI overhead
|
|
41
|
+
const positions = new Int32Array([42, 10, 43, 0, 44, 5]);
|
|
42
|
+
const results = sm.originalPositionsFor(positions);
|
|
43
|
+
// Int32Array [srcIdx, line, col, nameIdx, ...]
|
|
44
|
+
// -1 means no mapping / no name
|
|
45
|
+
|
|
46
|
+
// Resolve indices
|
|
47
|
+
const source = sm.source(results[0]);
|
|
48
|
+
const name = results[3] >= 0 ? sm.name(results[3]) : null;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API
|
|
52
|
+
|
|
53
|
+
### `new SourceMap(json: string)`
|
|
54
|
+
|
|
55
|
+
Parse a source map from a JSON string.
|
|
56
|
+
|
|
57
|
+
### Instance methods
|
|
58
|
+
|
|
59
|
+
| Method | Returns | Description |
|
|
60
|
+
|--------|---------|-------------|
|
|
61
|
+
| `originalPositionFor(line, column)` | `{ source, line, column, name } \| null` | Forward lookup (0-based) |
|
|
62
|
+
| `generatedPositionFor(source, line, column)` | `{ line, column } \| null` | Reverse lookup (0-based) |
|
|
63
|
+
| `originalPositionsFor(positions: Int32Array)` | `Int32Array` | Batch forward lookup |
|
|
64
|
+
| `source(index)` | `string` | Resolve source index to filename |
|
|
65
|
+
| `name(index)` | `string` | Resolve name index to string |
|
|
66
|
+
|
|
67
|
+
### Instance properties
|
|
68
|
+
|
|
69
|
+
| Property | Type | Description |
|
|
70
|
+
|----------|------|-------------|
|
|
71
|
+
| `lineCount` | `number` | Number of generated lines |
|
|
72
|
+
| `mappingCount` | `number` | Total decoded mappings |
|
|
73
|
+
| `sources` | `string[]` | All source filenames |
|
|
74
|
+
| `names` | `string[]` | All names |
|
|
75
|
+
|
|
76
|
+
## Performance
|
|
77
|
+
|
|
78
|
+
| Operation | @srcmap/sourcemap | @jridgewell/trace-mapping |
|
|
79
|
+
|-----------|-------------------|---------------------------|
|
|
80
|
+
| 1000x batch lookup (large) | 160 us | 15 us |
|
|
81
|
+
| Single lookup | 345 ns | 24 ns |
|
|
82
|
+
|
|
83
|
+
NAPI has ~300ns overhead per call. For bulk operations, use the batch API (`originalPositionsFor`) or consider the [WASM package](https://www.npmjs.com/package/@srcmap/sourcemap-wasm) which has lower per-call overhead.
|
|
84
|
+
|
|
85
|
+
## Part of [srcmap](https://github.com/BartWaardenburg/srcmap)
|
|
86
|
+
|
|
87
|
+
High-performance source map tooling written in Rust. See also:
|
|
88
|
+
- [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) - VLQ codec (NAPI)
|
|
89
|
+
- [`@srcmap/sourcemap-wasm`](https://www.npmjs.com/package/@srcmap/sourcemap-wasm) - Source map parser (WASM, recommended for batch ops)
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@srcmap/sourcemap",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "High-performance source map parser and consumer powered by Rust",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -26,27 +26,30 @@
|
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"files": [
|
|
28
28
|
"index.js",
|
|
29
|
-
"index.d.ts"
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"README.md"
|
|
30
31
|
],
|
|
31
32
|
"optionalDependencies": {
|
|
32
|
-
"@srcmap/sourcemap-darwin-x64": "0.1.
|
|
33
|
-
"@srcmap/sourcemap-darwin-arm64": "0.1.
|
|
34
|
-
"@srcmap/sourcemap-linux-x64-gnu": "0.1.
|
|
35
|
-
"@srcmap/sourcemap-linux-x64-musl": "0.1.
|
|
36
|
-
"@srcmap/sourcemap-linux-arm64-gnu": "0.1.
|
|
37
|
-
"@srcmap/sourcemap-linux-arm64-musl": "0.1.
|
|
38
|
-
"@srcmap/sourcemap-win32-x64-msvc": "0.1.
|
|
33
|
+
"@srcmap/sourcemap-darwin-x64": "0.1.3",
|
|
34
|
+
"@srcmap/sourcemap-darwin-arm64": "0.1.3",
|
|
35
|
+
"@srcmap/sourcemap-linux-x64-gnu": "0.1.3",
|
|
36
|
+
"@srcmap/sourcemap-linux-x64-musl": "0.1.3",
|
|
37
|
+
"@srcmap/sourcemap-linux-arm64-gnu": "0.1.3",
|
|
38
|
+
"@srcmap/sourcemap-linux-arm64-musl": "0.1.3",
|
|
39
|
+
"@srcmap/sourcemap-win32-x64-msvc": "0.1.3"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"@napi-rs/cli": "^3.0.0"
|
|
42
43
|
},
|
|
43
44
|
"scripts": {
|
|
44
45
|
"build": "napi build --release --platform",
|
|
45
|
-
"build:debug": "napi build --platform"
|
|
46
|
+
"build:debug": "napi build --platform",
|
|
47
|
+
"test": "node --test __tests__/sourcemap.test.mjs",
|
|
48
|
+
"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.test.mjs"
|
|
46
49
|
},
|
|
47
50
|
"repository": {
|
|
48
51
|
"type": "git",
|
|
49
|
-
"url": "https://github.com/
|
|
52
|
+
"url": "git+https://github.com/BartWaardenburg/srcmap.git"
|
|
50
53
|
},
|
|
51
54
|
"keywords": [
|
|
52
55
|
"sourcemap",
|