Ajout de promotion et de commande
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
Copyright 2024 Justin Ridgewell <justin@ridgewell.name>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+348
@@ -0,0 +1,348 @@
|
||||
# @jridgewell/trace-mapping
|
||||
|
||||
> Trace the original position through a source map
|
||||
|
||||
`trace-mapping` allows you to take the line and column of an output file and trace it to the
|
||||
original location in the source file through a source map.
|
||||
|
||||
You may already be familiar with the [`source-map`][source-map] package's `SourceMapConsumer`. This
|
||||
provides the same `originalPositionFor` and `generatedPositionFor` API, without requiring WASM.
|
||||
|
||||
## Installation
|
||||
|
||||
```sh
|
||||
npm install @jridgewell/trace-mapping
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```typescript
|
||||
import {
|
||||
TraceMap,
|
||||
originalPositionFor,
|
||||
generatedPositionFor,
|
||||
sourceContentFor,
|
||||
isIgnored,
|
||||
} from '@jridgewell/trace-mapping';
|
||||
|
||||
const tracer = new TraceMap({
|
||||
version: 3,
|
||||
sources: ['input.js'],
|
||||
sourcesContent: ['content of input.js'],
|
||||
names: ['foo'],
|
||||
mappings: 'KAyCIA',
|
||||
ignoreList: [],
|
||||
});
|
||||
|
||||
// Lines start at line 1, columns at column 0.
|
||||
const traced = originalPositionFor(tracer, { line: 1, column: 5 });
|
||||
assert.deepEqual(traced, {
|
||||
source: 'input.js',
|
||||
line: 42,
|
||||
column: 4,
|
||||
name: 'foo',
|
||||
});
|
||||
|
||||
const content = sourceContentFor(tracer, traced.source);
|
||||
assert.strictEqual(content, 'content for input.js');
|
||||
|
||||
const generated = generatedPositionFor(tracer, {
|
||||
source: 'input.js',
|
||||
line: 42,
|
||||
column: 4,
|
||||
});
|
||||
assert.deepEqual(generated, {
|
||||
line: 1,
|
||||
column: 5,
|
||||
});
|
||||
|
||||
const ignored = isIgnored(tracer, 'input.js');
|
||||
assert.equal(ignored, false);
|
||||
```
|
||||
|
||||
We also provide a lower level API to get the actual segment that matches our line and column. Unlike
|
||||
`originalPositionFor`, `traceSegment` uses a 0-base for `line`:
|
||||
|
||||
```typescript
|
||||
import { traceSegment } from '@jridgewell/trace-mapping';
|
||||
|
||||
// line is 0-base.
|
||||
const traced = traceSegment(tracer, /* line */ 0, /* column */ 5);
|
||||
|
||||
// Segments are [outputColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
|
||||
// Again, line is 0-base and so is sourceLine
|
||||
assert.deepEqual(traced, [5, 0, 41, 4, 0]);
|
||||
```
|
||||
|
||||
### SectionedSourceMaps
|
||||
|
||||
The sourcemap spec defines a special `sections` field that's designed to handle concatenation of
|
||||
output code with associated sourcemaps. This type of sourcemap is rarely used (no major build tool
|
||||
produces it), but if you are hand coding a concatenation you may need it. We provide an `AnyMap`
|
||||
helper that can receive either a regular sourcemap or a `SectionedSourceMap` and returns a
|
||||
`TraceMap` instance:
|
||||
|
||||
```typescript
|
||||
import { AnyMap } from '@jridgewell/trace-mapping';
|
||||
const fooOutput = 'foo';
|
||||
const barOutput = 'bar';
|
||||
const output = [fooOutput, barOutput].join('\n');
|
||||
|
||||
const sectioned = new AnyMap({
|
||||
version: 3,
|
||||
sections: [
|
||||
{
|
||||
// 0-base line and column
|
||||
offset: { line: 0, column: 0 },
|
||||
// fooOutput's sourcemap
|
||||
map: {
|
||||
version: 3,
|
||||
sources: ['foo.js'],
|
||||
names: ['foo'],
|
||||
mappings: 'AAAAA',
|
||||
},
|
||||
},
|
||||
{
|
||||
// barOutput's sourcemap will not affect the first line, only the second
|
||||
offset: { line: 1, column: 0 },
|
||||
map: {
|
||||
version: 3,
|
||||
sources: ['bar.js'],
|
||||
names: ['bar'],
|
||||
mappings: 'AAAAA',
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const traced = originalPositionFor(sectioned, {
|
||||
line: 2,
|
||||
column: 0,
|
||||
});
|
||||
|
||||
assert.deepEqual(traced, {
|
||||
source: 'bar.js',
|
||||
line: 1,
|
||||
column: 0,
|
||||
name: 'bar',
|
||||
});
|
||||
```
|
||||
|
||||
## Benchmarks
|
||||
|
||||
```
|
||||
node v20.10.0
|
||||
|
||||
amp.js.map - 45120 segments
|
||||
|
||||
Memory Usage:
|
||||
trace-mapping decoded 414164 bytes
|
||||
trace-mapping encoded 6274352 bytes
|
||||
source-map-js 10968904 bytes
|
||||
source-map-0.6.1 17587160 bytes
|
||||
source-map-0.8.0 8812155 bytes
|
||||
Chrome dev tools 8672912 bytes
|
||||
Smallest memory usage is trace-mapping decoded
|
||||
|
||||
Init speed:
|
||||
trace-mapping: decoded JSON input x 205 ops/sec ±0.19% (88 runs sampled)
|
||||
trace-mapping: encoded JSON input x 405 ops/sec ±1.47% (88 runs sampled)
|
||||
trace-mapping: decoded Object input x 4,645 ops/sec ±0.15% (98 runs sampled)
|
||||
trace-mapping: encoded Object input x 458 ops/sec ±1.63% (91 runs sampled)
|
||||
source-map-js: encoded Object input x 75.48 ops/sec ±1.64% (67 runs sampled)
|
||||
source-map-0.6.1: encoded Object input x 39.37 ops/sec ±1.44% (53 runs sampled)
|
||||
Chrome dev tools: encoded Object input x 150 ops/sec ±1.76% (79 runs sampled)
|
||||
Fastest is trace-mapping: decoded Object input
|
||||
|
||||
Trace speed (random):
|
||||
trace-mapping: decoded originalPositionFor x 44,946 ops/sec ±0.16% (99 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 37,995 ops/sec ±1.81% (89 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 9,230 ops/sec ±1.36% (93 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 8,057 ops/sec ±0.84% (96 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 28,198 ops/sec ±1.12% (91 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 46,276 ops/sec ±1.35% (95 runs sampled)
|
||||
Fastest is Chrome dev tools: encoded originalPositionFor
|
||||
|
||||
Trace speed (ascending):
|
||||
trace-mapping: decoded originalPositionFor x 204,406 ops/sec ±0.19% (97 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 196,695 ops/sec ±0.24% (99 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 11,948 ops/sec ±0.94% (99 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 10,730 ops/sec ±0.36% (100 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 51,427 ops/sec ±0.21% (98 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 162,615 ops/sec ±0.18% (98 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
|
||||
***
|
||||
|
||||
|
||||
babel.min.js.map - 347793 segments
|
||||
|
||||
Memory Usage:
|
||||
trace-mapping decoded 18504 bytes
|
||||
trace-mapping encoded 35428008 bytes
|
||||
source-map-js 51676808 bytes
|
||||
source-map-0.6.1 63367136 bytes
|
||||
source-map-0.8.0 43158400 bytes
|
||||
Chrome dev tools 50721552 bytes
|
||||
Smallest memory usage is trace-mapping decoded
|
||||
|
||||
Init speed:
|
||||
trace-mapping: decoded JSON input x 17.82 ops/sec ±6.35% (35 runs sampled)
|
||||
trace-mapping: encoded JSON input x 31.57 ops/sec ±7.50% (43 runs sampled)
|
||||
trace-mapping: decoded Object input x 867 ops/sec ±0.74% (94 runs sampled)
|
||||
trace-mapping: encoded Object input x 33.83 ops/sec ±7.66% (46 runs sampled)
|
||||
source-map-js: encoded Object input x 6.58 ops/sec ±3.31% (20 runs sampled)
|
||||
source-map-0.6.1: encoded Object input x 4.23 ops/sec ±3.43% (15 runs sampled)
|
||||
Chrome dev tools: encoded Object input x 22.14 ops/sec ±3.79% (41 runs sampled)
|
||||
Fastest is trace-mapping: decoded Object input
|
||||
|
||||
Trace speed (random):
|
||||
trace-mapping: decoded originalPositionFor x 78,234 ops/sec ±1.48% (29 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 60,761 ops/sec ±1.35% (21 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 51,448 ops/sec ±2.17% (89 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 47,221 ops/sec ±1.99% (15 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 84,002 ops/sec ±1.45% (27 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 106,457 ops/sec ±1.38% (37 runs sampled)
|
||||
Fastest is Chrome dev tools: encoded originalPositionFor
|
||||
|
||||
Trace speed (ascending):
|
||||
trace-mapping: decoded originalPositionFor x 930,943 ops/sec ±0.25% (99 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 843,545 ops/sec ±0.34% (97 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 114,510 ops/sec ±1.37% (36 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 87,412 ops/sec ±0.72% (92 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 197,709 ops/sec ±0.89% (59 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 688,983 ops/sec ±0.33% (98 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
|
||||
***
|
||||
|
||||
|
||||
preact.js.map - 1992 segments
|
||||
|
||||
Memory Usage:
|
||||
trace-mapping decoded 33136 bytes
|
||||
trace-mapping encoded 254240 bytes
|
||||
source-map-js 837488 bytes
|
||||
source-map-0.6.1 961928 bytes
|
||||
source-map-0.8.0 54384 bytes
|
||||
Chrome dev tools 709680 bytes
|
||||
Smallest memory usage is trace-mapping decoded
|
||||
|
||||
Init speed:
|
||||
trace-mapping: decoded JSON input x 3,709 ops/sec ±0.13% (99 runs sampled)
|
||||
trace-mapping: encoded JSON input x 6,447 ops/sec ±0.22% (101 runs sampled)
|
||||
trace-mapping: decoded Object input x 83,062 ops/sec ±0.23% (100 runs sampled)
|
||||
trace-mapping: encoded Object input x 14,980 ops/sec ±0.28% (100 runs sampled)
|
||||
source-map-js: encoded Object input x 2,544 ops/sec ±0.16% (99 runs sampled)
|
||||
source-map-0.6.1: encoded Object input x 1,221 ops/sec ±0.37% (97 runs sampled)
|
||||
Chrome dev tools: encoded Object input x 4,241 ops/sec ±0.39% (93 runs sampled)
|
||||
Fastest is trace-mapping: decoded Object input
|
||||
|
||||
Trace speed (random):
|
||||
trace-mapping: decoded originalPositionFor x 91,028 ops/sec ±0.14% (94 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 84,348 ops/sec ±0.26% (98 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 26,998 ops/sec ±0.23% (98 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 18,049 ops/sec ±0.26% (100 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 41,916 ops/sec ±0.28% (98 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 88,616 ops/sec ±0.14% (98 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
Trace speed (ascending):
|
||||
trace-mapping: decoded originalPositionFor x 319,960 ops/sec ±0.16% (100 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 302,153 ops/sec ±0.18% (100 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 35,574 ops/sec ±0.19% (100 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 19,943 ops/sec ±0.12% (101 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 54,648 ops/sec ±0.20% (99 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 278,319 ops/sec ±0.17% (102 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
|
||||
***
|
||||
|
||||
|
||||
react.js.map - 5726 segments
|
||||
|
||||
Memory Usage:
|
||||
trace-mapping decoded 10872 bytes
|
||||
trace-mapping encoded 681512 bytes
|
||||
source-map-js 2563944 bytes
|
||||
source-map-0.6.1 2150864 bytes
|
||||
source-map-0.8.0 88680 bytes
|
||||
Chrome dev tools 1149576 bytes
|
||||
Smallest memory usage is trace-mapping decoded
|
||||
|
||||
Init speed:
|
||||
trace-mapping: decoded JSON input x 1,887 ops/sec ±0.28% (99 runs sampled)
|
||||
trace-mapping: encoded JSON input x 4,749 ops/sec ±0.48% (97 runs sampled)
|
||||
trace-mapping: decoded Object input x 74,236 ops/sec ±0.11% (99 runs sampled)
|
||||
trace-mapping: encoded Object input x 5,752 ops/sec ±0.38% (100 runs sampled)
|
||||
source-map-js: encoded Object input x 806 ops/sec ±0.19% (97 runs sampled)
|
||||
source-map-0.6.1: encoded Object input x 418 ops/sec ±0.33% (94 runs sampled)
|
||||
Chrome dev tools: encoded Object input x 1,524 ops/sec ±0.57% (92 runs sampled)
|
||||
Fastest is trace-mapping: decoded Object input
|
||||
|
||||
Trace speed (random):
|
||||
trace-mapping: decoded originalPositionFor x 620,201 ops/sec ±0.33% (96 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 579,548 ops/sec ±0.35% (97 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 230,983 ops/sec ±0.62% (54 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 158,145 ops/sec ±0.80% (46 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 343,801 ops/sec ±0.55% (96 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 659,649 ops/sec ±0.49% (98 runs sampled)
|
||||
Fastest is Chrome dev tools: encoded originalPositionFor
|
||||
|
||||
Trace speed (ascending):
|
||||
trace-mapping: decoded originalPositionFor x 2,368,079 ops/sec ±0.32% (98 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 2,134,039 ops/sec ±2.72% (87 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 290,120 ops/sec ±2.49% (82 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 187,613 ops/sec ±0.86% (49 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 479,569 ops/sec ±0.65% (96 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 2,048,414 ops/sec ±0.24% (98 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
|
||||
***
|
||||
|
||||
|
||||
vscode.map - 2141001 segments
|
||||
|
||||
Memory Usage:
|
||||
trace-mapping decoded 5206584 bytes
|
||||
trace-mapping encoded 208370336 bytes
|
||||
source-map-js 278493008 bytes
|
||||
source-map-0.6.1 391564048 bytes
|
||||
source-map-0.8.0 257508787 bytes
|
||||
Chrome dev tools 291053000 bytes
|
||||
Smallest memory usage is trace-mapping decoded
|
||||
|
||||
Init speed:
|
||||
trace-mapping: decoded JSON input x 1.63 ops/sec ±33.88% (9 runs sampled)
|
||||
trace-mapping: encoded JSON input x 3.29 ops/sec ±36.13% (13 runs sampled)
|
||||
trace-mapping: decoded Object input x 103 ops/sec ±0.93% (77 runs sampled)
|
||||
trace-mapping: encoded Object input x 5.42 ops/sec ±28.54% (19 runs sampled)
|
||||
source-map-js: encoded Object input x 1.07 ops/sec ±13.84% (7 runs sampled)
|
||||
source-map-0.6.1: encoded Object input x 0.60 ops/sec ±2.43% (6 runs sampled)
|
||||
Chrome dev tools: encoded Object input x 2.61 ops/sec ±22.00% (11 runs sampled)
|
||||
Fastest is trace-mapping: decoded Object input
|
||||
|
||||
Trace speed (random):
|
||||
trace-mapping: decoded originalPositionFor x 257,019 ops/sec ±0.97% (93 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 179,163 ops/sec ±0.83% (92 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 73,337 ops/sec ±1.35% (87 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 38,797 ops/sec ±1.66% (88 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 107,758 ops/sec ±1.94% (45 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 188,550 ops/sec ±1.85% (79 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
|
||||
Trace speed (ascending):
|
||||
trace-mapping: decoded originalPositionFor x 447,621 ops/sec ±3.64% (94 runs sampled)
|
||||
trace-mapping: encoded originalPositionFor x 323,698 ops/sec ±5.20% (88 runs sampled)
|
||||
source-map-js: encoded originalPositionFor x 78,387 ops/sec ±1.69% (89 runs sampled)
|
||||
source-map-0.6.1: encoded originalPositionFor x 41,016 ops/sec ±3.01% (25 runs sampled)
|
||||
source-map-0.8.0: encoded originalPositionFor x 124,204 ops/sec ±0.90% (92 runs sampled)
|
||||
Chrome dev tools: encoded originalPositionFor x 230,087 ops/sec ±2.61% (93 runs sampled)
|
||||
Fastest is trace-mapping: decoded originalPositionFor
|
||||
```
|
||||
|
||||
[source-map]: https://www.npmjs.com/package/source-map
|
||||
+493
@@ -0,0 +1,493 @@
|
||||
// src/trace-mapping.ts
|
||||
import { encode, decode } from "@jridgewell/sourcemap-codec";
|
||||
|
||||
// src/resolve.ts
|
||||
import resolveUri from "@jridgewell/resolve-uri";
|
||||
|
||||
// src/strip-filename.ts
|
||||
function stripFilename(path) {
|
||||
if (!path) return "";
|
||||
const index = path.lastIndexOf("/");
|
||||
return path.slice(0, index + 1);
|
||||
}
|
||||
|
||||
// src/resolve.ts
|
||||
function resolver(mapUrl, sourceRoot) {
|
||||
const from = stripFilename(mapUrl);
|
||||
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
||||
return (source) => resolveUri(prefix + (source || ""), from);
|
||||
}
|
||||
|
||||
// src/sourcemap-segment.ts
|
||||
var COLUMN = 0;
|
||||
var SOURCES_INDEX = 1;
|
||||
var SOURCE_LINE = 2;
|
||||
var SOURCE_COLUMN = 3;
|
||||
var NAMES_INDEX = 4;
|
||||
var REV_GENERATED_LINE = 1;
|
||||
var REV_GENERATED_COLUMN = 2;
|
||||
|
||||
// src/sort.ts
|
||||
function maybeSort(mappings, owned) {
|
||||
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
||||
if (unsortedIndex === mappings.length) return mappings;
|
||||
if (!owned) mappings = mappings.slice();
|
||||
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
||||
mappings[i] = sortSegments(mappings[i], owned);
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
function nextUnsortedSegmentLine(mappings, start) {
|
||||
for (let i = start; i < mappings.length; i++) {
|
||||
if (!isSorted(mappings[i])) return i;
|
||||
}
|
||||
return mappings.length;
|
||||
}
|
||||
function isSorted(line) {
|
||||
for (let j = 1; j < line.length; j++) {
|
||||
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
function sortSegments(line, owned) {
|
||||
if (!owned) line = line.slice();
|
||||
return line.sort(sortComparator);
|
||||
}
|
||||
function sortComparator(a, b) {
|
||||
return a[COLUMN] - b[COLUMN];
|
||||
}
|
||||
|
||||
// src/by-source.ts
|
||||
function buildBySources(decoded, memos) {
|
||||
const sources = memos.map(() => []);
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
const line = decoded[i];
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const seg = line[j];
|
||||
if (seg.length === 1) continue;
|
||||
const sourceIndex2 = seg[SOURCES_INDEX];
|
||||
const sourceLine = seg[SOURCE_LINE];
|
||||
const sourceColumn = seg[SOURCE_COLUMN];
|
||||
const source = sources[sourceIndex2];
|
||||
const segs = source[sourceLine] || (source[sourceLine] = []);
|
||||
segs.push([sourceColumn, i, seg[COLUMN]]);
|
||||
}
|
||||
}
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const source = sources[i];
|
||||
for (let j = 0; j < source.length; j++) {
|
||||
const line = source[j];
|
||||
if (line) line.sort(sortComparator);
|
||||
}
|
||||
}
|
||||
return sources;
|
||||
}
|
||||
|
||||
// src/binary-search.ts
|
||||
var found = false;
|
||||
function binarySearch(haystack, needle, low, high) {
|
||||
while (low <= high) {
|
||||
const mid = low + (high - low >> 1);
|
||||
const cmp = haystack[mid][COLUMN] - needle;
|
||||
if (cmp === 0) {
|
||||
found = true;
|
||||
return mid;
|
||||
}
|
||||
if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
found = false;
|
||||
return low - 1;
|
||||
}
|
||||
function upperBound(haystack, needle, index) {
|
||||
for (let i = index + 1; i < haystack.length; index = i++) {
|
||||
if (haystack[i][COLUMN] !== needle) break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
function lowerBound(haystack, needle, index) {
|
||||
for (let i = index - 1; i >= 0; index = i--) {
|
||||
if (haystack[i][COLUMN] !== needle) break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
function memoizedState() {
|
||||
return {
|
||||
lastKey: -1,
|
||||
lastNeedle: -1,
|
||||
lastIndex: -1
|
||||
};
|
||||
}
|
||||
function memoizedBinarySearch(haystack, needle, state, key) {
|
||||
const { lastKey, lastNeedle, lastIndex } = state;
|
||||
let low = 0;
|
||||
let high = haystack.length - 1;
|
||||
if (key === lastKey) {
|
||||
if (needle === lastNeedle) {
|
||||
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
||||
return lastIndex;
|
||||
}
|
||||
if (needle >= lastNeedle) {
|
||||
low = lastIndex === -1 ? 0 : lastIndex;
|
||||
} else {
|
||||
high = lastIndex;
|
||||
}
|
||||
}
|
||||
state.lastKey = key;
|
||||
state.lastNeedle = needle;
|
||||
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
||||
}
|
||||
|
||||
// src/types.ts
|
||||
function parse(map) {
|
||||
return typeof map === "string" ? JSON.parse(map) : map;
|
||||
}
|
||||
|
||||
// src/flatten-map.ts
|
||||
var FlattenMap = function(map, mapUrl) {
|
||||
const parsed = parse(map);
|
||||
if (!("sections" in parsed)) {
|
||||
return new TraceMap(parsed, mapUrl);
|
||||
}
|
||||
const mappings = [];
|
||||
const sources = [];
|
||||
const sourcesContent = [];
|
||||
const names = [];
|
||||
const ignoreList = [];
|
||||
recurse(
|
||||
parsed,
|
||||
mapUrl,
|
||||
mappings,
|
||||
sources,
|
||||
sourcesContent,
|
||||
names,
|
||||
ignoreList,
|
||||
0,
|
||||
0,
|
||||
Infinity,
|
||||
Infinity
|
||||
);
|
||||
const joined = {
|
||||
version: 3,
|
||||
file: parsed.file,
|
||||
names,
|
||||
sources,
|
||||
sourcesContent,
|
||||
mappings,
|
||||
ignoreList
|
||||
};
|
||||
return presortedDecodedMap(joined);
|
||||
};
|
||||
function recurse(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
||||
const { sections } = input;
|
||||
for (let i = 0; i < sections.length; i++) {
|
||||
const { map, offset } = sections[i];
|
||||
let sl = stopLine;
|
||||
let sc = stopColumn;
|
||||
if (i + 1 < sections.length) {
|
||||
const nextOffset = sections[i + 1].offset;
|
||||
sl = Math.min(stopLine, lineOffset + nextOffset.line);
|
||||
if (sl === stopLine) {
|
||||
sc = Math.min(stopColumn, columnOffset + nextOffset.column);
|
||||
} else if (sl < stopLine) {
|
||||
sc = columnOffset + nextOffset.column;
|
||||
}
|
||||
}
|
||||
addSection(
|
||||
map,
|
||||
mapUrl,
|
||||
mappings,
|
||||
sources,
|
||||
sourcesContent,
|
||||
names,
|
||||
ignoreList,
|
||||
lineOffset + offset.line,
|
||||
columnOffset + offset.column,
|
||||
sl,
|
||||
sc
|
||||
);
|
||||
}
|
||||
}
|
||||
function addSection(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
|
||||
const parsed = parse(input);
|
||||
if ("sections" in parsed) return recurse(...arguments);
|
||||
const map = new TraceMap(parsed, mapUrl);
|
||||
const sourcesOffset = sources.length;
|
||||
const namesOffset = names.length;
|
||||
const decoded = decodedMappings(map);
|
||||
const { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map;
|
||||
append(sources, resolvedSources);
|
||||
append(names, map.names);
|
||||
if (contents) append(sourcesContent, contents);
|
||||
else for (let i = 0; i < resolvedSources.length; i++) sourcesContent.push(null);
|
||||
if (ignores) for (let i = 0; i < ignores.length; i++) ignoreList.push(ignores[i] + sourcesOffset);
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
const lineI = lineOffset + i;
|
||||
if (lineI > stopLine) return;
|
||||
const out = getLine(mappings, lineI);
|
||||
const cOffset = i === 0 ? columnOffset : 0;
|
||||
const line = decoded[i];
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const seg = line[j];
|
||||
const column = cOffset + seg[COLUMN];
|
||||
if (lineI === stopLine && column >= stopColumn) return;
|
||||
if (seg.length === 1) {
|
||||
out.push([column]);
|
||||
continue;
|
||||
}
|
||||
const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX];
|
||||
const sourceLine = seg[SOURCE_LINE];
|
||||
const sourceColumn = seg[SOURCE_COLUMN];
|
||||
out.push(
|
||||
seg.length === 4 ? [column, sourcesIndex, sourceLine, sourceColumn] : [column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX]]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
function append(arr, other) {
|
||||
for (let i = 0; i < other.length; i++) arr.push(other[i]);
|
||||
}
|
||||
function getLine(arr, index) {
|
||||
for (let i = arr.length; i <= index; i++) arr[i] = [];
|
||||
return arr[index];
|
||||
}
|
||||
|
||||
// src/trace-mapping.ts
|
||||
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
||||
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
||||
var LEAST_UPPER_BOUND = -1;
|
||||
var GREATEST_LOWER_BOUND = 1;
|
||||
var TraceMap = class {
|
||||
constructor(map, mapUrl) {
|
||||
const isString = typeof map === "string";
|
||||
if (!isString && map._decodedMemo) return map;
|
||||
const parsed = parse(map);
|
||||
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
||||
this.version = version;
|
||||
this.file = file;
|
||||
this.names = names || [];
|
||||
this.sourceRoot = sourceRoot;
|
||||
this.sources = sources;
|
||||
this.sourcesContent = sourcesContent;
|
||||
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
||||
const resolve = resolver(mapUrl, sourceRoot);
|
||||
this.resolvedSources = sources.map(resolve);
|
||||
const { mappings } = parsed;
|
||||
if (typeof mappings === "string") {
|
||||
this._encoded = mappings;
|
||||
this._decoded = void 0;
|
||||
} else if (Array.isArray(mappings)) {
|
||||
this._encoded = void 0;
|
||||
this._decoded = maybeSort(mappings, isString);
|
||||
} else if (parsed.sections) {
|
||||
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
||||
} else {
|
||||
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
||||
}
|
||||
this._decodedMemo = memoizedState();
|
||||
this._bySources = void 0;
|
||||
this._bySourceMemos = void 0;
|
||||
}
|
||||
};
|
||||
function cast(map) {
|
||||
return map;
|
||||
}
|
||||
function encodedMappings(map) {
|
||||
var _a, _b;
|
||||
return (_b = (_a = cast(map))._encoded) != null ? _b : _a._encoded = encode(cast(map)._decoded);
|
||||
}
|
||||
function decodedMappings(map) {
|
||||
var _a;
|
||||
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
||||
}
|
||||
function traceSegment(map, line, column) {
|
||||
const decoded = decodedMappings(map);
|
||||
if (line >= decoded.length) return null;
|
||||
const segments = decoded[line];
|
||||
const index = traceSegmentInternal(
|
||||
segments,
|
||||
cast(map)._decodedMemo,
|
||||
line,
|
||||
column,
|
||||
GREATEST_LOWER_BOUND
|
||||
);
|
||||
return index === -1 ? null : segments[index];
|
||||
}
|
||||
function originalPositionFor(map, needle) {
|
||||
let { line, column, bias } = needle;
|
||||
line--;
|
||||
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
||||
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
||||
const decoded = decodedMappings(map);
|
||||
if (line >= decoded.length) return OMapping(null, null, null, null);
|
||||
const segments = decoded[line];
|
||||
const index = traceSegmentInternal(
|
||||
segments,
|
||||
cast(map)._decodedMemo,
|
||||
line,
|
||||
column,
|
||||
bias || GREATEST_LOWER_BOUND
|
||||
);
|
||||
if (index === -1) return OMapping(null, null, null, null);
|
||||
const segment = segments[index];
|
||||
if (segment.length === 1) return OMapping(null, null, null, null);
|
||||
const { names, resolvedSources } = map;
|
||||
return OMapping(
|
||||
resolvedSources[segment[SOURCES_INDEX]],
|
||||
segment[SOURCE_LINE] + 1,
|
||||
segment[SOURCE_COLUMN],
|
||||
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
||||
);
|
||||
}
|
||||
function generatedPositionFor(map, needle) {
|
||||
const { source, line, column, bias } = needle;
|
||||
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
||||
}
|
||||
function allGeneratedPositionsFor(map, needle) {
|
||||
const { source, line, column, bias } = needle;
|
||||
return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
|
||||
}
|
||||
function eachMapping(map, cb) {
|
||||
const decoded = decodedMappings(map);
|
||||
const { names, resolvedSources } = map;
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
const line = decoded[i];
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const seg = line[j];
|
||||
const generatedLine = i + 1;
|
||||
const generatedColumn = seg[0];
|
||||
let source = null;
|
||||
let originalLine = null;
|
||||
let originalColumn = null;
|
||||
let name = null;
|
||||
if (seg.length !== 1) {
|
||||
source = resolvedSources[seg[1]];
|
||||
originalLine = seg[2] + 1;
|
||||
originalColumn = seg[3];
|
||||
}
|
||||
if (seg.length === 5) name = names[seg[4]];
|
||||
cb({
|
||||
generatedLine,
|
||||
generatedColumn,
|
||||
source,
|
||||
originalLine,
|
||||
originalColumn,
|
||||
name
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function sourceIndex(map, source) {
|
||||
const { sources, resolvedSources } = map;
|
||||
let index = sources.indexOf(source);
|
||||
if (index === -1) index = resolvedSources.indexOf(source);
|
||||
return index;
|
||||
}
|
||||
function sourceContentFor(map, source) {
|
||||
const { sourcesContent } = map;
|
||||
if (sourcesContent == null) return null;
|
||||
const index = sourceIndex(map, source);
|
||||
return index === -1 ? null : sourcesContent[index];
|
||||
}
|
||||
function isIgnored(map, source) {
|
||||
const { ignoreList } = map;
|
||||
if (ignoreList == null) return false;
|
||||
const index = sourceIndex(map, source);
|
||||
return index === -1 ? false : ignoreList.includes(index);
|
||||
}
|
||||
function presortedDecodedMap(map, mapUrl) {
|
||||
const tracer = new TraceMap(clone(map, []), mapUrl);
|
||||
cast(tracer)._decoded = map.mappings;
|
||||
return tracer;
|
||||
}
|
||||
function decodedMap(map) {
|
||||
return clone(map, decodedMappings(map));
|
||||
}
|
||||
function encodedMap(map) {
|
||||
return clone(map, encodedMappings(map));
|
||||
}
|
||||
function clone(map, mappings) {
|
||||
return {
|
||||
version: map.version,
|
||||
file: map.file,
|
||||
names: map.names,
|
||||
sourceRoot: map.sourceRoot,
|
||||
sources: map.sources,
|
||||
sourcesContent: map.sourcesContent,
|
||||
mappings,
|
||||
ignoreList: map.ignoreList || map.x_google_ignoreList
|
||||
};
|
||||
}
|
||||
function OMapping(source, line, column, name) {
|
||||
return { source, line, column, name };
|
||||
}
|
||||
function GMapping(line, column) {
|
||||
return { line, column };
|
||||
}
|
||||
function traceSegmentInternal(segments, memo, line, column, bias) {
|
||||
let index = memoizedBinarySearch(segments, column, memo, line);
|
||||
if (found) {
|
||||
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
||||
} else if (bias === LEAST_UPPER_BOUND) index++;
|
||||
if (index === -1 || index === segments.length) return -1;
|
||||
return index;
|
||||
}
|
||||
function sliceGeneratedPositions(segments, memo, line, column, bias) {
|
||||
let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
|
||||
if (!found && bias === LEAST_UPPER_BOUND) min++;
|
||||
if (min === -1 || min === segments.length) return [];
|
||||
const matchedColumn = found ? column : segments[min][COLUMN];
|
||||
if (!found) min = lowerBound(segments, matchedColumn, min);
|
||||
const max = upperBound(segments, matchedColumn, min);
|
||||
const result = [];
|
||||
for (; min <= max; min++) {
|
||||
const segment = segments[min];
|
||||
result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
function generatedPosition(map, source, line, column, bias, all) {
|
||||
var _a, _b;
|
||||
line--;
|
||||
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
||||
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
||||
const { sources, resolvedSources } = map;
|
||||
let sourceIndex2 = sources.indexOf(source);
|
||||
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
|
||||
if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
|
||||
const bySourceMemos = (_a = cast(map))._bySourceMemos || (_a._bySourceMemos = sources.map(memoizedState));
|
||||
const generated = (_b = cast(map))._bySources || (_b._bySources = buildBySources(decodedMappings(map), bySourceMemos));
|
||||
const segments = generated[sourceIndex2][line];
|
||||
if (segments == null) return all ? [] : GMapping(null, null);
|
||||
const memo = bySourceMemos[sourceIndex2];
|
||||
if (all) return sliceGeneratedPositions(segments, memo, line, column, bias);
|
||||
const index = traceSegmentInternal(segments, memo, line, column, bias);
|
||||
if (index === -1) return GMapping(null, null);
|
||||
const segment = segments[index];
|
||||
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
||||
}
|
||||
export {
|
||||
FlattenMap as AnyMap,
|
||||
FlattenMap,
|
||||
GREATEST_LOWER_BOUND,
|
||||
LEAST_UPPER_BOUND,
|
||||
TraceMap,
|
||||
allGeneratedPositionsFor,
|
||||
decodedMap,
|
||||
decodedMappings,
|
||||
eachMapping,
|
||||
encodedMap,
|
||||
encodedMappings,
|
||||
generatedPositionFor,
|
||||
isIgnored,
|
||||
originalPositionFor,
|
||||
presortedDecodedMap,
|
||||
sourceContentFor,
|
||||
traceSegment
|
||||
};
|
||||
//# sourceMappingURL=trace-mapping.mjs.map
|
||||
+6
File diff suppressed because one or more lines are too long
+559
File diff suppressed because it is too large
Load Diff
+6
File diff suppressed because one or more lines are too long
+67
@@ -0,0 +1,67 @@
|
||||
{
|
||||
"name": "@jridgewell/trace-mapping",
|
||||
"version": "0.3.31",
|
||||
"description": "Trace the original position through a source map",
|
||||
"keywords": [
|
||||
"source",
|
||||
"map"
|
||||
],
|
||||
"main": "dist/trace-mapping.umd.js",
|
||||
"module": "dist/trace-mapping.mjs",
|
||||
"types": "types/trace-mapping.d.cts",
|
||||
"files": [
|
||||
"dist",
|
||||
"src",
|
||||
"types"
|
||||
],
|
||||
"exports": {
|
||||
".": [
|
||||
{
|
||||
"import": {
|
||||
"types": "./types/trace-mapping.d.mts",
|
||||
"default": "./dist/trace-mapping.mjs"
|
||||
},
|
||||
"default": {
|
||||
"types": "./types/trace-mapping.d.cts",
|
||||
"default": "./dist/trace-mapping.umd.js"
|
||||
}
|
||||
},
|
||||
"./dist/trace-mapping.umd.js"
|
||||
],
|
||||
"./package.json": "./package.json"
|
||||
},
|
||||
"scripts": {
|
||||
"benchmark": "run-s build:code benchmark:*",
|
||||
"benchmark:install": "cd benchmark && npm install",
|
||||
"benchmark:only": "node --expose-gc benchmark/index.mjs",
|
||||
"build": "run-s -n build:code build:types",
|
||||
"build:code": "node ../../esbuild.mjs trace-mapping.ts",
|
||||
"build:types": "run-s build:types:force build:types:emit build:types:mts",
|
||||
"build:types:force": "rimraf tsconfig.build.tsbuildinfo",
|
||||
"build:types:emit": "tsc --project tsconfig.build.json",
|
||||
"build:types:mts": "node ../../mts-types.mjs",
|
||||
"clean": "run-s -n clean:code clean:types",
|
||||
"clean:code": "tsc --build --clean tsconfig.build.json",
|
||||
"clean:types": "rimraf dist types",
|
||||
"test": "run-s -n test:types test:only test:format",
|
||||
"test:format": "prettier --check '{src,test}/**/*.ts'",
|
||||
"test:only": "mocha",
|
||||
"test:types": "eslint '{src,test}/**/*.ts'",
|
||||
"lint": "run-s -n lint:types lint:format",
|
||||
"lint:format": "npm run test:format -- --write",
|
||||
"lint:types": "npm run test:types -- --fix",
|
||||
"prepublishOnly": "npm run-s -n build test"
|
||||
},
|
||||
"homepage": "https://github.com/jridgewell/sourcemaps/tree/main/packages/trace-mapping",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jridgewell/sourcemaps.git",
|
||||
"directory": "packages/trace-mapping"
|
||||
},
|
||||
"author": "Justin Ridgewell <justin@ridgewell.name>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@jridgewell/resolve-uri": "^3.1.0",
|
||||
"@jridgewell/sourcemap-codec": "^1.4.14"
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
import type { SourceMapSegment, ReverseSegment } from './sourcemap-segment';
|
||||
import { COLUMN } from './sourcemap-segment';
|
||||
|
||||
export type MemoState = {
|
||||
lastKey: number;
|
||||
lastNeedle: number;
|
||||
lastIndex: number;
|
||||
};
|
||||
|
||||
export let found = false;
|
||||
|
||||
/**
|
||||
* A binary search implementation that returns the index if a match is found.
|
||||
* If no match is found, then the left-index (the index associated with the item that comes just
|
||||
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
||||
* the next index:
|
||||
*
|
||||
* ```js
|
||||
* const array = [1, 3];
|
||||
* const needle = 2;
|
||||
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
||||
*
|
||||
* assert.equal(index, 0);
|
||||
* array.splice(index + 1, 0, needle);
|
||||
* assert.deepEqual(array, [1, 2, 3]);
|
||||
* ```
|
||||
*/
|
||||
export function binarySearch(
|
||||
haystack: SourceMapSegment[] | ReverseSegment[],
|
||||
needle: number,
|
||||
low: number,
|
||||
high: number,
|
||||
): number {
|
||||
while (low <= high) {
|
||||
const mid = low + ((high - low) >> 1);
|
||||
const cmp = haystack[mid][COLUMN] - needle;
|
||||
|
||||
if (cmp === 0) {
|
||||
found = true;
|
||||
return mid;
|
||||
}
|
||||
|
||||
if (cmp < 0) {
|
||||
low = mid + 1;
|
||||
} else {
|
||||
high = mid - 1;
|
||||
}
|
||||
}
|
||||
|
||||
found = false;
|
||||
return low - 1;
|
||||
}
|
||||
|
||||
export function upperBound(
|
||||
haystack: SourceMapSegment[] | ReverseSegment[],
|
||||
needle: number,
|
||||
index: number,
|
||||
): number {
|
||||
for (let i = index + 1; i < haystack.length; index = i++) {
|
||||
if (haystack[i][COLUMN] !== needle) break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
export function lowerBound(
|
||||
haystack: SourceMapSegment[] | ReverseSegment[],
|
||||
needle: number,
|
||||
index: number,
|
||||
): number {
|
||||
for (let i = index - 1; i >= 0; index = i--) {
|
||||
if (haystack[i][COLUMN] !== needle) break;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
export function memoizedState(): MemoState {
|
||||
return {
|
||||
lastKey: -1,
|
||||
lastNeedle: -1,
|
||||
lastIndex: -1,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This overly complicated beast is just to record the last tested line/column and the resulting
|
||||
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
||||
*/
|
||||
export function memoizedBinarySearch(
|
||||
haystack: SourceMapSegment[] | ReverseSegment[],
|
||||
needle: number,
|
||||
state: MemoState,
|
||||
key: number,
|
||||
): number {
|
||||
const { lastKey, lastNeedle, lastIndex } = state;
|
||||
|
||||
let low = 0;
|
||||
let high = haystack.length - 1;
|
||||
if (key === lastKey) {
|
||||
if (needle === lastNeedle) {
|
||||
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
||||
return lastIndex;
|
||||
}
|
||||
|
||||
if (needle >= lastNeedle) {
|
||||
// lastIndex may be -1 if the previous needle was not found.
|
||||
low = lastIndex === -1 ? 0 : lastIndex;
|
||||
} else {
|
||||
high = lastIndex;
|
||||
}
|
||||
}
|
||||
state.lastKey = key;
|
||||
state.lastNeedle = needle;
|
||||
|
||||
return (state.lastIndex = binarySearch(haystack, needle, low, high));
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
import { COLUMN, SOURCES_INDEX, SOURCE_LINE, SOURCE_COLUMN } from './sourcemap-segment';
|
||||
import { sortComparator } from './sort';
|
||||
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment';
|
||||
|
||||
export type Source = ReverseSegment[][];
|
||||
|
||||
// Rebuilds the original source files, with mappings that are ordered by source line/column instead
|
||||
// of generated line/column.
|
||||
export default function buildBySources(
|
||||
decoded: readonly SourceMapSegment[][],
|
||||
memos: unknown[],
|
||||
): Source[] {
|
||||
const sources: Source[] = memos.map(() => []);
|
||||
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
const line = decoded[i];
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const seg = line[j];
|
||||
if (seg.length === 1) continue;
|
||||
|
||||
const sourceIndex = seg[SOURCES_INDEX];
|
||||
const sourceLine = seg[SOURCE_LINE];
|
||||
const sourceColumn = seg[SOURCE_COLUMN];
|
||||
|
||||
const source = sources[sourceIndex];
|
||||
const segs = (source[sourceLine] ||= []);
|
||||
segs.push([sourceColumn, i, seg[COLUMN]]);
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < sources.length; i++) {
|
||||
const source = sources[i];
|
||||
for (let j = 0; j < source.length; j++) {
|
||||
const line = source[j];
|
||||
if (line) line.sort(sortComparator);
|
||||
}
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
import { TraceMap, presortedDecodedMap, decodedMappings } from './trace-mapping';
|
||||
import {
|
||||
COLUMN,
|
||||
SOURCES_INDEX,
|
||||
SOURCE_LINE,
|
||||
SOURCE_COLUMN,
|
||||
NAMES_INDEX,
|
||||
} from './sourcemap-segment';
|
||||
import { parse } from './types';
|
||||
|
||||
import type {
|
||||
DecodedSourceMap,
|
||||
DecodedSourceMapXInput,
|
||||
EncodedSourceMapXInput,
|
||||
SectionedSourceMapXInput,
|
||||
SectionedSourceMapInput,
|
||||
SectionXInput,
|
||||
Ro,
|
||||
} from './types';
|
||||
import type { SourceMapSegment } from './sourcemap-segment';
|
||||
|
||||
type FlattenMap = {
|
||||
new (map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
(map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
};
|
||||
|
||||
export const FlattenMap: FlattenMap = function (map, mapUrl) {
|
||||
const parsed = parse(map as SectionedSourceMapInput);
|
||||
|
||||
if (!('sections' in parsed)) {
|
||||
return new TraceMap(parsed as DecodedSourceMapXInput | EncodedSourceMapXInput, mapUrl);
|
||||
}
|
||||
|
||||
const mappings: SourceMapSegment[][] = [];
|
||||
const sources: string[] = [];
|
||||
const sourcesContent: (string | null)[] = [];
|
||||
const names: string[] = [];
|
||||
const ignoreList: number[] = [];
|
||||
|
||||
recurse(
|
||||
parsed,
|
||||
mapUrl,
|
||||
mappings,
|
||||
sources,
|
||||
sourcesContent,
|
||||
names,
|
||||
ignoreList,
|
||||
0,
|
||||
0,
|
||||
Infinity,
|
||||
Infinity,
|
||||
);
|
||||
|
||||
const joined: DecodedSourceMap = {
|
||||
version: 3,
|
||||
file: parsed.file,
|
||||
names,
|
||||
sources,
|
||||
sourcesContent,
|
||||
mappings,
|
||||
ignoreList,
|
||||
};
|
||||
|
||||
return presortedDecodedMap(joined);
|
||||
} as FlattenMap;
|
||||
|
||||
function recurse(
|
||||
input: SectionedSourceMapXInput,
|
||||
mapUrl: string | null | undefined,
|
||||
mappings: SourceMapSegment[][],
|
||||
sources: string[],
|
||||
sourcesContent: (string | null)[],
|
||||
names: string[],
|
||||
ignoreList: number[],
|
||||
lineOffset: number,
|
||||
columnOffset: number,
|
||||
stopLine: number,
|
||||
stopColumn: number,
|
||||
) {
|
||||
const { sections } = input;
|
||||
for (let i = 0; i < sections.length; i++) {
|
||||
const { map, offset } = sections[i];
|
||||
|
||||
let sl = stopLine;
|
||||
let sc = stopColumn;
|
||||
if (i + 1 < sections.length) {
|
||||
const nextOffset = sections[i + 1].offset;
|
||||
sl = Math.min(stopLine, lineOffset + nextOffset.line);
|
||||
|
||||
if (sl === stopLine) {
|
||||
sc = Math.min(stopColumn, columnOffset + nextOffset.column);
|
||||
} else if (sl < stopLine) {
|
||||
sc = columnOffset + nextOffset.column;
|
||||
}
|
||||
}
|
||||
|
||||
addSection(
|
||||
map,
|
||||
mapUrl,
|
||||
mappings,
|
||||
sources,
|
||||
sourcesContent,
|
||||
names,
|
||||
ignoreList,
|
||||
lineOffset + offset.line,
|
||||
columnOffset + offset.column,
|
||||
sl,
|
||||
sc,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function addSection(
|
||||
input: SectionXInput['map'],
|
||||
mapUrl: string | null | undefined,
|
||||
mappings: SourceMapSegment[][],
|
||||
sources: string[],
|
||||
sourcesContent: (string | null)[],
|
||||
names: string[],
|
||||
ignoreList: number[],
|
||||
lineOffset: number,
|
||||
columnOffset: number,
|
||||
stopLine: number,
|
||||
stopColumn: number,
|
||||
) {
|
||||
const parsed = parse(input);
|
||||
if ('sections' in parsed) return recurse(...(arguments as unknown as Parameters<typeof recurse>));
|
||||
|
||||
const map = new TraceMap(parsed, mapUrl);
|
||||
const sourcesOffset = sources.length;
|
||||
const namesOffset = names.length;
|
||||
const decoded = decodedMappings(map);
|
||||
const { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map;
|
||||
|
||||
append(sources, resolvedSources);
|
||||
append(names, map.names);
|
||||
|
||||
if (contents) append(sourcesContent, contents);
|
||||
else for (let i = 0; i < resolvedSources.length; i++) sourcesContent.push(null);
|
||||
|
||||
if (ignores) for (let i = 0; i < ignores.length; i++) ignoreList.push(ignores[i] + sourcesOffset);
|
||||
|
||||
for (let i = 0; i < decoded.length; i++) {
|
||||
const lineI = lineOffset + i;
|
||||
|
||||
// We can only add so many lines before we step into the range that the next section's map
|
||||
// controls. When we get to the last line, then we'll start checking the segments to see if
|
||||
// they've crossed into the column range. But it may not have any columns that overstep, so we
|
||||
// still need to check that we don't overstep lines, too.
|
||||
if (lineI > stopLine) return;
|
||||
|
||||
// The out line may already exist in mappings (if we're continuing the line started by a
|
||||
// previous section). Or, we may have jumped ahead several lines to start this section.
|
||||
const out = getLine(mappings, lineI);
|
||||
// On the 0th loop, the section's column offset shifts us forward. On all other lines (since the
|
||||
// map can be multiple lines), it doesn't.
|
||||
const cOffset = i === 0 ? columnOffset : 0;
|
||||
|
||||
const line = decoded[i];
|
||||
for (let j = 0; j < line.length; j++) {
|
||||
const seg = line[j];
|
||||
const column = cOffset + seg[COLUMN];
|
||||
|
||||
// If this segment steps into the column range that the next section's map controls, we need
|
||||
// to stop early.
|
||||
if (lineI === stopLine && column >= stopColumn) return;
|
||||
|
||||
if (seg.length === 1) {
|
||||
out.push([column]);
|
||||
continue;
|
||||
}
|
||||
|
||||
const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX];
|
||||
const sourceLine = seg[SOURCE_LINE];
|
||||
const sourceColumn = seg[SOURCE_COLUMN];
|
||||
out.push(
|
||||
seg.length === 4
|
||||
? [column, sourcesIndex, sourceLine, sourceColumn]
|
||||
: [column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX]],
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function append<T>(arr: T[], other: T[]) {
|
||||
for (let i = 0; i < other.length; i++) arr.push(other[i]);
|
||||
}
|
||||
|
||||
function getLine<T>(arr: T[][], index: number): T[] {
|
||||
for (let i = arr.length; i <= index; i++) arr[i] = [];
|
||||
return arr[index];
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import resolveUri from '@jridgewell/resolve-uri';
|
||||
import stripFilename from './strip-filename';
|
||||
|
||||
type Resolve = (source: string | null) => string;
|
||||
export default function resolver(
|
||||
mapUrl: string | null | undefined,
|
||||
sourceRoot: string | undefined,
|
||||
): Resolve {
|
||||
const from = stripFilename(mapUrl);
|
||||
// The sourceRoot is always treated as a directory, if it's not empty.
|
||||
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
||||
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
||||
const prefix = sourceRoot ? sourceRoot + '/' : '';
|
||||
|
||||
return (source) => resolveUri(prefix + (source || ''), from);
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import { COLUMN } from './sourcemap-segment';
|
||||
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment';
|
||||
|
||||
export default function maybeSort(
|
||||
mappings: SourceMapSegment[][],
|
||||
owned: boolean,
|
||||
): SourceMapSegment[][] {
|
||||
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
||||
if (unsortedIndex === mappings.length) return mappings;
|
||||
|
||||
// If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
|
||||
// not, we do not want to modify the consumer's input array.
|
||||
if (!owned) mappings = mappings.slice();
|
||||
|
||||
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
||||
mappings[i] = sortSegments(mappings[i], owned);
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
function nextUnsortedSegmentLine(mappings: SourceMapSegment[][], start: number): number {
|
||||
for (let i = start; i < mappings.length; i++) {
|
||||
if (!isSorted(mappings[i])) return i;
|
||||
}
|
||||
return mappings.length;
|
||||
}
|
||||
|
||||
function isSorted(line: SourceMapSegment[]): boolean {
|
||||
for (let j = 1; j < line.length; j++) {
|
||||
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function sortSegments(line: SourceMapSegment[], owned: boolean): SourceMapSegment[] {
|
||||
if (!owned) line = line.slice();
|
||||
return line.sort(sortComparator);
|
||||
}
|
||||
|
||||
export function sortComparator<T extends SourceMapSegment | ReverseSegment>(a: T, b: T): number {
|
||||
return a[COLUMN] - b[COLUMN];
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
type GeneratedColumn = number;
|
||||
type SourcesIndex = number;
|
||||
type SourceLine = number;
|
||||
type SourceColumn = number;
|
||||
type NamesIndex = number;
|
||||
|
||||
type GeneratedLine = number;
|
||||
|
||||
export type SourceMapSegment =
|
||||
| [GeneratedColumn]
|
||||
| [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn]
|
||||
| [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
||||
|
||||
export type ReverseSegment = [SourceColumn, GeneratedLine, GeneratedColumn];
|
||||
|
||||
export const COLUMN = 0;
|
||||
export const SOURCES_INDEX = 1;
|
||||
export const SOURCE_LINE = 2;
|
||||
export const SOURCE_COLUMN = 3;
|
||||
export const NAMES_INDEX = 4;
|
||||
|
||||
export const REV_GENERATED_LINE = 1;
|
||||
export const REV_GENERATED_COLUMN = 2;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Removes everything after the last "/", but leaves the slash.
|
||||
*/
|
||||
export default function stripFilename(path: string | undefined | null): string {
|
||||
if (!path) return '';
|
||||
const index = path.lastIndexOf('/');
|
||||
return path.slice(0, index + 1);
|
||||
}
|
||||
+502
File diff suppressed because it is too large
Load Diff
+114
@@ -0,0 +1,114 @@
|
||||
import type { SourceMapSegment } from './sourcemap-segment';
|
||||
import type { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND, TraceMap } from './trace-mapping';
|
||||
|
||||
export interface SourceMapV3 {
|
||||
file?: string | null;
|
||||
names: string[];
|
||||
sourceRoot?: string;
|
||||
sources: (string | null)[];
|
||||
sourcesContent?: (string | null)[];
|
||||
version: 3;
|
||||
ignoreList?: number[];
|
||||
}
|
||||
|
||||
export interface EncodedSourceMap extends SourceMapV3 {
|
||||
mappings: string;
|
||||
}
|
||||
|
||||
export interface DecodedSourceMap extends SourceMapV3 {
|
||||
mappings: SourceMapSegment[][];
|
||||
}
|
||||
|
||||
export interface Section {
|
||||
offset: { line: number; column: number };
|
||||
map: EncodedSourceMap | DecodedSourceMap | SectionedSourceMap;
|
||||
}
|
||||
|
||||
export interface SectionedSourceMap {
|
||||
file?: string | null;
|
||||
sections: Section[];
|
||||
version: 3;
|
||||
}
|
||||
|
||||
export type OriginalMapping = {
|
||||
source: string | null;
|
||||
line: number;
|
||||
column: number;
|
||||
name: string | null;
|
||||
};
|
||||
|
||||
export type InvalidOriginalMapping = {
|
||||
source: null;
|
||||
line: null;
|
||||
column: null;
|
||||
name: null;
|
||||
};
|
||||
|
||||
export type GeneratedMapping = {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
export type InvalidGeneratedMapping = {
|
||||
line: null;
|
||||
column: null;
|
||||
};
|
||||
|
||||
export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
||||
|
||||
export type XInput = { x_google_ignoreList?: SourceMapV3['ignoreList'] };
|
||||
export type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
||||
export type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
||||
export type SectionedSourceMapXInput = Omit<SectionedSourceMap, 'sections'> & {
|
||||
sections: SectionXInput[];
|
||||
};
|
||||
export type SectionXInput = Omit<Section, 'map'> & {
|
||||
map: SectionedSourceMapInput;
|
||||
};
|
||||
|
||||
export type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
||||
export type SectionedSourceMapInput = SourceMapInput | SectionedSourceMapXInput;
|
||||
|
||||
export type Needle = { line: number; column: number; bias?: Bias };
|
||||
export type SourceNeedle = { source: string; line: number; column: number; bias?: Bias };
|
||||
|
||||
export type EachMapping =
|
||||
| {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: null;
|
||||
originalLine: null;
|
||||
originalColumn: null;
|
||||
name: null;
|
||||
}
|
||||
| {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: string | null;
|
||||
originalLine: number;
|
||||
originalColumn: number;
|
||||
name: string | null;
|
||||
};
|
||||
|
||||
export abstract class SourceMap {
|
||||
declare version: SourceMapV3['version'];
|
||||
declare file: SourceMapV3['file'];
|
||||
declare names: SourceMapV3['names'];
|
||||
declare sourceRoot: SourceMapV3['sourceRoot'];
|
||||
declare sources: SourceMapV3['sources'];
|
||||
declare sourcesContent: SourceMapV3['sourcesContent'];
|
||||
declare resolvedSources: SourceMapV3['sources'];
|
||||
declare ignoreList: SourceMapV3['ignoreList'];
|
||||
}
|
||||
|
||||
export type Ro<T> =
|
||||
T extends Array<infer V>
|
||||
? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>>
|
||||
: T extends object
|
||||
? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>>
|
||||
: T;
|
||||
type RoArray<T> = Ro<T>[];
|
||||
type RoObject<T> = { [K in keyof T]: T[K] | Ro<T[K]> };
|
||||
|
||||
export function parse<T>(map: T): Exclude<T, string> {
|
||||
return typeof map === 'string' ? JSON.parse(map) : (map as Exclude<T, string>);
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import type { SourceMapSegment, ReverseSegment } from './sourcemap-segment.cts';
|
||||
export type MemoState = {
|
||||
lastKey: number;
|
||||
lastNeedle: number;
|
||||
lastIndex: number;
|
||||
};
|
||||
export declare let found: boolean;
|
||||
/**
|
||||
* A binary search implementation that returns the index if a match is found.
|
||||
* If no match is found, then the left-index (the index associated with the item that comes just
|
||||
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
||||
* the next index:
|
||||
*
|
||||
* ```js
|
||||
* const array = [1, 3];
|
||||
* const needle = 2;
|
||||
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
||||
*
|
||||
* assert.equal(index, 0);
|
||||
* array.splice(index + 1, 0, needle);
|
||||
* assert.deepEqual(array, [1, 2, 3]);
|
||||
* ```
|
||||
*/
|
||||
export declare function binarySearch(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, low: number, high: number): number;
|
||||
export declare function upperBound(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, index: number): number;
|
||||
export declare function lowerBound(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, index: number): number;
|
||||
export declare function memoizedState(): MemoState;
|
||||
/**
|
||||
* This overly complicated beast is just to record the last tested line/column and the resulting
|
||||
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
||||
*/
|
||||
export declare function memoizedBinarySearch(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, state: MemoState, key: number): number;
|
||||
//# sourceMappingURL=binary-search.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"binary-search.d.ts","sourceRoot":"","sources":["../src/binary-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG5E,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,IAAI,KAAK,SAAQ,CAAC;AAEzB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,MAAM,CAmBR;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED,wBAAgB,aAAa,IAAI,SAAS,CAMzC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,GACV,MAAM,CAsBR"}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
import type { SourceMapSegment, ReverseSegment } from './sourcemap-segment.mts';
|
||||
export type MemoState = {
|
||||
lastKey: number;
|
||||
lastNeedle: number;
|
||||
lastIndex: number;
|
||||
};
|
||||
export declare let found: boolean;
|
||||
/**
|
||||
* A binary search implementation that returns the index if a match is found.
|
||||
* If no match is found, then the left-index (the index associated with the item that comes just
|
||||
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
||||
* the next index:
|
||||
*
|
||||
* ```js
|
||||
* const array = [1, 3];
|
||||
* const needle = 2;
|
||||
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
||||
*
|
||||
* assert.equal(index, 0);
|
||||
* array.splice(index + 1, 0, needle);
|
||||
* assert.deepEqual(array, [1, 2, 3]);
|
||||
* ```
|
||||
*/
|
||||
export declare function binarySearch(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, low: number, high: number): number;
|
||||
export declare function upperBound(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, index: number): number;
|
||||
export declare function lowerBound(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, index: number): number;
|
||||
export declare function memoizedState(): MemoState;
|
||||
/**
|
||||
* This overly complicated beast is just to record the last tested line/column and the resulting
|
||||
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
||||
*/
|
||||
export declare function memoizedBinarySearch(haystack: SourceMapSegment[] | ReverseSegment[], needle: number, state: MemoState, key: number): number;
|
||||
//# sourceMappingURL=binary-search.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"binary-search.d.ts","sourceRoot":"","sources":["../src/binary-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG5E,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,IAAI,KAAK,SAAQ,CAAC;AAEzB;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,GACX,MAAM,CAmBR;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,GACZ,MAAM,CAKR;AAED,wBAAgB,aAAa,IAAI,SAAS,CAMzC;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,cAAc,EAAE,EAC/C,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,EAChB,GAAG,EAAE,MAAM,GACV,MAAM,CAsBR"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.cts';
|
||||
export type Source = ReverseSegment[][];
|
||||
export = function buildBySources(decoded: readonly SourceMapSegment[][], memos: unknown[]): Source[];
|
||||
//# sourceMappingURL=by-source.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"by-source.d.ts","sourceRoot":"","sources":["../src/by-source.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,MAAM,MAAM,MAAM,GAAG,cAAc,EAAE,EAAE,CAAC;AAIxC,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,EACtC,KAAK,EAAE,OAAO,EAAE,GACf,MAAM,EAAE,CA4BV"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.mts';
|
||||
export type Source = ReverseSegment[][];
|
||||
export default function buildBySources(decoded: readonly SourceMapSegment[][], memos: unknown[]): Source[];
|
||||
//# sourceMappingURL=by-source.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"by-source.d.ts","sourceRoot":"","sources":["../src/by-source.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,MAAM,MAAM,MAAM,GAAG,cAAc,EAAE,EAAE,CAAC;AAIxC,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,EACtC,KAAK,EAAE,OAAO,EAAE,GACf,MAAM,EAAE,CA4BV"}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { TraceMap } from './trace-mapping.cts';
|
||||
import type { SectionedSourceMapInput, Ro } from './types.cts';
|
||||
type FlattenMap = {
|
||||
new (map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
(map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
};
|
||||
export declare const FlattenMap: FlattenMap;
|
||||
export {};
|
||||
//# sourceMappingURL=flatten-map.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"flatten-map.d.ts","sourceRoot":"","sources":["../src/flatten-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwC,MAAM,iBAAiB,CAAC;AAUjF,OAAO,KAAK,EAKV,uBAAuB,EAEvB,EAAE,EACH,MAAM,SAAS,CAAC;AAGjB,KAAK,UAAU,GAAG;IAChB,KAAK,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;IACzE,CAAC,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,UAsCV,CAAC"}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { TraceMap } from './trace-mapping.mts';
|
||||
import type { SectionedSourceMapInput, Ro } from './types.mts';
|
||||
type FlattenMap = {
|
||||
new (map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
(map: Ro<SectionedSourceMapInput>, mapUrl?: string | null): TraceMap;
|
||||
};
|
||||
export declare const FlattenMap: FlattenMap;
|
||||
export {};
|
||||
//# sourceMappingURL=flatten-map.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"flatten-map.d.ts","sourceRoot":"","sources":["../src/flatten-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAwC,MAAM,iBAAiB,CAAC;AAUjF,OAAO,KAAK,EAKV,uBAAuB,EAEvB,EAAE,EACH,MAAM,SAAS,CAAC;AAGjB,KAAK,UAAU,GAAG;IAChB,KAAK,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;IACzE,CAAC,GAAG,EAAE,EAAE,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,QAAQ,CAAC;CACtE,CAAC;AAEF,eAAO,MAAM,UAAU,EAAE,UAsCV,CAAC"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
type Resolve = (source: string | null) => string;
|
||||
export = function resolver(mapUrl: string | null | undefined, sourceRoot: string | undefined): Resolve;
|
||||
export {};
|
||||
//# sourceMappingURL=resolve.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;AACjD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAQT"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
type Resolve = (source: string | null) => string;
|
||||
export default function resolver(mapUrl: string | null | undefined, sourceRoot: string | undefined): Resolve;
|
||||
export {};
|
||||
//# sourceMappingURL=resolve.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../src/resolve.ts"],"names":[],"mappings":"AAGA,KAAK,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,MAAM,CAAC;AACjD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC9B,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACjC,UAAU,EAAE,MAAM,GAAG,SAAS,GAC7B,OAAO,CAQT"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.cts';
|
||||
export = function maybeSort(mappings: SourceMapSegment[][], owned: boolean): SourceMapSegment[][];
|
||||
export declare function sortComparator<T extends SourceMapSegment | ReverseSegment>(a: T, b: T): number;
|
||||
//# sourceMappingURL=sort.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAC9B,KAAK,EAAE,OAAO,GACb,gBAAgB,EAAE,EAAE,CAYtB;AAuBD,wBAAgB,cAAc,CAAC,CAAC,SAAS,gBAAgB,GAAG,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAE9F"}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.mts';
|
||||
export default function maybeSort(mappings: SourceMapSegment[][], owned: boolean): SourceMapSegment[][];
|
||||
export declare function sortComparator<T extends SourceMapSegment | ReverseSegment>(a: T, b: T): number;
|
||||
//# sourceMappingURL=sort.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5E,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAC9B,KAAK,EAAE,OAAO,GACb,gBAAgB,EAAE,EAAE,CAYtB;AAuBD,wBAAgB,cAAc,CAAC,CAAC,SAAS,gBAAgB,GAAG,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,MAAM,CAE9F"}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
type GeneratedColumn = number;
|
||||
type SourcesIndex = number;
|
||||
type SourceLine = number;
|
||||
type SourceColumn = number;
|
||||
type NamesIndex = number;
|
||||
type GeneratedLine = number;
|
||||
export type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
||||
export type ReverseSegment = [SourceColumn, GeneratedLine, GeneratedColumn];
|
||||
export declare const COLUMN = 0;
|
||||
export declare const SOURCES_INDEX = 1;
|
||||
export declare const SOURCE_LINE = 2;
|
||||
export declare const SOURCE_COLUMN = 3;
|
||||
export declare const NAMES_INDEX = 4;
|
||||
export declare const REV_GENERATED_LINE = 1;
|
||||
export declare const REV_GENERATED_COLUMN = 2;
|
||||
export {};
|
||||
//# sourceMappingURL=sourcemap-segment.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sourcemap-segment.d.ts","sourceRoot":"","sources":["../src/sourcemap-segment.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,MAAM,CAAC;AAC9B,KAAK,YAAY,GAAG,MAAM,CAAC;AAC3B,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB,KAAK,YAAY,GAAG,MAAM,CAAC;AAC3B,KAAK,UAAU,GAAG,MAAM,CAAC;AAEzB,KAAK,aAAa,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GACxB,CAAC,eAAe,CAAC,GACjB,CAAC,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC,GACzD,CAAC,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;AAE5E,eAAO,MAAM,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAC"}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
type GeneratedColumn = number;
|
||||
type SourcesIndex = number;
|
||||
type SourceLine = number;
|
||||
type SourceColumn = number;
|
||||
type NamesIndex = number;
|
||||
type GeneratedLine = number;
|
||||
export type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
||||
export type ReverseSegment = [SourceColumn, GeneratedLine, GeneratedColumn];
|
||||
export declare const COLUMN = 0;
|
||||
export declare const SOURCES_INDEX = 1;
|
||||
export declare const SOURCE_LINE = 2;
|
||||
export declare const SOURCE_COLUMN = 3;
|
||||
export declare const NAMES_INDEX = 4;
|
||||
export declare const REV_GENERATED_LINE = 1;
|
||||
export declare const REV_GENERATED_COLUMN = 2;
|
||||
export {};
|
||||
//# sourceMappingURL=sourcemap-segment.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"sourcemap-segment.d.ts","sourceRoot":"","sources":["../src/sourcemap-segment.ts"],"names":[],"mappings":"AAAA,KAAK,eAAe,GAAG,MAAM,CAAC;AAC9B,KAAK,YAAY,GAAG,MAAM,CAAC;AAC3B,KAAK,UAAU,GAAG,MAAM,CAAC;AACzB,KAAK,YAAY,GAAG,MAAM,CAAC;AAC3B,KAAK,UAAU,GAAG,MAAM,CAAC;AAEzB,KAAK,aAAa,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,gBAAgB,GACxB,CAAC,eAAe,CAAC,GACjB,CAAC,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,CAAC,GACzD,CAAC,eAAe,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG,CAAC,YAAY,EAAE,aAAa,EAAE,eAAe,CAAC,CAAC;AAE5E,eAAO,MAAM,MAAM,IAAI,CAAC;AACxB,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,aAAa,IAAI,CAAC;AAC/B,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B,eAAO,MAAM,kBAAkB,IAAI,CAAC;AACpC,eAAO,MAAM,oBAAoB,IAAI,CAAC"}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Removes everything after the last "/", but leaves the slash.
|
||||
*/
|
||||
export = function stripFilename(path: string | undefined | null): string;
|
||||
//# sourceMappingURL=strip-filename.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"strip-filename.d.ts","sourceRoot":"","sources":["../src/strip-filename.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAI7E"}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Removes everything after the last "/", but leaves the slash.
|
||||
*/
|
||||
export default function stripFilename(path: string | undefined | null): string;
|
||||
//# sourceMappingURL=strip-filename.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"strip-filename.d.ts","sourceRoot":"","sources":["../src/strip-filename.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAI7E"}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import type { SourceMapSegment } from './sourcemap-segment.cts';
|
||||
import type { SourceMapV3, DecodedSourceMap, EncodedSourceMap, InvalidOriginalMapping, OriginalMapping, InvalidGeneratedMapping, GeneratedMapping, SourceMapInput, Needle, SourceNeedle, SourceMap, EachMapping, Ro } from './types.cts';
|
||||
export type { SourceMapSegment } from './sourcemap-segment.cts';
|
||||
export type { SourceMap, DecodedSourceMap, EncodedSourceMap, Section, SectionedSourceMap, SourceMapV3, Bias, EachMapping, GeneratedMapping, InvalidGeneratedMapping, InvalidOriginalMapping, Needle, OriginalMapping, OriginalMapping as Mapping, SectionedSourceMapInput, SourceMapInput, SourceNeedle, XInput, EncodedSourceMapXInput, DecodedSourceMapXInput, SectionedSourceMapXInput, SectionXInput, } from './types.cts';
|
||||
export declare const LEAST_UPPER_BOUND = -1;
|
||||
export declare const GREATEST_LOWER_BOUND = 1;
|
||||
export { FlattenMap, FlattenMap as AnyMap } from './flatten-map.cts';
|
||||
export declare class TraceMap implements SourceMap {
|
||||
version: SourceMapV3['version'];
|
||||
file: SourceMapV3['file'];
|
||||
names: SourceMapV3['names'];
|
||||
sourceRoot: SourceMapV3['sourceRoot'];
|
||||
sources: SourceMapV3['sources'];
|
||||
sourcesContent: SourceMapV3['sourcesContent'];
|
||||
ignoreList: SourceMapV3['ignoreList'];
|
||||
resolvedSources: string[];
|
||||
private _encoded;
|
||||
private _decoded;
|
||||
private _decodedMemo;
|
||||
private _bySources;
|
||||
private _bySourceMemos;
|
||||
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
||||
}
|
||||
/**
|
||||
* Returns the encoded (VLQ string) form of the SourceMap's mappings field.
|
||||
*/
|
||||
export declare function encodedMappings(map: TraceMap): EncodedSourceMap['mappings'];
|
||||
/**
|
||||
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
||||
*/
|
||||
export declare function decodedMappings(map: TraceMap): Readonly<DecodedSourceMap['mappings']>;
|
||||
/**
|
||||
* A low-level API to find the segment associated with a generated line/column (think, from a
|
||||
* stack trace). Line and column here are 0-based, unlike `originalPositionFor`.
|
||||
*/
|
||||
export declare function traceSegment(map: TraceMap, line: number, column: number): Readonly<SourceMapSegment> | null;
|
||||
/**
|
||||
* A higher-level API to find the source/line/column associated with a generated line/column
|
||||
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
||||
* `source-map` library.
|
||||
*/
|
||||
export declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
|
||||
/**
|
||||
* Finds the generated line/column position of the provided source/line/column source position.
|
||||
*/
|
||||
export declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
||||
/**
|
||||
* Finds all generated line/column positions of the provided source/line/column source position.
|
||||
*/
|
||||
export declare function allGeneratedPositionsFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping[];
|
||||
/**
|
||||
* Iterates each mapping in generated position order.
|
||||
*/
|
||||
export declare function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void;
|
||||
/**
|
||||
* Retrieves the source content for a particular source, if its found. Returns null if not.
|
||||
*/
|
||||
export declare function sourceContentFor(map: TraceMap, source: string): string | null;
|
||||
/**
|
||||
* Determines if the source is marked to ignore by the source map.
|
||||
*/
|
||||
export declare function isIgnored(map: TraceMap, source: string): boolean;
|
||||
/**
|
||||
* A helper that skips sorting of the input map's mappings array, which can be expensive for larger
|
||||
* maps.
|
||||
*/
|
||||
export declare function presortedDecodedMap(map: DecodedSourceMap, mapUrl?: string): TraceMap;
|
||||
/**
|
||||
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
|
||||
* a sourcemap, or to JSON.stringify.
|
||||
*/
|
||||
export declare function decodedMap(map: TraceMap): Omit<DecodedSourceMap, 'mappings'> & {
|
||||
mappings: readonly SourceMapSegment[][];
|
||||
};
|
||||
/**
|
||||
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
|
||||
* a sourcemap, or to JSON.stringify.
|
||||
*/
|
||||
export declare function encodedMap(map: TraceMap): EncodedSourceMap;
|
||||
//# sourceMappingURL=trace-mapping.d.ts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+80
@@ -0,0 +1,80 @@
|
||||
import type { SourceMapSegment } from './sourcemap-segment.mts';
|
||||
import type { SourceMapV3, DecodedSourceMap, EncodedSourceMap, InvalidOriginalMapping, OriginalMapping, InvalidGeneratedMapping, GeneratedMapping, SourceMapInput, Needle, SourceNeedle, SourceMap, EachMapping, Ro } from './types.mts';
|
||||
export type { SourceMapSegment } from './sourcemap-segment.mts';
|
||||
export type { SourceMap, DecodedSourceMap, EncodedSourceMap, Section, SectionedSourceMap, SourceMapV3, Bias, EachMapping, GeneratedMapping, InvalidGeneratedMapping, InvalidOriginalMapping, Needle, OriginalMapping, OriginalMapping as Mapping, SectionedSourceMapInput, SourceMapInput, SourceNeedle, XInput, EncodedSourceMapXInput, DecodedSourceMapXInput, SectionedSourceMapXInput, SectionXInput, } from './types.mts';
|
||||
export declare const LEAST_UPPER_BOUND = -1;
|
||||
export declare const GREATEST_LOWER_BOUND = 1;
|
||||
export { FlattenMap, FlattenMap as AnyMap } from './flatten-map.mts';
|
||||
export declare class TraceMap implements SourceMap {
|
||||
version: SourceMapV3['version'];
|
||||
file: SourceMapV3['file'];
|
||||
names: SourceMapV3['names'];
|
||||
sourceRoot: SourceMapV3['sourceRoot'];
|
||||
sources: SourceMapV3['sources'];
|
||||
sourcesContent: SourceMapV3['sourcesContent'];
|
||||
ignoreList: SourceMapV3['ignoreList'];
|
||||
resolvedSources: string[];
|
||||
private _encoded;
|
||||
private _decoded;
|
||||
private _decodedMemo;
|
||||
private _bySources;
|
||||
private _bySourceMemos;
|
||||
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
||||
}
|
||||
/**
|
||||
* Returns the encoded (VLQ string) form of the SourceMap's mappings field.
|
||||
*/
|
||||
export declare function encodedMappings(map: TraceMap): EncodedSourceMap['mappings'];
|
||||
/**
|
||||
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
||||
*/
|
||||
export declare function decodedMappings(map: TraceMap): Readonly<DecodedSourceMap['mappings']>;
|
||||
/**
|
||||
* A low-level API to find the segment associated with a generated line/column (think, from a
|
||||
* stack trace). Line and column here are 0-based, unlike `originalPositionFor`.
|
||||
*/
|
||||
export declare function traceSegment(map: TraceMap, line: number, column: number): Readonly<SourceMapSegment> | null;
|
||||
/**
|
||||
* A higher-level API to find the source/line/column associated with a generated line/column
|
||||
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
||||
* `source-map` library.
|
||||
*/
|
||||
export declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
|
||||
/**
|
||||
* Finds the generated line/column position of the provided source/line/column source position.
|
||||
*/
|
||||
export declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
||||
/**
|
||||
* Finds all generated line/column positions of the provided source/line/column source position.
|
||||
*/
|
||||
export declare function allGeneratedPositionsFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping[];
|
||||
/**
|
||||
* Iterates each mapping in generated position order.
|
||||
*/
|
||||
export declare function eachMapping(map: TraceMap, cb: (mapping: EachMapping) => void): void;
|
||||
/**
|
||||
* Retrieves the source content for a particular source, if its found. Returns null if not.
|
||||
*/
|
||||
export declare function sourceContentFor(map: TraceMap, source: string): string | null;
|
||||
/**
|
||||
* Determines if the source is marked to ignore by the source map.
|
||||
*/
|
||||
export declare function isIgnored(map: TraceMap, source: string): boolean;
|
||||
/**
|
||||
* A helper that skips sorting of the input map's mappings array, which can be expensive for larger
|
||||
* maps.
|
||||
*/
|
||||
export declare function presortedDecodedMap(map: DecodedSourceMap, mapUrl?: string): TraceMap;
|
||||
/**
|
||||
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
|
||||
* a sourcemap, or to JSON.stringify.
|
||||
*/
|
||||
export declare function decodedMap(map: TraceMap): Omit<DecodedSourceMap, 'mappings'> & {
|
||||
mappings: readonly SourceMapSegment[][];
|
||||
};
|
||||
/**
|
||||
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
|
||||
* a sourcemap, or to JSON.stringify.
|
||||
*/
|
||||
export declare function encodedMap(map: TraceMap): EncodedSourceMap;
|
||||
//# sourceMappingURL=trace-mapping.d.ts.map
|
||||
+1
File diff suppressed because one or more lines are too long
+107
@@ -0,0 +1,107 @@
|
||||
import type { SourceMapSegment } from './sourcemap-segment.cts';
|
||||
import type { GREATEST_LOWER_BOUND, LEAST_UPPER_BOUND, TraceMap } from './trace-mapping.cts';
|
||||
export interface SourceMapV3 {
|
||||
file?: string | null;
|
||||
names: string[];
|
||||
sourceRoot?: string;
|
||||
sources: (string | null)[];
|
||||
sourcesContent?: (string | null)[];
|
||||
version: 3;
|
||||
ignoreList?: number[];
|
||||
}
|
||||
export interface EncodedSourceMap extends SourceMapV3 {
|
||||
mappings: string;
|
||||
}
|
||||
export interface DecodedSourceMap extends SourceMapV3 {
|
||||
mappings: SourceMapSegment[][];
|
||||
}
|
||||
export interface Section {
|
||||
offset: {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
map: EncodedSourceMap | DecodedSourceMap | SectionedSourceMap;
|
||||
}
|
||||
export interface SectionedSourceMap {
|
||||
file?: string | null;
|
||||
sections: Section[];
|
||||
version: 3;
|
||||
}
|
||||
export type OriginalMapping = {
|
||||
source: string | null;
|
||||
line: number;
|
||||
column: number;
|
||||
name: string | null;
|
||||
};
|
||||
export type InvalidOriginalMapping = {
|
||||
source: null;
|
||||
line: null;
|
||||
column: null;
|
||||
name: null;
|
||||
};
|
||||
export type GeneratedMapping = {
|
||||
line: number;
|
||||
column: number;
|
||||
};
|
||||
export type InvalidGeneratedMapping = {
|
||||
line: null;
|
||||
column: null;
|
||||
};
|
||||
export type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
||||
export type XInput = {
|
||||
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
||||
};
|
||||
export type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
||||
export type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
||||
export type SectionedSourceMapXInput = Omit<SectionedSourceMap, 'sections'> & {
|
||||
sections: SectionXInput[];
|
||||
};
|
||||
export type SectionXInput = Omit<Section, 'map'> & {
|
||||
map: SectionedSourceMapInput;
|
||||
};
|
||||
export type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
||||
export type SectionedSourceMapInput = SourceMapInput | SectionedSourceMapXInput;
|
||||
export type Needle = {
|
||||
line: number;
|
||||
column: number;
|
||||
bias?: Bias;
|
||||
};
|
||||
export type SourceNeedle = {
|
||||
source: string;
|
||||
line: number;
|
||||
column: number;
|
||||
bias?: Bias;
|
||||
};
|
||||
export type EachMapping = {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: null;
|
||||
originalLine: null;
|
||||
originalColumn: null;
|
||||
name: null;
|
||||
} | {
|
||||
generatedLine: number;
|
||||
generatedColumn: number;
|
||||
source: string | null;
|
||||
originalLine: number;
|
||||
originalColumn: number;
|
||||
name: string | null;
|
||||
};
|
||||
export declare abstract class SourceMap {
|
||||
version: SourceMapV3['version'];
|
||||
file: SourceMapV3['file'];
|
||||
names: SourceMapV3['names'];
|
||||
sourceRoot: SourceMapV3['sourceRoot'];
|
||||
sources: SourceMapV3['sources'];
|
||||
sourcesContent: SourceMapV3['sourcesContent'];
|
||||
resolvedSources: SourceMapV3['sources'];
|
||||
ignoreList: SourceMapV3['ignoreList'];
|
||||
}
|
||||
export type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
|
||||
type RoArray<T> = Ro<T>[];
|
||||
type RoObject<T> = {
|
||||
[K in keyof T]: T[K] | Ro<T[K]>;
|
||||
};
|
||||
export declare function parse<T>(map: T): Exclude<T, string>;
|
||||
export {};
|
||||
//# sourceMappingURL=types.d.ts.map
|
||||
+1
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user