| 1 | // src/set-array.ts
|
|---|
| 2 | var SetArray = class {
|
|---|
| 3 | constructor() {
|
|---|
| 4 | this._indexes = { __proto__: null };
|
|---|
| 5 | this.array = [];
|
|---|
| 6 | }
|
|---|
| 7 | };
|
|---|
| 8 | function cast(set) {
|
|---|
| 9 | return set;
|
|---|
| 10 | }
|
|---|
| 11 | function get(setarr, key) {
|
|---|
| 12 | return cast(setarr)._indexes[key];
|
|---|
| 13 | }
|
|---|
| 14 | function put(setarr, key) {
|
|---|
| 15 | const index = get(setarr, key);
|
|---|
| 16 | if (index !== void 0) return index;
|
|---|
| 17 | const { array, _indexes: indexes } = cast(setarr);
|
|---|
| 18 | const length = array.push(key);
|
|---|
| 19 | return indexes[key] = length - 1;
|
|---|
| 20 | }
|
|---|
| 21 | function remove(setarr, key) {
|
|---|
| 22 | const index = get(setarr, key);
|
|---|
| 23 | if (index === void 0) return;
|
|---|
| 24 | const { array, _indexes: indexes } = cast(setarr);
|
|---|
| 25 | for (let i = index + 1; i < array.length; i++) {
|
|---|
| 26 | const k = array[i];
|
|---|
| 27 | array[i - 1] = k;
|
|---|
| 28 | indexes[k]--;
|
|---|
| 29 | }
|
|---|
| 30 | indexes[key] = void 0;
|
|---|
| 31 | array.pop();
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | // src/gen-mapping.ts
|
|---|
| 35 | import {
|
|---|
| 36 | encode
|
|---|
| 37 | } from "@jridgewell/sourcemap-codec";
|
|---|
| 38 | import { TraceMap, decodedMappings } from "@jridgewell/trace-mapping";
|
|---|
| 39 |
|
|---|
| 40 | // src/sourcemap-segment.ts
|
|---|
| 41 | var COLUMN = 0;
|
|---|
| 42 | var SOURCES_INDEX = 1;
|
|---|
| 43 | var SOURCE_LINE = 2;
|
|---|
| 44 | var SOURCE_COLUMN = 3;
|
|---|
| 45 | var NAMES_INDEX = 4;
|
|---|
| 46 |
|
|---|
| 47 | // src/gen-mapping.ts
|
|---|
| 48 | var NO_NAME = -1;
|
|---|
| 49 | var GenMapping = class {
|
|---|
| 50 | constructor({ file, sourceRoot } = {}) {
|
|---|
| 51 | this._names = new SetArray();
|
|---|
| 52 | this._sources = new SetArray();
|
|---|
| 53 | this._sourcesContent = [];
|
|---|
| 54 | this._mappings = [];
|
|---|
| 55 | this.file = file;
|
|---|
| 56 | this.sourceRoot = sourceRoot;
|
|---|
| 57 | this._ignoreList = new SetArray();
|
|---|
| 58 | }
|
|---|
| 59 | };
|
|---|
| 60 | function cast2(map) {
|
|---|
| 61 | return map;
|
|---|
| 62 | }
|
|---|
| 63 | function addSegment(map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|---|
| 64 | return addSegmentInternal(
|
|---|
| 65 | false,
|
|---|
| 66 | map,
|
|---|
| 67 | genLine,
|
|---|
| 68 | genColumn,
|
|---|
| 69 | source,
|
|---|
| 70 | sourceLine,
|
|---|
| 71 | sourceColumn,
|
|---|
| 72 | name,
|
|---|
| 73 | content
|
|---|
| 74 | );
|
|---|
| 75 | }
|
|---|
| 76 | function addMapping(map, mapping) {
|
|---|
| 77 | return addMappingInternal(false, map, mapping);
|
|---|
| 78 | }
|
|---|
| 79 | var maybeAddSegment = (map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) => {
|
|---|
| 80 | return addSegmentInternal(
|
|---|
| 81 | true,
|
|---|
| 82 | map,
|
|---|
| 83 | genLine,
|
|---|
| 84 | genColumn,
|
|---|
| 85 | source,
|
|---|
| 86 | sourceLine,
|
|---|
| 87 | sourceColumn,
|
|---|
| 88 | name,
|
|---|
| 89 | content
|
|---|
| 90 | );
|
|---|
| 91 | };
|
|---|
| 92 | var maybeAddMapping = (map, mapping) => {
|
|---|
| 93 | return addMappingInternal(true, map, mapping);
|
|---|
| 94 | };
|
|---|
| 95 | function setSourceContent(map, source, content) {
|
|---|
| 96 | const {
|
|---|
| 97 | _sources: sources,
|
|---|
| 98 | _sourcesContent: sourcesContent
|
|---|
| 99 | // _originalScopes: originalScopes,
|
|---|
| 100 | } = cast2(map);
|
|---|
| 101 | const index = put(sources, source);
|
|---|
| 102 | sourcesContent[index] = content;
|
|---|
| 103 | }
|
|---|
| 104 | function setIgnore(map, source, ignore = true) {
|
|---|
| 105 | const {
|
|---|
| 106 | _sources: sources,
|
|---|
| 107 | _sourcesContent: sourcesContent,
|
|---|
| 108 | _ignoreList: ignoreList
|
|---|
| 109 | // _originalScopes: originalScopes,
|
|---|
| 110 | } = cast2(map);
|
|---|
| 111 | const index = put(sources, source);
|
|---|
| 112 | if (index === sourcesContent.length) sourcesContent[index] = null;
|
|---|
| 113 | if (ignore) put(ignoreList, index);
|
|---|
| 114 | else remove(ignoreList, index);
|
|---|
| 115 | }
|
|---|
| 116 | function toDecodedMap(map) {
|
|---|
| 117 | const {
|
|---|
| 118 | _mappings: mappings,
|
|---|
| 119 | _sources: sources,
|
|---|
| 120 | _sourcesContent: sourcesContent,
|
|---|
| 121 | _names: names,
|
|---|
| 122 | _ignoreList: ignoreList
|
|---|
| 123 | // _originalScopes: originalScopes,
|
|---|
| 124 | // _generatedRanges: generatedRanges,
|
|---|
| 125 | } = cast2(map);
|
|---|
| 126 | removeEmptyFinalLines(mappings);
|
|---|
| 127 | return {
|
|---|
| 128 | version: 3,
|
|---|
| 129 | file: map.file || void 0,
|
|---|
| 130 | names: names.array,
|
|---|
| 131 | sourceRoot: map.sourceRoot || void 0,
|
|---|
| 132 | sources: sources.array,
|
|---|
| 133 | sourcesContent,
|
|---|
| 134 | mappings,
|
|---|
| 135 | // originalScopes,
|
|---|
| 136 | // generatedRanges,
|
|---|
| 137 | ignoreList: ignoreList.array
|
|---|
| 138 | };
|
|---|
| 139 | }
|
|---|
| 140 | function toEncodedMap(map) {
|
|---|
| 141 | const decoded = toDecodedMap(map);
|
|---|
| 142 | return Object.assign({}, decoded, {
|
|---|
| 143 | // originalScopes: decoded.originalScopes.map((os) => encodeOriginalScopes(os)),
|
|---|
| 144 | // generatedRanges: encodeGeneratedRanges(decoded.generatedRanges as GeneratedRange[]),
|
|---|
| 145 | mappings: encode(decoded.mappings)
|
|---|
| 146 | });
|
|---|
| 147 | }
|
|---|
| 148 | function fromMap(input) {
|
|---|
| 149 | const map = new TraceMap(input);
|
|---|
| 150 | const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
|
|---|
| 151 | putAll(cast2(gen)._names, map.names);
|
|---|
| 152 | putAll(cast2(gen)._sources, map.sources);
|
|---|
| 153 | cast2(gen)._sourcesContent = map.sourcesContent || map.sources.map(() => null);
|
|---|
| 154 | cast2(gen)._mappings = decodedMappings(map);
|
|---|
| 155 | if (map.ignoreList) putAll(cast2(gen)._ignoreList, map.ignoreList);
|
|---|
| 156 | return gen;
|
|---|
| 157 | }
|
|---|
| 158 | function allMappings(map) {
|
|---|
| 159 | const out = [];
|
|---|
| 160 | const { _mappings: mappings, _sources: sources, _names: names } = cast2(map);
|
|---|
| 161 | for (let i = 0; i < mappings.length; i++) {
|
|---|
| 162 | const line = mappings[i];
|
|---|
| 163 | for (let j = 0; j < line.length; j++) {
|
|---|
| 164 | const seg = line[j];
|
|---|
| 165 | const generated = { line: i + 1, column: seg[COLUMN] };
|
|---|
| 166 | let source = void 0;
|
|---|
| 167 | let original = void 0;
|
|---|
| 168 | let name = void 0;
|
|---|
| 169 | if (seg.length !== 1) {
|
|---|
| 170 | source = sources.array[seg[SOURCES_INDEX]];
|
|---|
| 171 | original = { line: seg[SOURCE_LINE] + 1, column: seg[SOURCE_COLUMN] };
|
|---|
| 172 | if (seg.length === 5) name = names.array[seg[NAMES_INDEX]];
|
|---|
| 173 | }
|
|---|
| 174 | out.push({ generated, source, original, name });
|
|---|
| 175 | }
|
|---|
| 176 | }
|
|---|
| 177 | return out;
|
|---|
| 178 | }
|
|---|
| 179 | function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
|
|---|
| 180 | const {
|
|---|
| 181 | _mappings: mappings,
|
|---|
| 182 | _sources: sources,
|
|---|
| 183 | _sourcesContent: sourcesContent,
|
|---|
| 184 | _names: names
|
|---|
| 185 | // _originalScopes: originalScopes,
|
|---|
| 186 | } = cast2(map);
|
|---|
| 187 | const line = getIndex(mappings, genLine);
|
|---|
| 188 | const index = getColumnIndex(line, genColumn);
|
|---|
| 189 | if (!source) {
|
|---|
| 190 | if (skipable && skipSourceless(line, index)) return;
|
|---|
| 191 | return insert(line, index, [genColumn]);
|
|---|
| 192 | }
|
|---|
| 193 | assert(sourceLine);
|
|---|
| 194 | assert(sourceColumn);
|
|---|
| 195 | const sourcesIndex = put(sources, source);
|
|---|
| 196 | const namesIndex = name ? put(names, name) : NO_NAME;
|
|---|
| 197 | if (sourcesIndex === sourcesContent.length) sourcesContent[sourcesIndex] = content != null ? content : null;
|
|---|
| 198 | if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
|
|---|
| 199 | return;
|
|---|
| 200 | }
|
|---|
| 201 | return insert(
|
|---|
| 202 | line,
|
|---|
| 203 | index,
|
|---|
| 204 | name ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex] : [genColumn, sourcesIndex, sourceLine, sourceColumn]
|
|---|
| 205 | );
|
|---|
| 206 | }
|
|---|
| 207 | function assert(_val) {
|
|---|
| 208 | }
|
|---|
| 209 | function getIndex(arr, index) {
|
|---|
| 210 | for (let i = arr.length; i <= index; i++) {
|
|---|
| 211 | arr[i] = [];
|
|---|
| 212 | }
|
|---|
| 213 | return arr[index];
|
|---|
| 214 | }
|
|---|
| 215 | function getColumnIndex(line, genColumn) {
|
|---|
| 216 | let index = line.length;
|
|---|
| 217 | for (let i = index - 1; i >= 0; index = i--) {
|
|---|
| 218 | const current = line[i];
|
|---|
| 219 | if (genColumn >= current[COLUMN]) break;
|
|---|
| 220 | }
|
|---|
| 221 | return index;
|
|---|
| 222 | }
|
|---|
| 223 | function insert(array, index, value) {
|
|---|
| 224 | for (let i = array.length; i > index; i--) {
|
|---|
| 225 | array[i] = array[i - 1];
|
|---|
| 226 | }
|
|---|
| 227 | array[index] = value;
|
|---|
| 228 | }
|
|---|
| 229 | function removeEmptyFinalLines(mappings) {
|
|---|
| 230 | const { length } = mappings;
|
|---|
| 231 | let len = length;
|
|---|
| 232 | for (let i = len - 1; i >= 0; len = i, i--) {
|
|---|
| 233 | if (mappings[i].length > 0) break;
|
|---|
| 234 | }
|
|---|
| 235 | if (len < length) mappings.length = len;
|
|---|
| 236 | }
|
|---|
| 237 | function putAll(setarr, array) {
|
|---|
| 238 | for (let i = 0; i < array.length; i++) put(setarr, array[i]);
|
|---|
| 239 | }
|
|---|
| 240 | function skipSourceless(line, index) {
|
|---|
| 241 | if (index === 0) return true;
|
|---|
| 242 | const prev = line[index - 1];
|
|---|
| 243 | return prev.length === 1;
|
|---|
| 244 | }
|
|---|
| 245 | function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
|
|---|
| 246 | if (index === 0) return false;
|
|---|
| 247 | const prev = line[index - 1];
|
|---|
| 248 | if (prev.length === 1) return false;
|
|---|
| 249 | return sourcesIndex === prev[SOURCES_INDEX] && sourceLine === prev[SOURCE_LINE] && sourceColumn === prev[SOURCE_COLUMN] && namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME);
|
|---|
| 250 | }
|
|---|
| 251 | function addMappingInternal(skipable, map, mapping) {
|
|---|
| 252 | const { generated, source, original, name, content } = mapping;
|
|---|
| 253 | if (!source) {
|
|---|
| 254 | return addSegmentInternal(
|
|---|
| 255 | skipable,
|
|---|
| 256 | map,
|
|---|
| 257 | generated.line - 1,
|
|---|
| 258 | generated.column,
|
|---|
| 259 | null,
|
|---|
| 260 | null,
|
|---|
| 261 | null,
|
|---|
| 262 | null,
|
|---|
| 263 | null
|
|---|
| 264 | );
|
|---|
| 265 | }
|
|---|
| 266 | assert(original);
|
|---|
| 267 | return addSegmentInternal(
|
|---|
| 268 | skipable,
|
|---|
| 269 | map,
|
|---|
| 270 | generated.line - 1,
|
|---|
| 271 | generated.column,
|
|---|
| 272 | source,
|
|---|
| 273 | original.line - 1,
|
|---|
| 274 | original.column,
|
|---|
| 275 | name,
|
|---|
| 276 | content
|
|---|
| 277 | );
|
|---|
| 278 | }
|
|---|
| 279 | export {
|
|---|
| 280 | GenMapping,
|
|---|
| 281 | addMapping,
|
|---|
| 282 | addSegment,
|
|---|
| 283 | allMappings,
|
|---|
| 284 | fromMap,
|
|---|
| 285 | maybeAddMapping,
|
|---|
| 286 | maybeAddSegment,
|
|---|
| 287 | setIgnore,
|
|---|
| 288 | setSourceContent,
|
|---|
| 289 | toDecodedMap,
|
|---|
| 290 | toEncodedMap
|
|---|
| 291 | };
|
|---|
| 292 | //# sourceMappingURL=gen-mapping.mjs.map
|
|---|