summaryrefslogtreecommitdiff
path: root/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs')
-rw-r--r--node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs236
1 files changed, 118 insertions, 118 deletions
diff --git a/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs b/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
index 5aeb5ccc..5d38e383 100644
--- a/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
+++ b/node_modules/@jridgewell/gen-mapping/dist/gen-mapping.mjs
@@ -1,4 +1,4 @@
-import { SetArray, put } from '@jridgewell/set-array';
+import { SetArray, put, remove } from '@jridgewell/set-array';
import { encode } from '@jridgewell/sourcemap-codec';
import { TraceMap, decodedMappings } from '@jridgewell/trace-mapping';
@@ -10,152 +10,153 @@ const NAMES_INDEX = 4;
const NO_NAME = -1;
/**
- * 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.
*/
-let addSegment;
+class GenMapping {
+ constructor({ file, sourceRoot } = {}) {
+ this._names = new SetArray();
+ this._sources = new SetArray();
+ this._sourcesContent = [];
+ this._mappings = [];
+ this.file = file;
+ this.sourceRoot = sourceRoot;
+ this._ignoreList = new SetArray();
+ }
+}
/**
- * 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.
*/
-let addMapping;
+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);
+}
/**
* Same as `addSegment`, but will only add the segment if it generates useful information in the
* resulting map. This only works correctly if segments are added **in order**, meaning you should
* not add a segment with a lower generated line/column than one that came before.
*/
-let maybeAddSegment;
+const maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
+ return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
+};
/**
* Same as `addMapping`, but will only add the mapping if it generates useful information in the
* resulting map. This only works correctly if mappings are added **in order**, meaning you should
* not add a mapping with a lower generated line/column than one that came before.
*/
-let maybeAddMapping;
+const maybeAddMapping = (map, mapping) => {
+ return addMappingInternal(true, map, mapping);
+};
/**
* Adds/removes the content of the source file to the source map.
*/
-let setSourceContent;
+function setSourceContent(map, source, content) {
+ const { _sources: sources, _sourcesContent: sourcesContent } = cast(map);
+ const index = put(sources, source);
+ sourcesContent[index] = content;
+}
+function setIgnore(map, source, ignore = true) {
+ const { _sources: sources, _sourcesContent: sourcesContent, _ignoreList: ignoreList } = cast(map);
+ const index = put(sources, source);
+ if (index === sourcesContent.length)
+ sourcesContent[index] = null;
+ if (ignore)
+ put(ignoreList, index);
+ else
+ remove(ignoreList, index);
+}
/**
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
-let toDecodedMap;
+function toDecodedMap(map) {
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList, } = cast(map);
+ removeEmptyFinalLines(mappings);
+ return {
+ version: 3,
+ file: map.file || undefined,
+ names: names.array,
+ sourceRoot: map.sourceRoot || undefined,
+ sources: sources.array,
+ sourcesContent,
+ mappings,
+ ignoreList: ignoreList.array,
+ };
+}
/**
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
-let toEncodedMap;
+function toEncodedMap(map) {
+ const decoded = toDecodedMap(map);
+ return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
+}
/**
* Constructs a new GenMapping, using the already present mappings of the input.
*/
-let fromMap;
+function fromMap(input) {
+ const map = new 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 = decodedMappings(map);
+ if (map.ignoreList)
+ putAll(cast(gen)._ignoreList, map.ignoreList);
+ return gen;
+}
/**
* Returns an array of high-level mapping objects for every recorded segment, which could then be
* passed to the `source-map` library.
*/
-let allMappings;
-// 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();
- this._sources = new SetArray();
- this._sourcesContent = [];
- this._mappings = [];
- this.file = file;
- this.sourceRoot = sourceRoot;
- }
-}
-(() => {
- addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
- return addSegmentInternal(false, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
- };
- maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
- return addSegmentInternal(true, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content);
- };
- addMapping = (map, mapping) => {
- return addMappingInternal(false, map, mapping);
- };
- maybeAddMapping = (map, mapping) => {
- return addMappingInternal(true, map, mapping);
- };
- setSourceContent = (map, source, content) => {
- const { _sources: sources, _sourcesContent: sourcesContent } = map;
- sourcesContent[put(sources, source)] = content;
- };
- 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,
- };
- };
- toEncodedMap = (map) => {
- const decoded = toDecodedMap(map);
- return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
- };
- 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 });
+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;
- };
- fromMap = (input) => {
- const map = new 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 = 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 = put(sources, source);
- const namesIndex = name ? 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 out;
+}
+// This split declaration is only so that terser can elminiate the static initialization block.
+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, name
- ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
- : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
- };
-})();
+ return insert(line, index, [genColumn]);
+ }
+ const sourcesIndex = put(sources, source);
+ const namesIndex = name ? 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) {
for (let i = mappings.length; i <= index; i++) {
mappings[i] = [];
@@ -187,9 +188,9 @@ function removeEmptyFinalLines(mappings) {
if (len < length)
mappings.length = len;
}
-function putAll(strarr, array) {
+function putAll(setarr, array) {
for (let i = 0; i < array.length; i++)
- put(strarr, array[i]);
+ put(setarr, array[i]);
}
function skipSourceless(line, index) {
// The start of a line is already sourceless, so adding a sourceless segment to the beginning
@@ -222,9 +223,8 @@ function addMappingInternal(skipable, map, mapping) {
if (!source) {
return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
}
- 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);
}
-export { GenMapping, addMapping, addSegment, allMappings, fromMap, maybeAddMapping, maybeAddSegment, setSourceContent, toDecodedMap, toEncodedMap };
+export { GenMapping, addMapping, addSegment, allMappings, fromMap, maybeAddMapping, maybeAddSegment, setIgnore, setSourceContent, toDecodedMap, toEncodedMap };
//# sourceMappingURL=gen-mapping.mjs.map