Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jridgewell/trace-mapping

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jridgewell/trace-mapping - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

81

dist/trace-mapping.umd.js

@@ -112,2 +112,25 @@ (function (global, factory) {

}
map(fn) {
const mapOut = [];
const mappings = this._mappings;
for (let i = 0; i < mappings.length; i++) {
const line = mappings[i];
const lineOut = [];
mapOut.push(lineOut);
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const { length } = seg;
let segOut;
if (length === 4)
segOut = fn(i, seg[0], seg[1], seg[2], seg[3], -1);
else if (length === 5)
segOut = fn(i, seg[0], seg[1], seg[2], seg[3], seg[4]);
else
segOut = fn(i, seg[0], -1, -1, -1, -1);
if (segOut != null)
lineOut.push(segOut);
}
}
return mapOut;
}
traceSegment(line, column) {

@@ -179,4 +202,4 @@ const mappings = this._mappings;

let sourcesIndex = 1;
let sourceLine = 0;
let sourceColumn = 0;
let sourceLine = 1;
let sourceColumn = 1;
let namesIndex = 1;

@@ -316,21 +339,25 @@ let lineSorted = true;

decodedMappings() {
return this.map(segmentify);
}
map(fn) {
const { _mappings: mappings, _lineIndices: lineIndices } = this;
const decoded = [];
let line = [];
let lineIndicesIndex = 1;
let lineIndex = lineIndices[lineIndicesIndex];
// The mappings TypedArray needs to be split on line boundaries to generate the proper decoded
// mappings array.
const mapOut = [];
let lineOut = [];
let generatedLine = 0;
let lineIndex = lineIndices[generatedLine + 1];
for (let i = 0; i < mappings.length;) {
while (i < lineIndex) {
line.push(segmentify(mappings, i));
const segOut = fn(generatedLine, mappings[i + 0], mappings[i + 1] - 1, mappings[i + 2] - 1, mappings[i + 3] - 1, mappings[i + 4] - 1);
if (segOut != null)
lineOut.push(segOut);
i += ITEM_LENGTH;
}
do {
lineIndex = lineIndices[++lineIndicesIndex];
decoded.push(line);
line = [];
mapOut.push(lineOut);
lineOut = [];
generatedLine++;
lineIndex = lineIndices[generatedLine + 1];
} while (i === lineIndex);
}
return decoded;
return mapOut;
}

@@ -347,16 +374,13 @@ traceSegment(line, column) {

return null;
return segmentify(mappings, index);
return segmentify(line, mappings[index + 0], mappings[index + 1] - 1, mappings[index + 2] - 1, mappings[index + 3] - 1, mappings[index + 4] - 1);
}
}
function segmentify(mappings, i) {
// If the second index (sourcesIndex) is 0, then the VLQ segment didn't specify 2-5 values.
if (mappings[i + 1] === 0)
return [mappings[i]];
// If the fifth index (namesIndex) is 0, then the VLQ segment didn't specify 5th value.
// The sourcesIndex 1 higher than specified, so we need to decrement it.
if (mappings[i + 4] === 0) {
return [mappings[i], mappings[i + 1] - 1, mappings[i + 2], mappings[i + 3]];
}
// The sourcesIndex and namesIndex are both 1 higher than specified, so we need to decrement them.
return [mappings[i], mappings[i + 1] - 1, mappings[i + 2], mappings[i + 3], mappings[i + 4] - 1];
function segmentify(_genLine, genCol, source, line, col, name) {
// If the sourcesIndex is -1, then the VLQ segment didn't specify 2-5 values.
if (source === -1)
return [genCol];
// If the namesIndex is -1, then the VLQ segment didn't specify 5th value.
if (name === -1)
return [genCol, source, line, col];
return [genCol, source, line, col, name];
}

@@ -406,2 +430,9 @@ function searchComparator(column, needle) {

/**
* Similar to Array.p.map, maps each segment into a new segment. Passes -1 for any values that do
* not exist in the SourceMapSegment. Both generatedLine and generatedColumn are 0-based.
*/
map(fn) {
return this._impl.map(fn);
}
/**
* A low-level API to find the segment associated with a generated line/column (think, from a

@@ -408,0 +439,0 @@ * stack trace). Line and column here are 0-based, unlike `originalPositionFor`.

@@ -1,2 +0,2 @@

import type { SourceMap, SourceMapSegment, EncodedSourceMap, DecodedSourceMap } from './types';
import type { SourceMap, SourceMapSegment, EncodedSourceMap, DecodedSourceMap, MapSegmentFn } from './types';
export declare class DecodedSourceMapImpl implements SourceMap {

@@ -10,3 +10,4 @@ private _mappings;

decodedMappings(): DecodedSourceMap['mappings'];
map<T>(fn: MapSegmentFn<T>): NonNullable<T>[][];
traceSegment(line: number, column: number): SourceMapSegment | null;
}

@@ -1,2 +0,2 @@

import type { SourceMap, SourceMapSegment, DecodedSourceMap, EncodedSourceMap } from './types';
import type { SourceMap, SourceMapSegment, DecodedSourceMap, EncodedSourceMap, MapSegmentFn } from './types';
export declare class EncodedSourceMapImpl implements SourceMap {

@@ -12,3 +12,4 @@ _lastIndex: number;

decodedMappings(): DecodedSourceMap['mappings'];
map<T>(fn: MapSegmentFn<T>): NonNullable<T>[][];
traceSegment(line: number, column: number): SourceMapSegment | null;
}

@@ -1,3 +0,3 @@

import type { SourceMapV3, DecodedSourceMap, EncodedSourceMap, InvalidMapping, Mapping, SourceMapSegment, SourceMapInput, Needle } from './types';
export type { SourceMapSegment, SourceMapInput, DecodedSourceMap, EncodedSourceMap } from './types';
import type { SourceMapV3, DecodedSourceMap, EncodedSourceMap, InvalidMapping, Mapping, SourceMapSegment, SourceMapInput, Needle, MapSegmentFn } from './types';
export type { SourceMapSegment, SourceMapInput, DecodedSourceMap, EncodedSourceMap, MapSegmentFn, } from './types';
export declare class TraceMap {

@@ -22,2 +22,7 @@ version: SourceMapV3['version'];

/**
* Similar to Array.p.map, maps each segment into a new segment. Passes -1 for any values that do
* not exist in the SourceMapSegment. Both generatedLine and generatedColumn are 0-based.
*/
map<T>(fn: MapSegmentFn<T>): NonNullable<T>[][];
/**
* A low-level API to find the segment associated with a generated line/column (think, from a

@@ -24,0 +29,0 @@ * stack trace). Line and column here are 0-based, unlike `originalPositionFor`.

@@ -38,7 +38,9 @@ export interface SourceMapV3 {

};
export declare type MapSegmentFn<T> = (generatedLine: number, generatedColumn: number, sourcesIndex: number, line: number, column: number, namesIndex: number) => T;
export declare abstract class SourceMap {
abstract encodedMappings(): EncodedSourceMap['mappings'];
abstract decodedMappings(): DecodedSourceMap['mappings'];
abstract map<T>(fn: MapSegmentFn<T>): NonNullable<T>[][];
abstract traceSegment(this: SourceMap, line: number, column: number): SourceMapSegment | null;
}
export {};
{
"name": "@jridgewell/trace-mapping",
"version": "0.2.1",
"version": "0.2.2",
"description": "Trace the original position through a source map",

@@ -5,0 +5,0 @@ "keywords": [

@@ -69,4 +69,4 @@ # @jridgewell/trace-mapping

trace-mapping: decoded originalPositionFor x 7,588 ops/sec ±0.09% (101 runs sampled)
trace-mapping: encoded originalPositionFor x 7,704 ops/sec ±0.19% (101 runs sampled)
trace-mapping: decoded originalPositionFor x 7,588 ops/sec ±0.09% (101 runs sampled)
source-map-js: encoded originalPositionFor x 1,657 ops/sec ±0.18% (100 runs sampled)

@@ -73,0 +73,0 @@ source-map: encoded originalPositionFor x 927 ops/sec ±0.28% (99 runs sampled)

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc