Socket
Socket
Sign inDemoInstall

@jridgewell/gen-mapping

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jridgewell/gen-mapping - npm Package Compare versions

Comparing version 0.3.3 to 0.3.4

222

dist/gen-mapping.umd.js

@@ -15,11 +15,27 @@ (function (global, factory) {

/**
* A low-level API to associate a generated position with an original source position. Line and
* column here are 0-based, unlike `addMapping`.
* Provides the state to generate a sourcemap.
*/
exports.addSegment = void 0;
class GenMapping {
constructor({ file, sourceRoot } = {}) {
this._names = new setArray.SetArray();
this._sources = new setArray.SetArray();
this._sourcesContent = [];
this._mappings = [];
this.file = file;
this.sourceRoot = sourceRoot;
}
}
/**
* A high-level API to associate a generated position with an original source position. Line is
* 1-based, but column is 0-based, due to legacy behavior in `source-map` library.
* Typescript doesn't allow friend access to private fields, so this just casts the map into a type
* with public access modifiers.
*/
exports.addMapping = void 0;
function cast(map) {
return map;
}
function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
return addSegmentInternal(false, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
}
function addMapping(map, mapping) {
return addMappingInternal(false, map, mapping);
}
/**

@@ -30,3 +46,5 @@ * Same as `addSegment`, but will only add the segment if it generates useful information in the

*/
exports.maybeAddSegment = void 0;
const maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
};
/**

@@ -37,7 +55,12 @@ * Same as `addMapping`, but will only add the mapping if it generates useful information in the

*/
exports.maybeAddMapping = void 0;
const maybeAddMapping = (map, mapping) => {
return addMappingInternal(true, map, mapping);
};
/**
* Adds/removes the content of the source file to the source map.
*/
exports.setSourceContent = void 0;
function setSourceContent(map, source, content) {
const { _sources: sources, _sourcesContent: sourcesContent } = cast(map);
sourcesContent[setArray.put(sources, source)] = content;
}
/**

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

*/
exports.toDecodedMap = void 0;
function toDecodedMap(map) {
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = cast(map);
removeEmptyFinalLines(mappings);
return {
version: 3,
file: map.file || undefined,
names: names.array,
sourceRoot: map.sourceRoot || undefined,
sources: sources.array,
sourcesContent,
mappings,
};
}
/**

@@ -53,7 +88,18 @@ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects

*/
exports.toEncodedMap = void 0;
function toEncodedMap(map) {
const decoded = toDecodedMap(map);
return Object.assign(Object.assign({}, decoded), { mappings: sourcemapCodec.encode(decoded.mappings) });
}
/**
* Constructs a new GenMapping, using the already present mappings of the input.
*/
exports.fromMap = void 0;
function fromMap(input) {
const map = new traceMapping.TraceMap(input);
const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
putAll(cast(gen)._names, map.names);
putAll(cast(gen)._sources, map.sources);
cast(gen)._sourcesContent = map.sourcesContent || map.sources.map(() => null);
cast(gen)._mappings = traceMapping.decodedMappings(map);
return gen;
}
/**

@@ -63,105 +109,45 @@ * Returns an array of high-level mapping objects for every recorded segment, which could then be

*/
exports.allMappings = void 0;
function allMappings(map) {
const out = [];
const { _mappings: mappings, _sources: sources, _names: names } = cast(map);
for (let i = 0; i < mappings.length; i++) {
const line = mappings[i];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generated = { line: i + 1, column: seg[COLUMN] };
let source = undefined;
let original = undefined;
let name = undefined;
if (seg.length !== 1) {
source = sources.array[seg[SOURCES_INDEX]];
original = { line: seg[SOURCE_LINE] + 1, column: seg[SOURCE_COLUMN] };
if (seg.length === 5)
name = names.array[seg[NAMES_INDEX]];
}
out.push({ generated, source, original, name });
}
}
return out;
}
// This split declaration is only so that terser can elminiate the static initialization block.
let addSegmentInternal;
/**
* Provides the state to generate a sourcemap.
*/
class GenMapping {
constructor({ file, sourceRoot } = {}) {
this._names = new setArray.SetArray();
this._sources = new setArray.SetArray();
this._sourcesContent = [];
this._mappings = [];
this.file = file;
this.sourceRoot = sourceRoot;
function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = cast(map);
const line = getLine(mappings, genLine);
const index = getColumnIndex(line, genColumn);
if (!source) {
if (skipable && skipSourceless(line, index))
return;
return insert(line, index, [genColumn]);
}
const sourcesIndex = setArray.put(sources, source);
const namesIndex = name ? setArray.put(names, name) : NO_NAME;
if (sourcesIndex === sourcesContent.length)
sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
return;
}
return insert(line, index, name
? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
: [genColumn, sourcesIndex, sourceLine, sourceColumn]);
}
(() => {
exports.addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(false, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
};
exports.maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
};
exports.addMapping = (map, mapping) => {
return addMappingInternal(false, map, mapping);
};
exports.maybeAddMapping = (map, mapping) => {
return addMappingInternal(true, map, mapping);
};
exports.setSourceContent = (map, source, content) => {
const { _sources: sources, _sourcesContent: sourcesContent } = map;
sourcesContent[setArray.put(sources, source)] = content;
};
exports.toDecodedMap = (map) => {
const { file, sourceRoot, _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
removeEmptyFinalLines(mappings);
return {
version: 3,
file: file || undefined,
names: names.array,
sourceRoot: sourceRoot || undefined,
sources: sources.array,
sourcesContent,
mappings,
};
};
exports.toEncodedMap = (map) => {
const decoded = exports.toDecodedMap(map);
return Object.assign(Object.assign({}, decoded), { mappings: sourcemapCodec.encode(decoded.mappings) });
};
exports.allMappings = (map) => {
const out = [];
const { _mappings: mappings, _sources: sources, _names: names } = map;
for (let i = 0; i < mappings.length; i++) {
const line = mappings[i];
for (let j = 0; j < line.length; j++) {
const seg = line[j];
const generated = { line: i + 1, column: seg[COLUMN] };
let source = undefined;
let original = undefined;
let name = undefined;
if (seg.length !== 1) {
source = sources.array[seg[SOURCES_INDEX]];
original = { line: seg[SOURCE_LINE] + 1, column: seg[SOURCE_COLUMN] };
if (seg.length === 5)
name = names.array[seg[NAMES_INDEX]];
}
out.push({ generated, source, original, name });
}
}
return out;
};
exports.fromMap = (input) => {
const map = new traceMapping.TraceMap(input);
const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
putAll(gen._names, map.names);
putAll(gen._sources, map.sources);
gen._sourcesContent = map.sourcesContent || map.sources.map(() => null);
gen._mappings = traceMapping.decodedMappings(map);
return gen;
};
// Internal helpers
addSegmentInternal = (skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
const line = getLine(mappings, genLine);
const index = getColumnIndex(line, genColumn);
if (!source) {
if (skipable && skipSourceless(line, index))
return;
return insert(line, index, [genColumn]);
}
const sourcesIndex = setArray.put(sources, source);
const namesIndex = name ? setArray.put(names, name) : NO_NAME;
if (sourcesIndex === sourcesContent.length)
sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
return;
}
return insert(line, index, name
? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
: [genColumn, sourcesIndex, sourceLine, sourceColumn]);
};
})();
function getLine(mappings, index) {

@@ -233,7 +219,15 @@ for (let i = mappings.length; i <= index; i++) {

}
const s = source;
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, s, original.line - 1, original.column, name, content);
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, source, original.line - 1, original.column, name, content);
}
exports.GenMapping = GenMapping;
exports.addMapping = addMapping;
exports.addSegment = addSegment;
exports.allMappings = allMappings;
exports.fromMap = fromMap;
exports.maybeAddMapping = maybeAddMapping;
exports.maybeAddSegment = maybeAddSegment;
exports.setSourceContent = setSourceContent;
exports.toDecodedMap = toDecodedMap;
exports.toEncodedMap = toEncodedMap;

