Socket
Socket
Sign inDemoInstall

@jridgewell/trace-mapping

Package Overview
Dependencies
2
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.3.22 to 0.3.23

344

dist/trace-mapping.umd.js

@@ -173,4 +173,5 @@ (function (global, factory) {

// indexes before we find where we need to insert.
const index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
insert(originalLine, (memo.lastIndex = index + 1), [sourceColumn, i, seg[COLUMN]]);
let index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
memo.lastIndex = ++index;
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
}

@@ -212,3 +213,3 @@ }

};
return exports.presortedDecodedMap(joined);
return presortedDecodedMap(joined);
};

@@ -240,3 +241,3 @@ function recurse(input, mapUrl, mappings, sources, sourcesContent, names, lineOffset, columnOffset, stopLine, stopColumn) {

const namesOffset = names.length;
const decoded = exports.decodedMappings(map);
const decoded = decodedMappings(map);
const { resolvedSources, sourcesContent: contents } = map;

@@ -299,10 +300,53 @@ append(sources, resolvedSources);

const GREATEST_LOWER_BOUND = 1;
class TraceMap {
constructor(map, mapUrl) {
const isString = typeof map === 'string';
if (!isString && map._decodedMemo)
return map;
const parsed = (isString ? JSON.parse(map) : 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;
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
this.resolvedSources = sources.map((s) => resolve(s || '', from));
const { mappings } = parsed;
if (typeof mappings === 'string') {
this._encoded = mappings;
this._decoded = undefined;
}
else {
this._encoded = undefined;
this._decoded = maybeSort(mappings, isString);
}
this._decodedMemo = memoizedState();
this._bySources = undefined;
this._bySourceMemos = undefined;
}
}
/**
* Typescript doesn't allow friend access to private fields, so this just casts the map into a type
* with public access modifiers.
*/
function cast(map) {
return map;
}
/**
* Returns the encoded (VLQ string) form of the SourceMap's mappings field.
*/
exports.encodedMappings = void 0;
function encodedMappings(map) {
var _a;
var _b;
return ((_a = (_b = cast(map))._encoded) !== null && _a !== void 0 ? _a : (_b._encoded = sourcemapCodec.encode(cast(map)._decoded)));
}
/**
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
*/
exports.decodedMappings = void 0;
function decodedMappings(map) {
var _a;
return ((_a = cast(map))._decoded || (_a._decoded = sourcemapCodec.decode(cast(map)._encoded)));
}
/**

@@ -312,3 +356,12 @@ * A low-level API to find the segment associated with a generated line/column (think, from a

*/
exports.traceSegment = void 0;
function traceSegment(map, line, column) {
const decoded = decodedMappings(map);
// It's common for parent source maps to have pointers to lines that have no
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
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];
}
/**

@@ -319,19 +372,85 @@ * A higher-level API to find the source/line/column associated with a generated line/column

*/
exports.originalPositionFor = void 0;
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);
// It's common for parent source maps to have pointers to lines that have no
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
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);
}
/**
* Finds the generated line/column position of the provided source/line/column source position.
*/
exports.generatedPositionFor = void 0;
function generatedPositionFor(map, needle) {
const { source, line, column, bias } = needle;
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
}
/**
* Finds all generated line/column positions of the provided source/line/column source position.
*/
exports.allGeneratedPositionsFor = void 0;
function allGeneratedPositionsFor(map, needle) {
const { source, line, column, bias } = needle;
// SourceMapConsumer uses LEAST_UPPER_BOUND for some reason, so we follow suit.
return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
}
/**
* Iterates each mapping in generated position order.
*/
exports.eachMapping = void 0;
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,
});
}
}
}
/**
* Retrieves the source content for a particular source, if its found. Returns null if not.
*/
exports.sourceContentFor = void 0;
function sourceContentFor(map, source) {
const { sources, resolvedSources, sourcesContent } = map;
if (sourcesContent == null)
return null;
let index = sources.indexOf(source);
if (index === -1)
index = resolvedSources.indexOf(source);
return index === -1 ? null : sourcesContent[index];
}
/**

@@ -341,3 +460,7 @@ * A helper that skips sorting of the input map's mappings array, which can be expensive for larger

*/
exports.presortedDecodedMap = void 0;
function presortedDecodedMap(map, mapUrl) {
const tracer = new TraceMap(clone(map, []), mapUrl);
cast(tracer)._decoded = map.mappings;
return tracer;
}
/**

@@ -347,3 +470,5 @@ * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects

*/
exports.decodedMap = void 0;
function decodedMap(map) {
return clone(map, decodedMappings(map));
}
/**

@@ -353,155 +478,5 @@ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects

*/
exports.encodedMap = void 0;
class TraceMap {
constructor(map, mapUrl) {
const isString = typeof map === 'string';
if (!isString && map._decodedMemo)
return map;
const parsed = (isString ? JSON.parse(map) : 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;
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
this.resolvedSources = sources.map((s) => resolve(s || '', from));
const { mappings } = parsed;
if (typeof mappings === 'string') {
this._encoded = mappings;
this._decoded = undefined;
}
else {
this._encoded = undefined;
this._decoded = maybeSort(mappings, isString);
}
this._decodedMemo = memoizedState();
this._bySources = undefined;
this._bySourceMemos = undefined;
}
function encodedMap(map) {
return clone(map, encodedMappings(map));
}
(() => {
exports.encodedMappings = (map) => {
var _a;
return ((_a = map._encoded) !== null && _a !== void 0 ? _a : (map._encoded = sourcemapCodec.encode(map._decoded)));
};
exports.decodedMappings = (map) => {
return (map._decoded || (map._decoded = sourcemapCodec.decode(map._encoded)));
};
exports.traceSegment = (map, line, column) => {
const decoded = exports.decodedMappings(map);
// It's common for parent source maps to have pointers to lines that have no
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
if (line >= decoded.length)
return null;
const segments = decoded[line];
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, GREATEST_LOWER_BOUND);
return index === -1 ? null : segments[index];
};
exports.originalPositionFor = (map, { line, column, bias }) => {
line--;
if (line < 0)
throw new Error(LINE_GTR_ZERO);
if (column < 0)
throw new Error(COL_GTR_EQ_ZERO);
const decoded = exports.decodedMappings(map);
// It's common for parent source maps to have pointers to lines that have no
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
if (line >= decoded.length)
return OMapping(null, null, null, null);
const segments = decoded[line];
const index = traceSegmentInternal(segments, 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);
};
exports.allGeneratedPositionsFor = (map, { source, line, column, bias }) => {
// SourceMapConsumer uses LEAST_UPPER_BOUND for some reason, so we follow suit.
return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
};
exports.generatedPositionFor = (map, { source, line, column, bias }) => {
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
};
exports.eachMapping = (map, cb) => {
const decoded = exports.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,
});
}
}
};
exports.sourceContentFor = (map, source) => {
const { sources, resolvedSources, sourcesContent } = map;
if (sourcesContent == null)
return null;
let index = sources.indexOf(source);
if (index === -1)
index = resolvedSources.indexOf(source);
return index === -1 ? null : sourcesContent[index];
};
exports.presortedDecodedMap = (map, mapUrl) => {
const tracer = new TraceMap(clone(map, []), mapUrl);
tracer._decoded = map.mappings;
return tracer;
};
exports.decodedMap = (map) => {
return clone(map, exports.decodedMappings(map));
};
exports.encodedMap = (map) => {
return clone(map, exports.encodedMappings(map));
};
function generatedPosition(map, source, line, column, bias, all) {
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 sourceIndex = sources.indexOf(source);
if (sourceIndex === -1)
sourceIndex = resolvedSources.indexOf(source);
if (sourceIndex === -1)
return all ? [] : GMapping(null, null);
const generated = (map._bySources || (map._bySources = buildBySources(exports.decodedMappings(map), (map._bySourceMemos = sources.map(memoizedState)))));
const segments = generated[sourceIndex][line];
if (segments == null)
return all ? [] : GMapping(null, null);
const memo = map._bySourceMemos[sourceIndex];
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]);
}
})();
function clone(map, mappings) {

@@ -562,2 +537,28 @@ return {

}
function generatedPosition(map, source, line, column, bias, all) {
var _a;
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 sourceIndex = sources.indexOf(source);
if (sourceIndex === -1)
sourceIndex = resolvedSources.indexOf(source);
if (sourceIndex === -1)
return all ? [] : GMapping(null, null);
const generated = ((_a = cast(map))._bySources || (_a._bySources = buildBySources(decodedMappings(map), (cast(map)._bySourceMemos = sources.map(memoizedState)))));
const segments = generated[sourceIndex][line];
if (segments == null)
return all ? [] : GMapping(null, null);
const memo = cast(map)._bySourceMemos[sourceIndex];
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]);
}

