source: imaps-frontend/node_modules/@jridgewell/source-map/dist/source-map.umd.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 49.2 KB
Line 
1(function (global, factory) {
2 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3 typeof define === 'function' && define.amd ? define(['exports'], factory) :
4 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.sourceMap = {}));
5})(this, (function (exports) { 'use strict';
6
7 const comma = ','.charCodeAt(0);
8 const semicolon = ';'.charCodeAt(0);
9 const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
10 const intToChar = new Uint8Array(64); // 64 possible chars.
11 const charToInt = new Uint8Array(128); // z is 122 in ASCII
12 for (let i = 0; i < chars.length; i++) {
13 const c = chars.charCodeAt(i);
14 intToChar[i] = c;
15 charToInt[c] = i;
16 }
17 // Provide a fallback for older environments.
18 const td = typeof TextDecoder !== 'undefined'
19 ? /* #__PURE__ */ new TextDecoder()
20 : typeof Buffer !== 'undefined'
21 ? {
22 decode(buf) {
23 const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
24 return out.toString();
25 },
26 }
27 : {
28 decode(buf) {
29 let out = '';
30 for (let i = 0; i < buf.length; i++) {
31 out += String.fromCharCode(buf[i]);
32 }
33 return out;
34 },
35 };
36 function decode(mappings) {
37 const state = new Int32Array(5);
38 const decoded = [];
39 let index = 0;
40 do {
41 const semi = indexOf(mappings, index);
42 const line = [];
43 let sorted = true;
44 let lastCol = 0;
45 state[0] = 0;
46 for (let i = index; i < semi; i++) {
47 let seg;
48 i = decodeInteger(mappings, i, state, 0); // genColumn
49 const col = state[0];
50 if (col < lastCol)
51 sorted = false;
52 lastCol = col;
53 if (hasMoreVlq(mappings, i, semi)) {
54 i = decodeInteger(mappings, i, state, 1); // sourcesIndex
55 i = decodeInteger(mappings, i, state, 2); // sourceLine
56 i = decodeInteger(mappings, i, state, 3); // sourceColumn
57 if (hasMoreVlq(mappings, i, semi)) {
58 i = decodeInteger(mappings, i, state, 4); // namesIndex
59 seg = [col, state[1], state[2], state[3], state[4]];
60 }
61 else {
62 seg = [col, state[1], state[2], state[3]];
63 }
64 }
65 else {
66 seg = [col];
67 }
68 line.push(seg);
69 }
70 if (!sorted)
71 sort(line);
72 decoded.push(line);
73 index = semi + 1;
74 } while (index <= mappings.length);
75 return decoded;
76 }
77 function indexOf(mappings, index) {
78 const idx = mappings.indexOf(';', index);
79 return idx === -1 ? mappings.length : idx;
80 }
81 function decodeInteger(mappings, pos, state, j) {
82 let value = 0;
83 let shift = 0;
84 let integer = 0;
85 do {
86 const c = mappings.charCodeAt(pos++);
87 integer = charToInt[c];
88 value |= (integer & 31) << shift;
89 shift += 5;
90 } while (integer & 32);
91 const shouldNegate = value & 1;
92 value >>>= 1;
93 if (shouldNegate) {
94 value = -0x80000000 | -value;
95 }
96 state[j] += value;
97 return pos;
98 }
99 function hasMoreVlq(mappings, i, length) {
100 if (i >= length)
101 return false;
102 return mappings.charCodeAt(i) !== comma;
103 }
104 function sort(line) {
105 line.sort(sortComparator$1);
106 }
107 function sortComparator$1(a, b) {
108 return a[0] - b[0];
109 }
110 function encode(decoded) {
111 const state = new Int32Array(5);
112 const bufLength = 1024 * 16;
113 const subLength = bufLength - 36;
114 const buf = new Uint8Array(bufLength);
115 const sub = buf.subarray(0, subLength);
116 let pos = 0;
117 let out = '';
118 for (let i = 0; i < decoded.length; i++) {
119 const line = decoded[i];
120 if (i > 0) {
121 if (pos === bufLength) {
122 out += td.decode(buf);
123 pos = 0;
124 }
125 buf[pos++] = semicolon;
126 }
127 if (line.length === 0)
128 continue;
129 state[0] = 0;
130 for (let j = 0; j < line.length; j++) {
131 const segment = line[j];
132 // We can push up to 5 ints, each int can take at most 7 chars, and we
133 // may push a comma.
134 if (pos > subLength) {
135 out += td.decode(sub);
136 buf.copyWithin(0, subLength, pos);
137 pos -= subLength;
138 }
139 if (j > 0)
140 buf[pos++] = comma;
141 pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
142 if (segment.length === 1)
143 continue;
144 pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
145 pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
146 pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
147 if (segment.length === 4)
148 continue;
149 pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
150 }
151 }
152 return out + td.decode(buf.subarray(0, pos));
153 }
154 function encodeInteger(buf, pos, state, segment, j) {
155 const next = segment[j];
156 let num = next - state[j];
157 state[j] = next;
158 num = num < 0 ? (-num << 1) | 1 : num << 1;
159 do {
160 let clamped = num & 0b011111;
161 num >>>= 5;
162 if (num > 0)
163 clamped |= 0b100000;
164 buf[pos++] = intToChar[clamped];
165 } while (num > 0);
166 return pos;
167 }
168
169 // Matches the scheme of a URL, eg "http://"
170 const schemeRegex = /^[\w+.-]+:\/\//;
171 /**
172 * Matches the parts of a URL:
173 * 1. Scheme, including ":", guaranteed.
174 * 2. User/password, including "@", optional.
175 * 3. Host, guaranteed.
176 * 4. Port, including ":", optional.
177 * 5. Path, including "/", optional.
178 * 6. Query, including "?", optional.
179 * 7. Hash, including "#", optional.
180 */
181 const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
182 /**
183 * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
184 * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
185 *
186 * 1. Host, optional.
187 * 2. Path, which may include "/", guaranteed.
188 * 3. Query, including "?", optional.
189 * 4. Hash, including "#", optional.
190 */
191 const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
192 function isAbsoluteUrl(input) {
193 return schemeRegex.test(input);
194 }
195 function isSchemeRelativeUrl(input) {
196 return input.startsWith('//');
197 }
198 function isAbsolutePath(input) {
199 return input.startsWith('/');
200 }
201 function isFileUrl(input) {
202 return input.startsWith('file:');
203 }
204 function isRelative(input) {
205 return /^[.?#]/.test(input);
206 }
207 function parseAbsoluteUrl(input) {
208 const match = urlRegex.exec(input);
209 return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
210 }
211 function parseFileUrl(input) {
212 const match = fileRegex.exec(input);
213 const path = match[2];
214 return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
215 }
216 function makeUrl(scheme, user, host, port, path, query, hash) {
217 return {
218 scheme,
219 user,
220 host,
221 port,
222 path,
223 query,
224 hash,
225 type: 7 /* Absolute */,
226 };
227 }
228 function parseUrl(input) {
229 if (isSchemeRelativeUrl(input)) {
230 const url = parseAbsoluteUrl('http:' + input);
231 url.scheme = '';
232 url.type = 6 /* SchemeRelative */;
233 return url;
234 }
235 if (isAbsolutePath(input)) {
236 const url = parseAbsoluteUrl('http://foo.com' + input);
237 url.scheme = '';
238 url.host = '';
239 url.type = 5 /* AbsolutePath */;
240 return url;
241 }
242 if (isFileUrl(input))
243 return parseFileUrl(input);
244 if (isAbsoluteUrl(input))
245 return parseAbsoluteUrl(input);
246 const url = parseAbsoluteUrl('http://foo.com/' + input);
247 url.scheme = '';
248 url.host = '';
249 url.type = input
250 ? input.startsWith('?')
251 ? 3 /* Query */
252 : input.startsWith('#')
253 ? 2 /* Hash */
254 : 4 /* RelativePath */
255 : 1 /* Empty */;
256 return url;
257 }
258 function stripPathFilename(path) {
259 // If a path ends with a parent directory "..", then it's a relative path with excess parent
260 // paths. It's not a file, so we can't strip it.
261 if (path.endsWith('/..'))
262 return path;
263 const index = path.lastIndexOf('/');
264 return path.slice(0, index + 1);
265 }
266 function mergePaths(url, base) {
267 normalizePath(base, base.type);
268 // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
269 // path).
270 if (url.path === '/') {
271 url.path = base.path;
272 }
273 else {
274 // Resolution happens relative to the base path's directory, not the file.
275 url.path = stripPathFilename(base.path) + url.path;
276 }
277 }
278 /**
279 * The path can have empty directories "//", unneeded parents "foo/..", or current directory
280 * "foo/.". We need to normalize to a standard representation.
281 */
282 function normalizePath(url, type) {
283 const rel = type <= 4 /* RelativePath */;
284 const pieces = url.path.split('/');
285 // We need to preserve the first piece always, so that we output a leading slash. The item at
286 // pieces[0] is an empty string.
287 let pointer = 1;
288 // Positive is the number of real directories we've output, used for popping a parent directory.
289 // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
290 let positive = 0;
291 // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
292 // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
293 // real directory, we won't need to append, unless the other conditions happen again.
294 let addTrailingSlash = false;
295 for (let i = 1; i < pieces.length; i++) {
296 const piece = pieces[i];
297 // An empty directory, could be a trailing slash, or just a double "//" in the path.
298 if (!piece) {
299 addTrailingSlash = true;
300 continue;
301 }
302 // If we encounter a real directory, then we don't need to append anymore.
303 addTrailingSlash = false;
304 // A current directory, which we can always drop.
305 if (piece === '.')
306 continue;
307 // A parent directory, we need to see if there are any real directories we can pop. Else, we
308 // have an excess of parents, and we'll need to keep the "..".
309 if (piece === '..') {
310 if (positive) {
311 addTrailingSlash = true;
312 positive--;
313 pointer--;
314 }
315 else if (rel) {
316 // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
317 // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
318 pieces[pointer++] = piece;
319 }
320 continue;
321 }
322 // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
323 // any popped or dropped directories.
324 pieces[pointer++] = piece;
325 positive++;
326 }
327 let path = '';
328 for (let i = 1; i < pointer; i++) {
329 path += '/' + pieces[i];
330 }
331 if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
332 path += '/';
333 }
334 url.path = path;
335 }
336 /**
337 * Attempts to resolve `input` URL/path relative to `base`.
338 */
339 function resolve$1(input, base) {
340 if (!input && !base)
341 return '';
342 const url = parseUrl(input);
343 let inputType = url.type;
344 if (base && inputType !== 7 /* Absolute */) {
345 const baseUrl = parseUrl(base);
346 const baseType = baseUrl.type;
347 switch (inputType) {
348 case 1 /* Empty */:
349 url.hash = baseUrl.hash;
350 // fall through
351 case 2 /* Hash */:
352 url.query = baseUrl.query;
353 // fall through
354 case 3 /* Query */:
355 case 4 /* RelativePath */:
356 mergePaths(url, baseUrl);
357 // fall through
358 case 5 /* AbsolutePath */:
359 // The host, user, and port are joined, you can't copy one without the others.
360 url.user = baseUrl.user;
361 url.host = baseUrl.host;
362 url.port = baseUrl.port;
363 // fall through
364 case 6 /* SchemeRelative */:
365 // The input doesn't have a schema at least, so we need to copy at least that over.
366 url.scheme = baseUrl.scheme;
367 }
368 if (baseType > inputType)
369 inputType = baseType;
370 }
371 normalizePath(url, inputType);
372 const queryHash = url.query + url.hash;
373 switch (inputType) {
374 // This is impossible, because of the empty checks at the start of the function.
375 // case UrlType.Empty:
376 case 2 /* Hash */:
377 case 3 /* Query */:
378 return queryHash;
379 case 4 /* RelativePath */: {
380 // The first char is always a "/", and we need it to be relative.
381 const path = url.path.slice(1);
382 if (!path)
383 return queryHash || '.';
384 if (isRelative(base || input) && !isRelative(path)) {
385 // If base started with a leading ".", or there is no base and input started with a ".",
386 // then we need to ensure that the relative path starts with a ".". We don't know if
387 // relative starts with a "..", though, so check before prepending.
388 return './' + path + queryHash;
389 }
390 return path + queryHash;
391 }
392 case 5 /* AbsolutePath */:
393 return url.path + queryHash;
394 default:
395 return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
396 }
397 }
398
399 function resolve(input, base) {
400 // The base is always treated as a directory, if it's not empty.
401 // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
402 // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
403 if (base && !base.endsWith('/'))
404 base += '/';
405 return resolve$1(input, base);
406 }
407
408 /**
409 * Removes everything after the last "/", but leaves the slash.
410 */
411 function stripFilename(path) {
412 if (!path)
413 return '';
414 const index = path.lastIndexOf('/');
415 return path.slice(0, index + 1);
416 }
417
418 const COLUMN$1 = 0;
419 const SOURCES_INDEX$1 = 1;
420 const SOURCE_LINE$1 = 2;
421 const SOURCE_COLUMN$1 = 3;
422 const NAMES_INDEX$1 = 4;
423 const REV_GENERATED_LINE = 1;
424 const REV_GENERATED_COLUMN = 2;
425
426 function maybeSort(mappings, owned) {
427 const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
428 if (unsortedIndex === mappings.length)
429 return mappings;
430 // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
431 // not, we do not want to modify the consumer's input array.
432 if (!owned)
433 mappings = mappings.slice();
434 for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
435 mappings[i] = sortSegments(mappings[i], owned);
436 }
437 return mappings;
438 }
439 function nextUnsortedSegmentLine(mappings, start) {
440 for (let i = start; i < mappings.length; i++) {
441 if (!isSorted(mappings[i]))
442 return i;
443 }
444 return mappings.length;
445 }
446 function isSorted(line) {
447 for (let j = 1; j < line.length; j++) {
448 if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) {
449 return false;
450 }
451 }
452 return true;
453 }
454 function sortSegments(line, owned) {
455 if (!owned)
456 line = line.slice();
457 return line.sort(sortComparator);
458 }
459 function sortComparator(a, b) {
460 return a[COLUMN$1] - b[COLUMN$1];
461 }
462
463 let found = false;
464 /**
465 * A binary search implementation that returns the index if a match is found.
466 * If no match is found, then the left-index (the index associated with the item that comes just
467 * before the desired index) is returned. To maintain proper sort order, a splice would happen at
468 * the next index:
469 *
470 * ```js
471 * const array = [1, 3];
472 * const needle = 2;
473 * const index = binarySearch(array, needle, (item, needle) => item - needle);
474 *
475 * assert.equal(index, 0);
476 * array.splice(index + 1, 0, needle);
477 * assert.deepEqual(array, [1, 2, 3]);
478 * ```
479 */
480 function binarySearch(haystack, needle, low, high) {
481 while (low <= high) {
482 const mid = low + ((high - low) >> 1);
483 const cmp = haystack[mid][COLUMN$1] - needle;
484 if (cmp === 0) {
485 found = true;
486 return mid;
487 }
488 if (cmp < 0) {
489 low = mid + 1;
490 }
491 else {
492 high = mid - 1;
493 }
494 }
495 found = false;
496 return low - 1;
497 }
498 function upperBound(haystack, needle, index) {
499 for (let i = index + 1; i < haystack.length; index = i++) {
500 if (haystack[i][COLUMN$1] !== needle)
501 break;
502 }
503 return index;
504 }
505 function lowerBound(haystack, needle, index) {
506 for (let i = index - 1; i >= 0; index = i--) {
507 if (haystack[i][COLUMN$1] !== needle)
508 break;
509 }
510 return index;
511 }
512 function memoizedState() {
513 return {
514 lastKey: -1,
515 lastNeedle: -1,
516 lastIndex: -1,
517 };
518 }
519 /**
520 * This overly complicated beast is just to record the last tested line/column and the resulting
521 * index, allowing us to skip a few tests if mappings are monotonically increasing.
522 */
523 function memoizedBinarySearch(haystack, needle, state, key) {
524 const { lastKey, lastNeedle, lastIndex } = state;
525 let low = 0;
526 let high = haystack.length - 1;
527 if (key === lastKey) {
528 if (needle === lastNeedle) {
529 found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
530 return lastIndex;
531 }
532 if (needle >= lastNeedle) {
533 // lastIndex may be -1 if the previous needle was not found.
534 low = lastIndex === -1 ? 0 : lastIndex;
535 }
536 else {
537 high = lastIndex;
538 }
539 }
540 state.lastKey = key;
541 state.lastNeedle = needle;
542 return (state.lastIndex = binarySearch(haystack, needle, low, high));
543 }
544
545 // Rebuilds the original source files, with mappings that are ordered by source line/column instead
546 // of generated line/column.
547 function buildBySources(decoded, memos) {
548 const sources = memos.map(buildNullArray);
549 for (let i = 0; i < decoded.length; i++) {
550 const line = decoded[i];
551 for (let j = 0; j < line.length; j++) {
552 const seg = line[j];
553 if (seg.length === 1)
554 continue;
555 const sourceIndex = seg[SOURCES_INDEX$1];
556 const sourceLine = seg[SOURCE_LINE$1];
557 const sourceColumn = seg[SOURCE_COLUMN$1];
558 const originalSource = sources[sourceIndex];
559 const originalLine = (originalSource[sourceLine] || (originalSource[sourceLine] = []));
560 const memo = memos[sourceIndex];
561 // The binary search either found a match, or it found the left-index just before where the
562 // segment should go. Either way, we want to insert after that. And there may be multiple
563 // generated segments associated with an original location, so there may need to move several
564 // indexes before we find where we need to insert.
565 let index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
566 memo.lastIndex = ++index;
567 insert$1(originalLine, index, [sourceColumn, i, seg[COLUMN$1]]);
568 }
569 }
570 return sources;
571 }
572 function insert$1(array, index, value) {
573 for (let i = array.length; i > index; i--) {
574 array[i] = array[i - 1];
575 }
576 array[index] = value;
577 }
578 // Null arrays allow us to use ordered index keys without actually allocating contiguous memory like
579 // a real array. We use a null-prototype object to avoid prototype pollution and deoptimizations.
580 // Numeric properties on objects are magically sorted in ascending order by the engine regardless of
581 // the insertion order. So, by setting any numeric keys, even out of order, we'll get ascending
582 // order when iterating with for-in.
583 function buildNullArray() {
584 return { __proto__: null };
585 }
586
587 const AnyMap = function (map, mapUrl) {
588 const parsed = parse(map);
589 if (!('sections' in parsed)) {
590 return new TraceMap(parsed, mapUrl);
591 }
592 const mappings = [];
593 const sources = [];
594 const sourcesContent = [];
595 const names = [];
596 const ignoreList = [];
597 recurse(parsed, mapUrl, mappings, sources, sourcesContent, names, ignoreList, 0, 0, Infinity, Infinity);
598 const joined = {
599 version: 3,
600 file: parsed.file,
601 names,
602 sources,
603 sourcesContent,
604 mappings,
605 ignoreList,
606 };
607 return presortedDecodedMap(joined);
608 };
609 function parse(map) {
610 return typeof map === 'string' ? JSON.parse(map) : map;
611 }
612 function recurse(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
613 const { sections } = input;
614 for (let i = 0; i < sections.length; i++) {
615 const { map, offset } = sections[i];
616 let sl = stopLine;
617 let sc = stopColumn;
618 if (i + 1 < sections.length) {
619 const nextOffset = sections[i + 1].offset;
620 sl = Math.min(stopLine, lineOffset + nextOffset.line);
621 if (sl === stopLine) {
622 sc = Math.min(stopColumn, columnOffset + nextOffset.column);
623 }
624 else if (sl < stopLine) {
625 sc = columnOffset + nextOffset.column;
626 }
627 }
628 addSection(map, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset + offset.line, columnOffset + offset.column, sl, sc);
629 }
630 }
631 function addSection(input, mapUrl, mappings, sources, sourcesContent, names, ignoreList, lineOffset, columnOffset, stopLine, stopColumn) {
632 const parsed = parse(input);
633 if ('sections' in parsed)
634 return recurse(...arguments);
635 const map = new TraceMap(parsed, mapUrl);
636 const sourcesOffset = sources.length;
637 const namesOffset = names.length;
638 const decoded = decodedMappings(map);
639 const { resolvedSources, sourcesContent: contents, ignoreList: ignores } = map;
640 append(sources, resolvedSources);
641 append(names, map.names);
642 if (contents)
643 append(sourcesContent, contents);
644 else
645 for (let i = 0; i < resolvedSources.length; i++)
646 sourcesContent.push(null);
647 if (ignores)
648 for (let i = 0; i < ignores.length; i++)
649 ignoreList.push(ignores[i] + sourcesOffset);
650 for (let i = 0; i < decoded.length; i++) {
651 const lineI = lineOffset + i;
652 // We can only add so many lines before we step into the range that the next section's map
653 // controls. When we get to the last line, then we'll start checking the segments to see if
654 // they've crossed into the column range. But it may not have any columns that overstep, so we
655 // still need to check that we don't overstep lines, too.
656 if (lineI > stopLine)
657 return;
658 // The out line may already exist in mappings (if we're continuing the line started by a
659 // previous section). Or, we may have jumped ahead several lines to start this section.
660 const out = getLine$1(mappings, lineI);
661 // On the 0th loop, the section's column offset shifts us forward. On all other lines (since the
662 // map can be multiple lines), it doesn't.
663 const cOffset = i === 0 ? columnOffset : 0;
664 const line = decoded[i];
665 for (let j = 0; j < line.length; j++) {
666 const seg = line[j];
667 const column = cOffset + seg[COLUMN$1];
668 // If this segment steps into the column range that the next section's map controls, we need
669 // to stop early.
670 if (lineI === stopLine && column >= stopColumn)
671 return;
672 if (seg.length === 1) {
673 out.push([column]);
674 continue;
675 }
676 const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX$1];
677 const sourceLine = seg[SOURCE_LINE$1];
678 const sourceColumn = seg[SOURCE_COLUMN$1];
679 out.push(seg.length === 4
680 ? [column, sourcesIndex, sourceLine, sourceColumn]
681 : [column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX$1]]);
682 }
683 }
684 }
685 function append(arr, other) {
686 for (let i = 0; i < other.length; i++)
687 arr.push(other[i]);
688 }
689 function getLine$1(arr, index) {
690 for (let i = arr.length; i <= index; i++)
691 arr[i] = [];
692 return arr[index];
693 }
694
695 const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
696 const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
697 const LEAST_UPPER_BOUND = -1;
698 const GREATEST_LOWER_BOUND = 1;
699 class TraceMap {
700 constructor(map, mapUrl) {
701 const isString = typeof map === 'string';
702 if (!isString && map._decodedMemo)
703 return map;
704 const parsed = (isString ? JSON.parse(map) : map);
705 const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
706 this.version = version;
707 this.file = file;
708 this.names = names || [];
709 this.sourceRoot = sourceRoot;
710 this.sources = sources;
711 this.sourcesContent = sourcesContent;
712 this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
713 const from = resolve(sourceRoot || '', stripFilename(mapUrl));
714 this.resolvedSources = sources.map((s) => resolve(s || '', from));
715 const { mappings } = parsed;
716 if (typeof mappings === 'string') {
717 this._encoded = mappings;
718 this._decoded = undefined;
719 }
720 else {
721 this._encoded = undefined;
722 this._decoded = maybeSort(mappings, isString);
723 }
724 this._decodedMemo = memoizedState();
725 this._bySources = undefined;
726 this._bySourceMemos = undefined;
727 }
728 }
729 /**
730 * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
731 * with public access modifiers.
732 */
733 function cast$2(map) {
734 return map;
735 }
736 /**
737 * Returns the encoded (VLQ string) form of the SourceMap's mappings field.
738 */
739 function encodedMappings(map) {
740 var _a;
741 var _b;
742 return ((_a = (_b = cast$2(map))._encoded) !== null && _a !== void 0 ? _a : (_b._encoded = encode(cast$2(map)._decoded)));
743 }
744 /**
745 * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
746 */
747 function decodedMappings(map) {
748 var _a;
749 return ((_a = cast$2(map))._decoded || (_a._decoded = decode(cast$2(map)._encoded)));
750 }
751 /**
752 * A higher-level API to find the source/line/column associated with a generated line/column
753 * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
754 * `source-map` library.
755 */
756 function originalPositionFor(map, needle) {
757 let { line, column, bias } = needle;
758 line--;
759 if (line < 0)
760 throw new Error(LINE_GTR_ZERO);
761 if (column < 0)
762 throw new Error(COL_GTR_EQ_ZERO);
763 const decoded = decodedMappings(map);
764 // It's common for parent source maps to have pointers to lines that have no
765 // mapping (like a "//# sourceMappingURL=") at the end of the child file.
766 if (line >= decoded.length)
767 return OMapping(null, null, null, null);
768 const segments = decoded[line];
769 const index = traceSegmentInternal(segments, cast$2(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
770 if (index === -1)
771 return OMapping(null, null, null, null);
772 const segment = segments[index];
773 if (segment.length === 1)
774 return OMapping(null, null, null, null);
775 const { names, resolvedSources } = map;
776 return OMapping(resolvedSources[segment[SOURCES_INDEX$1]], segment[SOURCE_LINE$1] + 1, segment[SOURCE_COLUMN$1], segment.length === 5 ? names[segment[NAMES_INDEX$1]] : null);
777 }
778 /**
779 * Finds the generated line/column position of the provided source/line/column source position.
780 */
781 function generatedPositionFor(map, needle) {
782 const { source, line, column, bias } = needle;
783 return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
784 }
785 /**
786 * Finds all generated line/column positions of the provided source/line/column source position.
787 */
788 function allGeneratedPositionsFor(map, needle) {
789 const { source, line, column, bias } = needle;
790 // SourceMapConsumer uses LEAST_UPPER_BOUND for some reason, so we follow suit.
791 return generatedPosition(map, source, line, column, bias || LEAST_UPPER_BOUND, true);
792 }
793 /**
794 * Iterates each mapping in generated position order.
795 */
796 function eachMapping(map, cb) {
797 const decoded = decodedMappings(map);
798 const { names, resolvedSources } = map;
799 for (let i = 0; i < decoded.length; i++) {
800 const line = decoded[i];
801 for (let j = 0; j < line.length; j++) {
802 const seg = line[j];
803 const generatedLine = i + 1;
804 const generatedColumn = seg[0];
805 let source = null;
806 let originalLine = null;
807 let originalColumn = null;
808 let name = null;
809 if (seg.length !== 1) {
810 source = resolvedSources[seg[1]];
811 originalLine = seg[2] + 1;
812 originalColumn = seg[3];
813 }
814 if (seg.length === 5)
815 name = names[seg[4]];
816 cb({
817 generatedLine,
818 generatedColumn,
819 source,
820 originalLine,
821 originalColumn,
822 name,
823 });
824 }
825 }
826 }
827 function sourceIndex(map, source) {
828 const { sources, resolvedSources } = map;
829 let index = sources.indexOf(source);
830 if (index === -1)
831 index = resolvedSources.indexOf(source);
832 return index;
833 }
834 /**
835 * Retrieves the source content for a particular source, if its found. Returns null if not.
836 */
837 function sourceContentFor(map, source) {
838 const { sourcesContent } = map;
839 if (sourcesContent == null)
840 return null;
841 const index = sourceIndex(map, source);
842 return index === -1 ? null : sourcesContent[index];
843 }
844 /**
845 * A helper that skips sorting of the input map's mappings array, which can be expensive for larger
846 * maps.
847 */
848 function presortedDecodedMap(map, mapUrl) {
849 const tracer = new TraceMap(clone(map, []), mapUrl);
850 cast$2(tracer)._decoded = map.mappings;
851 return tracer;
852 }
853 function clone(map, mappings) {
854 return {
855 version: map.version,
856 file: map.file,
857 names: map.names,
858 sourceRoot: map.sourceRoot,
859 sources: map.sources,
860 sourcesContent: map.sourcesContent,
861 mappings,
862 ignoreList: map.ignoreList || map.x_google_ignoreList,
863 };
864 }
865 function OMapping(source, line, column, name) {
866 return { source, line, column, name };
867 }
868 function GMapping(line, column) {
869 return { line, column };
870 }
871 function traceSegmentInternal(segments, memo, line, column, bias) {
872 let index = memoizedBinarySearch(segments, column, memo, line);
873 if (found) {
874 index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
875 }
876 else if (bias === LEAST_UPPER_BOUND)
877 index++;
878 if (index === -1 || index === segments.length)
879 return -1;
880 return index;
881 }
882 function sliceGeneratedPositions(segments, memo, line, column, bias) {
883 let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
884 // We ignored the bias when tracing the segment so that we're guarnateed to find the first (in
885 // insertion order) segment that matched. Even if we did respect the bias when tracing, we would
886 // still need to call `lowerBound()` to find the first segment, which is slower than just looking
887 // for the GREATEST_LOWER_BOUND to begin with. The only difference that matters for us is when the
888 // binary search didn't match, in which case GREATEST_LOWER_BOUND just needs to increment to
889 // match LEAST_UPPER_BOUND.
890 if (!found && bias === LEAST_UPPER_BOUND)
891 min++;
892 if (min === -1 || min === segments.length)
893 return [];
894 // We may have found the segment that started at an earlier column. If this is the case, then we
895 // need to slice all generated segments that match _that_ column, because all such segments span
896 // to our desired column.
897 const matchedColumn = found ? column : segments[min][COLUMN$1];
898 // The binary search is not guaranteed to find the lower bound when a match wasn't found.
899 if (!found)
900 min = lowerBound(segments, matchedColumn, min);
901 const max = upperBound(segments, matchedColumn, min);
902 const result = [];
903 for (; min <= max; min++) {
904 const segment = segments[min];
905 result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
906 }
907 return result;
908 }
909 function generatedPosition(map, source, line, column, bias, all) {
910 var _a;
911 line--;
912 if (line < 0)
913 throw new Error(LINE_GTR_ZERO);
914 if (column < 0)
915 throw new Error(COL_GTR_EQ_ZERO);
916 const { sources, resolvedSources } = map;
917 let sourceIndex = sources.indexOf(source);
918 if (sourceIndex === -1)
919 sourceIndex = resolvedSources.indexOf(source);
920 if (sourceIndex === -1)
921 return all ? [] : GMapping(null, null);
922 const generated = ((_a = cast$2(map))._bySources || (_a._bySources = buildBySources(decodedMappings(map), (cast$2(map)._bySourceMemos = sources.map(memoizedState)))));
923 const segments = generated[sourceIndex][line];
924 if (segments == null)
925 return all ? [] : GMapping(null, null);
926 const memo = cast$2(map)._bySourceMemos[sourceIndex];
927 if (all)
928 return sliceGeneratedPositions(segments, memo, line, column, bias);
929 const index = traceSegmentInternal(segments, memo, line, column, bias);
930 if (index === -1)
931 return GMapping(null, null);
932 const segment = segments[index];
933 return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
934 }
935
936 /**
937 * SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
938 * index of the `key` in the backing array.
939 *
940 * This is designed to allow synchronizing a second array with the contents of the backing array,
941 * like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
942 * and there are never duplicates.
943 */
944 class SetArray {
945 constructor() {
946 this._indexes = { __proto__: null };
947 this.array = [];
948 }
949 }
950 /**
951 * Typescript doesn't allow friend access to private fields, so this just casts the set into a type
952 * with public access modifiers.
953 */
954 function cast$1(set) {
955 return set;
956 }
957 /**
958 * Gets the index associated with `key` in the backing array, if it is already present.
959 */
960 function get(setarr, key) {
961 return cast$1(setarr)._indexes[key];
962 }
963 /**
964 * Puts `key` into the backing array, if it is not already present. Returns
965 * the index of the `key` in the backing array.
966 */
967 function put(setarr, key) {
968 // The key may or may not be present. If it is present, it's a number.
969 const index = get(setarr, key);
970 if (index !== undefined)
971 return index;
972 const { array, _indexes: indexes } = cast$1(setarr);
973 const length = array.push(key);
974 return (indexes[key] = length - 1);
975 }
976
977 const COLUMN = 0;
978 const SOURCES_INDEX = 1;
979 const SOURCE_LINE = 2;
980 const SOURCE_COLUMN = 3;
981 const NAMES_INDEX = 4;
982
983 const NO_NAME = -1;
984 /**
985 * Provides the state to generate a sourcemap.
986 */
987 class GenMapping {
988 constructor({ file, sourceRoot } = {}) {
989 this._names = new SetArray();
990 this._sources = new SetArray();
991 this._sourcesContent = [];
992 this._mappings = [];
993 this.file = file;
994 this.sourceRoot = sourceRoot;
995 this._ignoreList = new SetArray();
996 }
997 }
998 /**
999 * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
1000 * with public access modifiers.
1001 */
1002 function cast(map) {
1003 return map;
1004 }
1005 /**
1006 * Same as `addMapping`, but will only add the mapping if it generates useful information in the
1007 * resulting map. This only works correctly if mappings are added **in order**, meaning you should
1008 * not add a mapping with a lower generated line/column than one that came before.
1009 */
1010 const maybeAddMapping = (map, mapping) => {
1011 return addMappingInternal(true, map, mapping);
1012 };
1013 /**
1014 * Adds/removes the content of the source file to the source map.
1015 */
1016 function setSourceContent(map, source, content) {
1017 const { _sources: sources, _sourcesContent: sourcesContent } = cast(map);
1018 const index = put(sources, source);
1019 sourcesContent[index] = content;
1020 }
1021 /**
1022 * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
1023 * a sourcemap, or to JSON.stringify.
1024 */
1025 function toDecodedMap(map) {
1026 const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, _ignoreList: ignoreList, } = cast(map);
1027 removeEmptyFinalLines(mappings);
1028 return {
1029 version: 3,
1030 file: map.file || undefined,
1031 names: names.array,
1032 sourceRoot: map.sourceRoot || undefined,
1033 sources: sources.array,
1034 sourcesContent,
1035 mappings,
1036 ignoreList: ignoreList.array,
1037 };
1038 }
1039 /**
1040 * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
1041 * a sourcemap, or to JSON.stringify.
1042 */
1043 function toEncodedMap(map) {
1044 const decoded = toDecodedMap(map);
1045 return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
1046 }
1047 /**
1048 * Constructs a new GenMapping, using the already present mappings of the input.
1049 */
1050 function fromMap(input) {
1051 const map = new TraceMap(input);
1052 const gen = new GenMapping({ file: map.file, sourceRoot: map.sourceRoot });
1053 putAll(cast(gen)._names, map.names);
1054 putAll(cast(gen)._sources, map.sources);
1055 cast(gen)._sourcesContent = map.sourcesContent || map.sources.map(() => null);
1056 cast(gen)._mappings = decodedMappings(map);
1057 if (map.ignoreList)
1058 putAll(cast(gen)._ignoreList, map.ignoreList);
1059 return gen;
1060 }
1061 // This split declaration is only so that terser can elminiate the static initialization block.
1062 function addSegmentInternal(skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name, content) {
1063 const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = cast(map);
1064 const line = getLine(mappings, genLine);
1065 const index = getColumnIndex(line, genColumn);
1066 if (!source) {
1067 if (skipable && skipSourceless(line, index))
1068 return;
1069 return insert(line, index, [genColumn]);
1070 }
1071 const sourcesIndex = put(sources, source);
1072 const namesIndex = name ? put(names, name) : NO_NAME;
1073 if (sourcesIndex === sourcesContent.length)
1074 sourcesContent[sourcesIndex] = content !== null && content !== void 0 ? content : null;
1075 if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
1076 return;
1077 }
1078 return insert(line, index, name
1079 ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
1080 : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
1081 }
1082 function getLine(mappings, index) {
1083 for (let i = mappings.length; i <= index; i++) {
1084 mappings[i] = [];
1085 }
1086 return mappings[index];
1087 }
1088 function getColumnIndex(line, genColumn) {
1089 let index = line.length;
1090 for (let i = index - 1; i >= 0; index = i--) {
1091 const current = line[i];
1092 if (genColumn >= current[COLUMN])
1093 break;
1094 }
1095 return index;
1096 }
1097 function insert(array, index, value) {
1098 for (let i = array.length; i > index; i--) {
1099 array[i] = array[i - 1];
1100 }
1101 array[index] = value;
1102 }
1103 function removeEmptyFinalLines(mappings) {
1104 const { length } = mappings;
1105 let len = length;
1106 for (let i = len - 1; i >= 0; len = i, i--) {
1107 if (mappings[i].length > 0)
1108 break;
1109 }
1110 if (len < length)
1111 mappings.length = len;
1112 }
1113 function putAll(setarr, array) {
1114 for (let i = 0; i < array.length; i++)
1115 put(setarr, array[i]);
1116 }
1117 function skipSourceless(line, index) {
1118 // The start of a line is already sourceless, so adding a sourceless segment to the beginning
1119 // doesn't generate any useful information.
1120 if (index === 0)
1121 return true;
1122 const prev = line[index - 1];
1123 // If the previous segment is also sourceless, then adding another sourceless segment doesn't
1124 // genrate any new information. Else, this segment will end the source/named segment and point to
1125 // a sourceless position, which is useful.
1126 return prev.length === 1;
1127 }
1128 function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
1129 // A source/named segment at the start of a line gives position at that genColumn
1130 if (index === 0)
1131 return false;
1132 const prev = line[index - 1];
1133 // If the previous segment is sourceless, then we're transitioning to a source.
1134 if (prev.length === 1)
1135 return false;
1136 // If the previous segment maps to the exact same source position, then this segment doesn't
1137 // provide any new position information.
1138 return (sourcesIndex === prev[SOURCES_INDEX] &&
1139 sourceLine === prev[SOURCE_LINE] &&
1140 sourceColumn === prev[SOURCE_COLUMN] &&
1141 namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME));
1142 }
1143 function addMappingInternal(skipable, map, mapping) {
1144 const { generated, source, original, name, content } = mapping;
1145 if (!source) {
1146 return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null, null);
1147 }
1148 return addSegmentInternal(skipable, map, generated.line - 1, generated.column, source, original.line - 1, original.column, name, content);
1149 }
1150
1151 class SourceMapConsumer {
1152 constructor(map, mapUrl) {
1153 const trace = (this._map = new AnyMap(map, mapUrl));
1154 this.file = trace.file;
1155 this.names = trace.names;
1156 this.sourceRoot = trace.sourceRoot;
1157 this.sources = trace.resolvedSources;
1158 this.sourcesContent = trace.sourcesContent;
1159 this.version = trace.version;
1160 }
1161 static fromSourceMap(map, mapUrl) {
1162 // This is more performant if we receive
1163 // a @jridgewell/source-map SourceMapGenerator
1164 if (map.toDecodedMap) {
1165 return new SourceMapConsumer(map.toDecodedMap(), mapUrl);
1166 }
1167 // This is a fallback for `source-map` and `source-map-js`
1168 return new SourceMapConsumer(map.toJSON(), mapUrl);
1169 }
1170 get mappings() {
1171 return encodedMappings(this._map);
1172 }
1173 originalPositionFor(needle) {
1174 return originalPositionFor(this._map, needle);
1175 }
1176 generatedPositionFor(originalPosition) {
1177 return generatedPositionFor(this._map, originalPosition);
1178 }
1179 allGeneratedPositionsFor(originalPosition) {
1180 return allGeneratedPositionsFor(this._map, originalPosition);
1181 }
1182 hasContentsOfAllSources() {
1183 if (!this.sourcesContent || this.sourcesContent.length !== this.sources.length) {
1184 return false;
1185 }
1186 for (const content of this.sourcesContent) {
1187 if (content == null) {
1188 return false;
1189 }
1190 }
1191 return true;
1192 }
1193 sourceContentFor(source, nullOnMissing) {
1194 const sourceContent = sourceContentFor(this._map, source);
1195 if (sourceContent != null) {
1196 return sourceContent;
1197 }
1198 if (nullOnMissing) {
1199 return null;
1200 }
1201 throw new Error(`"${source}" is not in the SourceMap.`);
1202 }
1203 eachMapping(callback, context /*, order?: number*/) {
1204 // order is ignored as @jridgewell/trace-map doesn't implement it
1205 eachMapping(this._map, context ? callback.bind(context) : callback);
1206 }
1207 destroy() {
1208 // noop.
1209 }
1210 }
1211 class SourceMapGenerator {
1212 constructor(opts) {
1213 // TODO :: should this be duck-typed ?
1214 this._map = opts instanceof GenMapping ? opts : new GenMapping(opts);
1215 }
1216 static fromSourceMap(consumer) {
1217 return new SourceMapGenerator(fromMap(consumer));
1218 }
1219 addMapping(mapping) {
1220 maybeAddMapping(this._map, mapping);
1221 }
1222 setSourceContent(source, content) {
1223 setSourceContent(this._map, source, content);
1224 }
1225 toJSON() {
1226 return toEncodedMap(this._map);
1227 }
1228 toString() {
1229 return JSON.stringify(this.toJSON());
1230 }
1231 toDecodedMap() {
1232 return toDecodedMap(this._map);
1233 }
1234 }
1235
1236 exports.SourceMapConsumer = SourceMapConsumer;
1237 exports.SourceMapGenerator = SourceMapGenerator;
1238
1239 Object.defineProperty(exports, '__esModule', { value: true });
1240
1241}));
1242//# sourceMappingURL=source-map.umd.js.map
Note: See TracBrowser for help on using the repository browser.