gen-mapping.umd.js
6.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@jridgewell/set-array'), require('@jridgewell/sourcemap-codec')) :
typeof define === 'function' && define.amd ? define(['exports', '@jridgewell/set-array', '@jridgewell/sourcemap-codec'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.genMapping = {}, global.setArray, global.sourcemapCodec));
})(this, (function (exports, setArray, sourcemapCodec) { 'use strict';
/**
* A low-level API to associate a generated position with an original source position. Line and
* column here are 0-based, unlike `addMapping`.
*/
exports.addSegment = void 0;
/**
* 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.
*/
exports.addMapping = void 0;
/**
* Adds/removes the content of the source file to the source map.
*/
exports.setSourceContent = void 0;
/**
* Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
exports.decodedMap = void 0;
/**
* Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
* a sourcemap, or to JSON.stringify.
*/
exports.encodedMap = void 0;
/**
* Returns an array of high-level mapping objects for every recorded segment, which could then be
* passed to the `source-map` library.
*/
exports.allMappings = void 0;
/**
* 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;
}
}
(() => {
exports.addSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name) => {
const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
const line = getLine(mappings, genLine);
if (source == null) {
const seg = [genColumn];
const index = getColumnIndex(line, genColumn, seg);
return insert(line, index, seg);
}
const sourcesIndex = setArray.put(sources, source);
const seg = name
? [genColumn, sourcesIndex, sourceLine, sourceColumn, setArray.put(names, name)]
: [genColumn, sourcesIndex, sourceLine, sourceColumn];
const index = getColumnIndex(line, genColumn, seg);
if (sourcesIndex === sourcesContent.length)
sourcesContent[sourcesIndex] = null;
insert(line, index, seg);
};
exports.addMapping = (map, mapping) => {
const { generated, source, original, name } = mapping;
return exports.addSegment(map, generated.line - 1, generated.column, source, original == null ? undefined : original.line - 1, original === null || original === void 0 ? void 0 : original.column, name);
};
exports.setSourceContent = (map, source, content) => {
const { _sources: sources, _sourcesContent: sourcesContent } = map;
sourcesContent[setArray.put(sources, source)] = content;
};
exports.decodedMap = (map) => {
const { file, sourceRoot, _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
return {
version: 3,
file,
names: names.array,
sourceRoot: sourceRoot || undefined,
sources: sources.array,
sourcesContent,
mappings,
};
};
exports.encodedMap = (map) => {
const decoded = exports.decodedMap(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[0] };
let source = undefined;
let original = undefined;
let name = undefined;
if (seg.length !== 1) {
source = sources.array[seg[1]];
original = { line: seg[2] + 1, column: seg[3] };
if (seg.length === 5)
name = names.array[seg[4]];
}
out.push({ generated, source, original, name });
}
}
return out;
};
})();
function getLine(mappings, index) {
for (let i = mappings.length; i <= index; i++) {
mappings[i] = [];
}
return mappings[index];
}
function getColumnIndex(line, column, seg) {
let index = line.length;
for (let i = index - 1; i >= 0; i--, index--) {
const current = line[i];
const col = current[0];
if (col > column)
continue;
if (col < column)
break;
const cmp = compare(current, seg);
if (cmp === 0)
return index;
if (cmp < 0)
break;
}
return index;
}
function compare(a, b) {
let cmp = compareNum(a.length, b.length);
if (cmp !== 0)
return cmp;
// We've already checked genColumn
if (a.length === 1)
return 0;
cmp = compareNum(a[1], b[1]);
if (cmp !== 0)
return cmp;
cmp = compareNum(a[2], b[2]);
if (cmp !== 0)
return cmp;
cmp = compareNum(a[3], b[3]);
if (cmp !== 0)
return cmp;
if (a.length === 4)
return 0;
return compareNum(a[4], b[4]);
}
function compareNum(a, b) {
return a - b;
}
function insert(array, index, value) {
if (index === -1)
return;
for (let i = array.length; i > index; i--) {
array[i] = array[i - 1];
}
array[index] = value;
}
exports.GenMapping = GenMapping;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=gen-mapping.umd.js.map