@@ -568,4 +569,15 @@ exports.AnyMap = AnyMap;

exports.TraceMap = TraceMap;
exports.allGeneratedPositionsFor = allGeneratedPositionsFor;
exports.decodedMap = decodedMap;
exports.decodedMappings = decodedMappings;
exports.eachMapping = eachMapping;
exports.encodedMap = encodedMap;
exports.encodedMappings = encodedMappings;
exports.generatedPositionFor = generatedPositionFor;
exports.originalPositionFor = originalPositionFor;
exports.presortedDecodedMap = presortedDecodedMap;
exports.sourceContentFor = sourceContentFor;
exports.traceSegment = traceSegment;
}));
//# sourceMappingURL=trace-mapping.umd.js.map

@@ -7,10 +7,26 @@ import type { SourceMapSegment } from './sourcemap-segment';

export declare const GREATEST_LOWER_BOUND = 1;
export { AnyMap } from './any-map';
export declare class TraceMap implements SourceMap {
version: SourceMapV3['version'];
file: SourceMapV3['file'];
names: SourceMapV3['names'];
sourceRoot: SourceMapV3['sourceRoot'];
sources: SourceMapV3['sources'];
sourcesContent: SourceMapV3['sourcesContent'];
resolvedSources: string[];
private _encoded;
private _decoded;
private _decodedMemo;
private _bySources;
private _bySourceMemos;
constructor(map: SourceMapInput, mapUrl?: string | null);
}
/**
* Returns the encoded (VLQ string) form of the SourceMap's mappings field.
*/
export declare let encodedMappings: (map: TraceMap) => EncodedSourceMap['mappings'];
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 let decodedMappings: (map: TraceMap) => Readonly<DecodedSourceMap['mappings']>;
export declare function decodedMappings(map: TraceMap): Readonly<DecodedSourceMap['mappings']>;
/**

@@ -20,3 +36,3 @@ * A low-level API to find the segment associated with a generated line/column (think, from a

*/
export declare let traceSegment: (map: TraceMap, line: number, column: number) => Readonly<SourceMapSegment> | null;
export declare function traceSegment(map: TraceMap, line: number, column: number): Readonly<SourceMapSegment> | null;
/**

@@ -27,19 +43,19 @@ * A higher-level API to find the source/line/column associated with a generated line/column

*/
export declare let originalPositionFor: (map: TraceMap, needle: Needle) => OriginalMapping | InvalidOriginalMapping;
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 let generatedPositionFor: (map: TraceMap, needle: SourceNeedle) => GeneratedMapping | InvalidGeneratedMapping;
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 let allGeneratedPositionsFor: (map: TraceMap, needle: SourceNeedle) => GeneratedMapping[];
export declare function allGeneratedPositionsFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping[];
/**
* Iterates each mapping in generated position order.
*/
export declare let eachMapping: (map: TraceMap, cb: (mapping: EachMapping) => void) => void;
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 let sourceContentFor: (map: TraceMap, source: string) => string | null;
export declare function sourceContentFor(map: TraceMap, source: string): string | null;
/**

@@ -49,3 +65,3 @@ * A helper that skips sorting of the input map's mappings array, which can be expensive for larger

*/
export declare let presortedDecodedMap: (map: DecodedSourceMap, mapUrl?: string) => TraceMap;
export declare function presortedDecodedMap(map: DecodedSourceMap, mapUrl?: string): TraceMap;
/**

@@ -55,3 +71,3 @@ * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects

*/
export declare let decodedMap: (map: TraceMap) => Omit<DecodedSourceMap, 'mappings'> & {
export declare function decodedMap(map: TraceMap): Omit<DecodedSourceMap, 'mappings'> & {
mappings: readonly SourceMapSegment[][];

@@ -63,18 +79,2 @@ };

*/
export declare let encodedMap: (map: TraceMap) => EncodedSourceMap;
export { AnyMap } from './any-map';
export declare class TraceMap implements SourceMap {
version: SourceMapV3['version'];
file: SourceMapV3['file'];
names: SourceMapV3['names'];
sourceRoot: SourceMapV3['sourceRoot'];
sources: SourceMapV3['sources'];
sourcesContent: SourceMapV3['sourcesContent'];
resolvedSources: string[];
private _encoded;
private _decoded;
private _decodedMemo;
private _bySources;
private _bySourceMemos;
constructor(map: SourceMapInput, mapUrl?: string | null);
}
export declare function encodedMap(map: TraceMap): EncodedSourceMap;
{
"name": "@jridgewell/trace-mapping",
"version": "0.3.22",
"version": "0.3.23",
"description": "Trace the original position through a source map",

@@ -47,14 +47,15 @@ "keywords": [

"test": "run-s -n test:lint test:only",
"test:debug": "ava debug",
"test:debug": "mocha --inspect-brk",
"test:lint": "run-s -n test:lint:*",
"test:lint:prettier": "prettier --check '{src,test}/**/*.ts' '**/*.md'",
"test:lint:ts": "eslint '{src,test}/**/*.ts'",
"test:only": "c8 ava",
"test:watch": "ava --watch"
"test:only": "c8 mocha",
"test:watch": "mocha --watch"
},
"devDependencies": {
"@rollup/plugin-typescript": "11.1.6",
"@types/mocha": "10.0.6",
"@types/node": "20.11.20",
"@typescript-eslint/eslint-plugin": "6.18.1",
"@typescript-eslint/parser": "6.18.1",
"ava": "6.0.1",
"benchmark": "2.1.4",

@@ -66,2 +67,3 @@ "c8": "9.0.0",

"eslint-plugin-no-only-tests": "3.1.0",
"mocha": "10.3.0",
"npm-run-all": "4.1.5",

@@ -68,0 +70,0 @@ "prettier": "3.1.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc