1 | (function (global, factory) {
|
---|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
---|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
---|
4 | (global = global || self, factory(global.sourcemapCodec = {}));
|
---|
5 | }(this, function (exports) { 'use strict';
|
---|
6 |
|
---|
7 | var charToInteger = {};
|
---|
8 | var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
---|
9 | for (var i = 0; i < chars.length; i++) {
|
---|
10 | charToInteger[chars.charCodeAt(i)] = i;
|
---|
11 | }
|
---|
12 | function decode(mappings) {
|
---|
13 | var decoded = [];
|
---|
14 | var line = [];
|
---|
15 | var segment = [
|
---|
16 | 0,
|
---|
17 | 0,
|
---|
18 | 0,
|
---|
19 | 0,
|
---|
20 | 0,
|
---|
21 | ];
|
---|
22 | var j = 0;
|
---|
23 | for (var i = 0, shift = 0, value = 0; i < mappings.length; i++) {
|
---|
24 | var c = mappings.charCodeAt(i);
|
---|
25 | if (c === 44) { // ","
|
---|
26 | segmentify(line, segment, j);
|
---|
27 | j = 0;
|
---|
28 | }
|
---|
29 | else if (c === 59) { // ";"
|
---|
30 | segmentify(line, segment, j);
|
---|
31 | j = 0;
|
---|
32 | decoded.push(line);
|
---|
33 | line = [];
|
---|
34 | segment[0] = 0;
|
---|
35 | }
|
---|
36 | else {
|
---|
37 | var integer = charToInteger[c];
|
---|
38 | if (integer === undefined) {
|
---|
39 | throw new Error('Invalid character (' + String.fromCharCode(c) + ')');
|
---|
40 | }
|
---|
41 | var hasContinuationBit = integer & 32;
|
---|
42 | integer &= 31;
|
---|
43 | value += integer << shift;
|
---|
44 | if (hasContinuationBit) {
|
---|
45 | shift += 5;
|
---|
46 | }
|
---|
47 | else {
|
---|
48 | var shouldNegate = value & 1;
|
---|
49 | value >>>= 1;
|
---|
50 | if (shouldNegate) {
|
---|
51 | value = value === 0 ? -0x80000000 : -value;
|
---|
52 | }
|
---|
53 | segment[j] += value;
|
---|
54 | j++;
|
---|
55 | value = shift = 0; // reset
|
---|
56 | }
|
---|
57 | }
|
---|
58 | }
|
---|
59 | segmentify(line, segment, j);
|
---|
60 | decoded.push(line);
|
---|
61 | return decoded;
|
---|
62 | }
|
---|
63 | function segmentify(line, segment, j) {
|
---|
64 | // This looks ugly, but we're creating specialized arrays with a specific
|
---|
65 | // length. This is much faster than creating a new array (which v8 expands to
|
---|
66 | // a capacity of 17 after pushing the first item), or slicing out a subarray
|
---|
67 | // (which is slow). Length 4 is assumed to be the most frequent, followed by
|
---|
68 | // length 5 (since not everything will have an associated name), followed by
|
---|
69 | // length 1 (it's probably rare for a source substring to not have an
|
---|
70 | // associated segment data).
|
---|
71 | if (j === 4)
|
---|
72 | line.push([segment[0], segment[1], segment[2], segment[3]]);
|
---|
73 | else if (j === 5)
|
---|
74 | line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]);
|
---|
75 | else if (j === 1)
|
---|
76 | line.push([segment[0]]);
|
---|
77 | }
|
---|
78 | function encode(decoded) {
|
---|
79 | var sourceFileIndex = 0; // second field
|
---|
80 | var sourceCodeLine = 0; // third field
|
---|
81 | var sourceCodeColumn = 0; // fourth field
|
---|
82 | var nameIndex = 0; // fifth field
|
---|
83 | var mappings = '';
|
---|
84 | for (var i = 0; i < decoded.length; i++) {
|
---|
85 | var line = decoded[i];
|
---|
86 | if (i > 0)
|
---|
87 | mappings += ';';
|
---|
88 | if (line.length === 0)
|
---|
89 | continue;
|
---|
90 | var generatedCodeColumn = 0; // first field
|
---|
91 | var lineMappings = [];
|
---|
92 | for (var _i = 0, line_1 = line; _i < line_1.length; _i++) {
|
---|
93 | var segment = line_1[_i];
|
---|
94 | var segmentMappings = encodeInteger(segment[0] - generatedCodeColumn);
|
---|
95 | generatedCodeColumn = segment[0];
|
---|
96 | if (segment.length > 1) {
|
---|
97 | segmentMappings +=
|
---|
98 | encodeInteger(segment[1] - sourceFileIndex) +
|
---|
99 | encodeInteger(segment[2] - sourceCodeLine) +
|
---|
100 | encodeInteger(segment[3] - sourceCodeColumn);
|
---|
101 | sourceFileIndex = segment[1];
|
---|
102 | sourceCodeLine = segment[2];
|
---|
103 | sourceCodeColumn = segment[3];
|
---|
104 | }
|
---|
105 | if (segment.length === 5) {
|
---|
106 | segmentMappings += encodeInteger(segment[4] - nameIndex);
|
---|
107 | nameIndex = segment[4];
|
---|
108 | }
|
---|
109 | lineMappings.push(segmentMappings);
|
---|
110 | }
|
---|
111 | mappings += lineMappings.join(',');
|
---|
112 | }
|
---|
113 | return mappings;
|
---|
114 | }
|
---|
115 | function encodeInteger(num) {
|
---|
116 | var result = '';
|
---|
117 | num = num < 0 ? (-num << 1) | 1 : num << 1;
|
---|
118 | do {
|
---|
119 | var clamped = num & 31;
|
---|
120 | num >>>= 5;
|
---|
121 | if (num > 0) {
|
---|
122 | clamped |= 32;
|
---|
123 | }
|
---|
124 | result += chars[clamped];
|
---|
125 | } while (num > 0);
|
---|
126 | return result;
|
---|
127 | }
|
---|
128 |
|
---|
129 | exports.decode = decode;
|
---|
130 | exports.encode = encode;
|
---|
131 |
|
---|
132 | Object.defineProperty(exports, '__esModule', { value: true });
|
---|
133 |
|
---|
134 | }));
|
---|
135 | //# sourceMappingURL=sourcemap-codec.umd.js.map
|
---|