@@ -240,0 +234,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -9,10 +9,20 @@ import type { SourceMapInput } from '@jridgewell/trace-mapping';

/**
* Provides the state to generate a sourcemap.
*/
export declare class GenMapping {
private _names;
private _sources;
private _sourcesContent;
private _mappings;
file: string | null | undefined;
sourceRoot: string | null | undefined;
constructor({ file, sourceRoot }?: Options);
}
/**
* A low-level API to associate a generated position with an original source position. Line and
* column here are 0-based, unlike `addMapping`.
*/
export declare let addSegment: {
(map: GenMapping, genLine: number, genColumn: number, source?: null, sourceLine?: null, sourceColumn?: null, name?: null, content?: null): void;
(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name?: null, content?: string | null): void;
(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name: string, content?: string | null): void;
};
export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source?: null, sourceLine?: null, sourceColumn?: null, name?: null, content?: null): void;
export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name?: null, content?: string | null): void;
export declare function addSegment(map: GenMapping, genLine: number, genColumn: number, source: string, sourceLine: number, sourceColumn: number, name: string, content?: string | null): void;
/**

@@ -22,25 +32,23 @@ * A high-level API to associate a generated position with an original source position. Line is

*/
export declare let addMapping: {
(map: GenMapping, mapping: {
generated: Pos;
source?: null;
original?: null;
name?: null;
content?: null;
}): void;
(map: GenMapping, mapping: {
generated: Pos;
source: string;
original: Pos;
name?: null;
content?: string | null;
}): void;
(map: GenMapping, mapping: {
generated: Pos;
source: string;
original: Pos;
name: string;
content?: string | null;
}): void;
};
export declare function addMapping(map: GenMapping, mapping: {
generated: Pos;
source?: null;
original?: null;
name?: null;
content?: null;
}): void;
export declare function addMapping(map: GenMapping, mapping: {
generated: Pos;
source: string;
original: Pos;
name?: null;
content?: string | null;
}): void;
export declare function addMapping(map: GenMapping, mapping: {
generated: Pos;
source: string;
original: Pos;
name: string;
content?: string | null;
}): void;
/**

@@ -51,3 +59,3 @@ * Same as `addSegment`, but will only add the segment if it generates useful information in the

*/
export declare let maybeAddSegment: typeof addSegment;
export declare const maybeAddSegment: typeof addSegment;
/**

@@ -58,7 +66,7 @@ * Same as `addMapping`, but will only add the mapping if it generates useful information in the

*/
export declare let maybeAddMapping: typeof addMapping;
export declare const maybeAddMapping: typeof addMapping;
/**
* Adds/removes the content of the source file to the source map.
*/
export declare let setSourceContent: (map: GenMapping, source: string, content: string | null) => void;
export declare function setSourceContent(map: GenMapping, source: string, content: string | null): void;
/**

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

*/
export declare let toDecodedMap: (map: GenMapping) => DecodedSourceMap;
export declare function toDecodedMap(map: GenMapping): DecodedSourceMap;
/**

@@ -74,7 +82,7 @@ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects

*/
export declare let toEncodedMap: (map: GenMapping) => EncodedSourceMap;
export declare function toEncodedMap(map: GenMapping): EncodedSourceMap;
/**
* Constructs a new GenMapping, using the already present mappings of the input.
*/
export declare let fromMap: (input: SourceMapInput) => GenMapping;
export declare function fromMap(input: SourceMapInput): GenMapping;
/**

@@ -84,14 +92,2 @@ * Returns an array of high-level mapping objects for every recorded segment, which could then be

*/
export declare let allMappings: (map: GenMapping) => Mapping[];
/**
* Provides the state to generate a sourcemap.
*/
export declare class GenMapping {
private _names;
private _sources;
private _sourcesContent;
private _mappings;
file: string | null | undefined;
sourceRoot: string | null | undefined;
constructor({ file, sourceRoot }?: Options);
}
export declare function allMappings(map: GenMapping): Mapping[];
{
"name": "@jridgewell/gen-mapping",
"version": "0.3.3",
"version": "0.3.4",
"description": "Generate source maps",

@@ -44,4 +44,3 @@ "keywords": [

"lint:ts": "npm run test:lint:ts -- --fix",
"pretest": "run-s build:rollup",
"test": "run-s -n test:lint test:coverage",
"test": "run-s -n test:lint test:only",
"test:debug": "mocha --inspect-brk",

@@ -51,5 +50,4 @@ "test:lint": "run-s -n test:lint:*",

"test:lint:ts": "eslint '{src,test}/**/*.ts'",
"test:only": "mocha",
"test:coverage": "c8 mocha",
"test:watch": "run-p 'build:rollup -- --watch' 'test:only -- --watch'",
"test:only": "c8 mocha",
"test:watch": "mocha --watch",
"prepublishOnly": "npm run preversion",

@@ -72,2 +70,3 @@ "preversion": "run-s test build"

"rollup": "2.70.2",
"tsx": "4.7.1",
"typescript": "4.6.3"

@@ -74,0 +73,0 @@ },

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