v1.0 with SW PWA enabled

This commit is contained in:
Blomios
2026-01-01 17:40:53 +01:00
parent 1c0e22aac1
commit 3c8bebb2ad
29775 changed files with 2197201 additions and 119080 deletions

View File

@ -59,6 +59,32 @@ 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) {
@ -117,41 +143,6 @@ function memoizedBinarySearch(haystack, needle, state, key) {
return state.lastIndex = binarySearch(haystack, needle, low, high);
}
// src/by-source.ts
function buildBySources(decoded, memos) {
const sources = memos.map(buildNullArray);
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 originalSource = sources[sourceIndex2];
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
const memo = memos[sourceIndex2];
let index = upperBound(
originalLine,
sourceColumn,
memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine)
);
memo.lastIndex = ++index;
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
}
}
return sources;
}
function insert(array, index, value) {
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}
array[index] = value;
}
function buildNullArray() {
return { __proto__: null };
}
// src/types.ts
function parse(map) {
return typeof map === "string" ? JSON.parse(map) : map;
@ -461,7 +452,7 @@ function sliceGeneratedPositions(segments, memo, line, column, bias) {
return result;
}
function generatedPosition(map, source, line, column, bias, all) {
var _a;
var _a, _b;
line--;
if (line < 0) throw new Error(LINE_GTR_ZERO);
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
@ -469,13 +460,11 @@ function generatedPosition(map, source, line, column, bias, all) {
let sourceIndex2 = sources.indexOf(source);
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(
decodedMappings(map),
cast(map)._bySourceMemos = sources.map(memoizedState)
));
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 = cast(map)._bySourceMemos[sourceIndex2];
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);

File diff suppressed because one or more lines are too long

View File

@ -143,6 +143,32 @@ 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) {
@ -201,41 +227,6 @@ function memoizedBinarySearch(haystack, needle, state, key) {
return state.lastIndex = binarySearch(haystack, needle, low, high);
}
// src/by-source.ts
function buildBySources(decoded, memos) {
const sources = memos.map(buildNullArray);
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 originalSource = sources[sourceIndex2];
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
const memo = memos[sourceIndex2];
let index = upperBound(
originalLine,
sourceColumn,
memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine)
);
memo.lastIndex = ++index;
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
}
}
return sources;
}
function insert(array, index, value) {
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}
array[index] = value;
}
function buildNullArray() {
return { __proto__: null };
}
// src/types.ts
function parse(map) {
return typeof map === "string" ? JSON.parse(map) : map;
@ -545,7 +536,7 @@ function sliceGeneratedPositions(segments, memo, line, column, bias) {
return result;
}
function generatedPosition(map, source, line, column, bias, all) {
var _a;
var _a, _b;
line--;
if (line < 0) throw new Error(LINE_GTR_ZERO);
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
@ -553,13 +544,11 @@ function generatedPosition(map, source, line, column, bias, all) {
let sourceIndex2 = sources.indexOf(source);
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(
decodedMappings(map),
cast(map)._bySourceMemos = sources.map(memoizedState)
));
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 = cast(map)._bySourceMemos[sourceIndex2];
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);

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "@jridgewell/trace-mapping",
"version": "0.3.30",
"version": "0.3.31",
"description": "Trace the original position through a source map",
"keywords": [
"source",
@ -33,7 +33,7 @@
"scripts": {
"benchmark": "run-s build:code benchmark:*",
"benchmark:install": "cd benchmark && npm install",
"benchmark:only": "node --expose-gc benchmark/index.js",
"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",

View File

@ -1,21 +1,17 @@
import { COLUMN, SOURCES_INDEX, SOURCE_LINE, SOURCE_COLUMN } from './sourcemap-segment';
import { memoizedBinarySearch, upperBound } from './binary-search';
import { sortComparator } from './sort';
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment';
import type { MemoState } from './binary-search';
export type Source = {
__proto__: null;
[line: number]: Exclude<ReverseSegment, [number]>[];
};
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: MemoState[],
memos: unknown[],
): Source[] {
const sources: Source[] = memos.map(buildNullArray);
const sources: Source[] = memos.map(() => []);
for (let i = 0; i < decoded.length; i++) {
const line = decoded[i];
@ -26,40 +22,20 @@ export default function buildBySources(
const sourceIndex = seg[SOURCES_INDEX];
const sourceLine = seg[SOURCE_LINE];
const sourceColumn = seg[SOURCE_COLUMN];
const originalSource = sources[sourceIndex];
const originalLine = (originalSource[sourceLine] ||= []);
const memo = memos[sourceIndex];
// The binary search either found a match, or it found the left-index just before where the
// segment should go. Either way, we want to insert after that. And there may be multiple
// generated segments associated with an original location, so there may need to move several
// indexes before we find where we need to insert.
let index = upperBound(
originalLine,
sourceColumn,
memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine),
);
const source = sources[sourceIndex];
const segs = (source[sourceLine] ||= []);
segs.push([sourceColumn, i, seg[COLUMN]]);
}
}
memo.lastIndex = ++index;
insert(originalLine, index, [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;
}
function insert<T>(array: T[], index: number, value: T) {
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}
array[index] = value;
}
// Null arrays allow us to use ordered index keys without actually allocating contiguous memory like
// a real array. We use a null-prototype object to avoid prototype pollution and deoptimizations.
// Numeric properties on objects are magically sorted in ascending order by the engine regardless of
// the insertion order. So, by setting any numeric keys, even out of order, we'll get ascending
// order when iterating with for-in.
function buildNullArray<T extends { __proto__: null }>(): T {
return { __proto__: null } as T;
}

View File

@ -1,6 +1,6 @@
import { COLUMN } from './sourcemap-segment';
import type { SourceMapSegment } from './sourcemap-segment';
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment';
export default function maybeSort(
mappings: SourceMapSegment[][],
@ -40,6 +40,6 @@ function sortSegments(line: SourceMapSegment[], owned: boolean): SourceMapSegmen
return line.sort(sortComparator);
}
function sortComparator(a: SourceMapSegment, b: SourceMapSegment): number {
export function sortComparator<T extends SourceMapSegment | ReverseSegment>(a: T, b: T): number {
return a[COLUMN] - b[COLUMN];
}

View File

@ -484,15 +484,13 @@ function generatedPosition(
if (sourceIndex === -1) sourceIndex = resolvedSources.indexOf(source);
if (sourceIndex === -1) return all ? [] : GMapping(null, null);
const generated = (cast(map)._bySources ||= buildBySources(
decodedMappings(map),
(cast(map)._bySourceMemos = sources.map(memoizedState)),
));
const bySourceMemos = (cast(map)._bySourceMemos ||= sources.map(memoizedState));
const generated = (cast(map)._bySources ||= buildBySources(decodedMappings(map), bySourceMemos));
const segments = generated[sourceIndex][line];
if (segments == null) return all ? [] : GMapping(null, null);
const memo = cast(map)._bySourceMemos![sourceIndex];
const memo = bySourceMemos[sourceIndex];
if (all) return sliceGeneratedPositions(segments, memo, line, column, bias);

View File

@ -1,8 +1,4 @@
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.cts';
import type { MemoState } from './binary-search.cts';
export type Source = {
__proto__: null;
[line: number]: Exclude<ReverseSegment, [number]>[];
};
export = function buildBySources(decoded: readonly SourceMapSegment[][], memos: MemoState[]): Source[];
export type Source = ReverseSegment[][];
export = function buildBySources(decoded: readonly SourceMapSegment[][], memos: unknown[]): Source[];
//# sourceMappingURL=by-source.d.ts.map

View File

@ -1 +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;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,MAAM,MAAM,GAAG;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;CACrD,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,EACtC,KAAK,EAAE,SAAS,EAAE,GACjB,MAAM,EAAE,CAgCV"}
{"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"}

View File

@ -1,8 +1,4 @@
import type { ReverseSegment, SourceMapSegment } from './sourcemap-segment.mts';
import type { MemoState } from './binary-search.mts';
export type Source = {
__proto__: null;
[line: number]: Exclude<ReverseSegment, [number]>[];
};
export default function buildBySources(decoded: readonly SourceMapSegment[][], memos: MemoState[]): Source[];
export type Source = ReverseSegment[][];
export default function buildBySources(decoded: readonly SourceMapSegment[][], memos: unknown[]): Source[];
//# sourceMappingURL=by-source.d.ts.map

View File

@ -1 +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;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,MAAM,MAAM,MAAM,GAAG;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;CACrD,CAAC;AAIF,MAAM,CAAC,OAAO,UAAU,cAAc,CACpC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EAAE,EACtC,KAAK,EAAE,SAAS,EAAE,GACjB,MAAM,EAAE,CAgCV"}
{"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"}

View File

@ -1,3 +1,4 @@
import type { SourceMapSegment } from './sourcemap-segment.cts';
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

View File

@ -1 +1 @@
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAC9B,KAAK,EAAE,OAAO,GACb,gBAAgB,EAAE,EAAE,CAYtB"}
{"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"}

View File

@ -1,3 +1,4 @@
import type { SourceMapSegment } from './sourcemap-segment.mts';
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

View File

@ -1 +1 @@
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../src/sort.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,QAAQ,EAAE,gBAAgB,EAAE,EAAE,EAC9B,KAAK,EAAE,OAAO,GACb,gBAAgB,EAAE,EAAE,CAYtB"}
{"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"}