vite 3.0.0-alpha.7 → 3.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2884 +1,954 @@
1
1
  'use strict';
2
2
 
3
- var require$$0 = require('url');
4
- var require$$0$1 = require('fs');
5
- var require$$1 = require('path');
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
8
-
9
- var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
10
- var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
11
- var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
12
-
13
3
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
14
4
 
15
5
  var bundle_min$1 = {exports: {}};
16
6
 
17
- var sourceMap = {};
18
-
19
- var sourceMapGenerator = {};
20
-
21
- var base64Vlq = {};
22
-
23
- var base64$1 = {};
24
-
25
- /* -*- Mode: js; js-indent-level: 2; -*- */
26
-
27
- /*
28
- * Copyright 2011 Mozilla Foundation and contributors
29
- * Licensed under the New BSD license. See LICENSE or:
30
- * http://opensource.org/licenses/BSD-3-Clause
31
- */
32
-
33
- const intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
34
-
35
- /**
36
- * Encode an integer in the range of 0 to 63 to a single base 64 digit.
37
- */
38
- base64$1.encode = function(number) {
39
- if (0 <= number && number < intToCharMap.length) {
40
- return intToCharMap[number];
41
- }
42
- throw new TypeError("Must be between 0 and 63: " + number);
43
- };
44
-
45
- /* -*- Mode: js; js-indent-level: 2; -*- */
46
-
47
- /*
48
- * Copyright 2011 Mozilla Foundation and contributors
49
- * Licensed under the New BSD license. See LICENSE or:
50
- * http://opensource.org/licenses/BSD-3-Clause
51
- *
52
- * Based on the Base 64 VLQ implementation in Closure Compiler:
53
- * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
54
- *
55
- * Copyright 2011 The Closure Compiler Authors. All rights reserved.
56
- * Redistribution and use in source and binary forms, with or without
57
- * modification, are permitted provided that the following conditions are
58
- * met:
59
- *
60
- * * Redistributions of source code must retain the above copyright
61
- * notice, this list of conditions and the following disclaimer.
62
- * * Redistributions in binary form must reproduce the above
63
- * copyright notice, this list of conditions and the following
64
- * disclaimer in the documentation and/or other materials provided
65
- * with the distribution.
66
- * * Neither the name of Google Inc. nor the names of its
67
- * contributors may be used to endorse or promote products derived
68
- * from this software without specific prior written permission.
69
- *
70
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
71
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
72
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
73
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
74
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
75
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
76
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
77
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
78
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
79
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81
- */
82
-
83
- const base64 = base64$1;
84
-
85
- // A single base 64 digit can contain 6 bits of data. For the base 64 variable
86
- // length quantities we use in the source map spec, the first bit is the sign,
87
- // the next four bits are the actual value, and the 6th bit is the
88
- // continuation bit. The continuation bit tells us whether there are more
89
- // digits in this value following this digit.
90
- //
91
- // Continuation
92
- // | Sign
93
- // | |
94
- // V V
95
- // 101011
96
-
97
- const VLQ_BASE_SHIFT = 5;
98
-
99
- // binary: 100000
100
- const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
101
-
102
- // binary: 011111
103
- const VLQ_BASE_MASK = VLQ_BASE - 1;
104
-
105
- // binary: 100000
106
- const VLQ_CONTINUATION_BIT = VLQ_BASE;
107
-
108
- /**
109
- * Converts from a two-complement value to a value where the sign bit is
110
- * placed in the least significant bit. For example, as decimals:
111
- * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
112
- * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
113
- */
114
- function toVLQSigned(aValue) {
115
- return aValue < 0
116
- ? ((-aValue) << 1) + 1
117
- : (aValue << 1) + 0;
118
- }
119
-
120
- /**
121
- * Returns the base 64 VLQ encoded value.
122
- */
123
- base64Vlq.encode = function base64VLQ_encode(aValue) {
124
- let encoded = "";
125
- let digit;
126
-
127
- let vlq = toVLQSigned(aValue);
128
-
129
- do {
130
- digit = vlq & VLQ_BASE_MASK;
131
- vlq >>>= VLQ_BASE_SHIFT;
132
- if (vlq > 0) {
133
- // There are still more digits in this value, so we must make sure the
134
- // continuation bit is marked.
135
- digit |= VLQ_CONTINUATION_BIT;
136
- }
137
- encoded += base64.encode(digit);
138
- } while (vlq > 0);
139
-
140
- return encoded;
141
- };
142
-
143
- var util$4 = {};
144
-
145
- /* -*- Mode: js; js-indent-level: 2; -*- */
146
-
147
- // Note: This file is overridden in the 'package.json#browser' field to
148
- // substitute lib/url-browser.js instead.
149
-
150
- // Use the URL global for Node 10, and the 'url' module for Node 8.
151
- var url = typeof URL === "function" ? URL : require$$0__default.URL;
152
-
153
- /* -*- Mode: js; js-indent-level: 2; -*- */
154
-
155
- /*
156
- * Copyright 2011 Mozilla Foundation and contributors
157
- * Licensed under the New BSD license. See LICENSE or:
158
- * http://opensource.org/licenses/BSD-3-Clause
159
- */
160
-
161
- const URL$1 = url;
162
-
163
- /**
164
- * This is a helper function for getting values from parameter/options
165
- * objects.
166
- *
167
- * @param args The object we are extracting values from
168
- * @param name The name of the property we are getting.
169
- * @param defaultValue An optional value to return if the property is missing
170
- * from the object. If this is not specified and the property is missing, an
171
- * error will be thrown.
172
- */
173
- function getArg(aArgs, aName, aDefaultValue) {
174
- if (aName in aArgs) {
175
- return aArgs[aName];
176
- } else if (arguments.length === 3) {
177
- return aDefaultValue;
178
- }
179
- throw new Error('"' + aName + '" is a required argument.');
180
-
181
- }
182
- util$4.getArg = getArg;
183
-
184
- const supportsNullProto = (function() {
185
- const obj = Object.create(null);
186
- return !("__proto__" in obj);
187
- }());
188
-
189
- function identity(s) {
190
- return s;
191
- }
192
-
193
- /**
194
- * Because behavior goes wacky when you set `__proto__` on objects, we
195
- * have to prefix all the strings in our set with an arbitrary character.
196
- *
197
- * See https://github.com/mozilla/source-map/pull/31 and
198
- * https://github.com/mozilla/source-map/issues/30
199
- *
200
- * @param String aStr
201
- */
202
- function toSetString(aStr) {
203
- if (isProtoString(aStr)) {
204
- return "$" + aStr;
205
- }
206
-
207
- return aStr;
208
- }
209
- util$4.toSetString = supportsNullProto ? identity : toSetString;
210
-
211
- function fromSetString(aStr) {
212
- if (isProtoString(aStr)) {
213
- return aStr.slice(1);
214
- }
215
-
216
- return aStr;
217
- }
218
- util$4.fromSetString = supportsNullProto ? identity : fromSetString;
219
-
220
- function isProtoString(s) {
221
- if (!s) {
222
- return false;
223
- }
224
-
225
- const length = s.length;
226
-
227
- if (length < 9 /* "__proto__".length */) {
228
- return false;
229
- }
230
-
231
- /* eslint-disable no-multi-spaces */
232
- if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
233
- s.charCodeAt(length - 2) !== 95 /* '_' */ ||
234
- s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
235
- s.charCodeAt(length - 4) !== 116 /* 't' */ ||
236
- s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
237
- s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
238
- s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
239
- s.charCodeAt(length - 8) !== 95 /* '_' */ ||
240
- s.charCodeAt(length - 9) !== 95 /* '_' */) {
241
- return false;
242
- }
243
- /* eslint-enable no-multi-spaces */
244
-
245
- for (let i = length - 10; i >= 0; i--) {
246
- if (s.charCodeAt(i) !== 36 /* '$' */) {
247
- return false;
248
- }
249
- }
250
-
251
- return true;
252
- }
253
-
254
- function strcmp(aStr1, aStr2) {
255
- if (aStr1 === aStr2) {
256
- return 0;
257
- }
258
-
259
- if (aStr1 === null) {
260
- return 1; // aStr2 !== null
261
- }
262
-
263
- if (aStr2 === null) {
264
- return -1; // aStr1 !== null
265
- }
266
-
267
- if (aStr1 > aStr2) {
268
- return 1;
269
- }
270
-
271
- return -1;
272
- }
273
-
274
- /**
275
- * Comparator between two mappings with inflated source and name strings where
276
- * the generated positions are compared.
277
- */
278
- function compareByGeneratedPositionsInflated(mappingA, mappingB) {
279
- let cmp = mappingA.generatedLine - mappingB.generatedLine;
280
- if (cmp !== 0) {
281
- return cmp;
282
- }
283
-
284
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
285
- if (cmp !== 0) {
286
- return cmp;
287
- }
288
-
289
- cmp = strcmp(mappingA.source, mappingB.source);
290
- if (cmp !== 0) {
291
- return cmp;
292
- }
293
-
294
- cmp = mappingA.originalLine - mappingB.originalLine;
295
- if (cmp !== 0) {
296
- return cmp;
297
- }
298
-
299
- cmp = mappingA.originalColumn - mappingB.originalColumn;
300
- if (cmp !== 0) {
301
- return cmp;
302
- }
303
-
304
- return strcmp(mappingA.name, mappingB.name);
305
- }
306
- util$4.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
307
-
308
- /**
309
- * Strip any JSON XSSI avoidance prefix from the string (as documented
310
- * in the source maps specification), and then parse the string as
311
- * JSON.
312
- */
313
- function parseSourceMapInput(str) {
314
- return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ""));
315
- }
316
- util$4.parseSourceMapInput = parseSourceMapInput;
317
-
318
- // We use 'http' as the base here because we want URLs processed relative
319
- // to the safe base to be treated as "special" URLs during parsing using
320
- // the WHATWG URL parsing. This ensures that backslash normalization
321
- // applies to the path and such.
322
- const PROTOCOL = "http:";
323
- const PROTOCOL_AND_HOST = `${PROTOCOL}//host`;
324
-
325
- /**
326
- * Make it easy to create small utilities that tweak a URL's path.
327
- */
328
- function createSafeHandler(cb) {
329
- return input => {
330
- const type = getURLType(input);
331
- const base = buildSafeBase(input);
332
- const url = new URL$1(input, base);
333
-
334
- cb(url);
335
-
336
- const result = url.toString();
337
-
338
- if (type === "absolute") {
339
- return result;
340
- } else if (type === "scheme-relative") {
341
- return result.slice(PROTOCOL.length);
342
- } else if (type === "path-absolute") {
343
- return result.slice(PROTOCOL_AND_HOST.length);
344
- }
345
-
346
- // This assumes that the callback will only change
347
- // the path, search and hash values.
348
- return computeRelativeURL(base, result);
349
- };
350
- }
351
-
352
- function withBase(url, base) {
353
- return new URL$1(url, base).toString();
354
- }
355
-
356
- function buildUniqueSegment(prefix, str) {
357
- let id = 0;
358
- do {
359
- const ident = prefix + (id++);
360
- if (str.indexOf(ident) === -1) return ident;
361
- } while (true);
362
- }
363
-
364
- function buildSafeBase(str) {
365
- const maxDotParts = str.split("..").length - 1;
366
-
367
- // If we used a segment that also existed in `str`, then we would be unable
368
- // to compute relative paths. For example, if `segment` were just "a":
369
- //
370
- // const url = "../../a/"
371
- // const base = buildSafeBase(url); // http://host/a/a/
372
- // const joined = "http://host/a/";
373
- // const result = relative(base, joined);
374
- //
375
- // Expected: "../../a/";
376
- // Actual: "a/"
377
- //
378
- const segment = buildUniqueSegment("p", str);
379
-
380
- let base = `${PROTOCOL_AND_HOST}/`;
381
- for (let i = 0; i < maxDotParts; i++) {
382
- base += `${segment}/`;
383
- }
384
- return base;
385
- }
386
-
387
- const ABSOLUTE_SCHEME = /^[A-Za-z0-9\+\-\.]+:/;
388
- function getURLType(url) {
389
- if (url[0] === "/") {
390
- if (url[1] === "/") return "scheme-relative";
391
- return "path-absolute";
392
- }
393
-
394
- return ABSOLUTE_SCHEME.test(url) ? "absolute" : "path-relative";
395
- }
396
-
397
- /**
398
- * Given two URLs that are assumed to be on the same
399
- * protocol/host/user/password build a relative URL from the
400
- * path, params, and hash values.
401
- *
402
- * @param rootURL The root URL that the target will be relative to.
403
- * @param targetURL The target that the relative URL points to.
404
- * @return A rootURL-relative, normalized URL value.
405
- */
406
- function computeRelativeURL(rootURL, targetURL) {
407
- if (typeof rootURL === "string") rootURL = new URL$1(rootURL);
408
- if (typeof targetURL === "string") targetURL = new URL$1(targetURL);
409
-
410
- const targetParts = targetURL.pathname.split("/");
411
- const rootParts = rootURL.pathname.split("/");
412
-
413
- // If we've got a URL path ending with a "/", we remove it since we'd
414
- // otherwise be relative to the wrong location.
415
- if (rootParts.length > 0 && !rootParts[rootParts.length - 1]) {
416
- rootParts.pop();
417
- }
418
-
419
- while (
420
- targetParts.length > 0 &&
421
- rootParts.length > 0 &&
422
- targetParts[0] === rootParts[0]
423
- ) {
424
- targetParts.shift();
425
- rootParts.shift();
426
- }
427
-
428
- const relativePath = rootParts
429
- .map(() => "..")
430
- .concat(targetParts)
431
- .join("/");
432
-
433
- return relativePath + targetURL.search + targetURL.hash;
434
- }
435
-
436
- /**
437
- * Given a URL, ensure that it is treated as a directory URL.
438
- *
439
- * @param url
440
- * @return A normalized URL value.
441
- */
442
- const ensureDirectory = createSafeHandler(url => {
443
- url.pathname = url.pathname.replace(/\/?$/, "/");
444
- });
445
-
446
- /**
447
- * Given a URL, strip off any filename if one is present.
448
- *
449
- * @param url
450
- * @return A normalized URL value.
451
- */
452
- const trimFilename = createSafeHandler(url => {
453
- url.href = new URL$1(".", url.toString()).toString();
454
- });
455
-
456
- /**
457
- * Normalize a given URL.
458
- * * Convert backslashes.
459
- * * Remove any ".." and "." segments.
460
- *
461
- * @param url
462
- * @return A normalized URL value.
463
- */
464
- const normalize = createSafeHandler(url => {});
465
- util$4.normalize = normalize;
466
-
467
- /**
468
- * Joins two paths/URLs.
469
- *
470
- * All returned URLs will be normalized.
471
- *
472
- * @param aRoot The root path or URL. Assumed to reference a directory.
473
- * @param aPath The path or URL to be joined with the root.
474
- * @return A joined and normalized URL value.
475
- */
476
- function join(aRoot, aPath) {
477
- const pathType = getURLType(aPath);
478
- const rootType = getURLType(aRoot);
479
-
480
- aRoot = ensureDirectory(aRoot);
481
-
482
- if (pathType === "absolute") {
483
- return withBase(aPath, undefined);
484
- }
485
- if (rootType === "absolute") {
486
- return withBase(aPath, aRoot);
487
- }
488
-
489
- if (pathType === "scheme-relative") {
490
- return normalize(aPath);
491
- }
492
- if (rootType === "scheme-relative") {
493
- return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice(PROTOCOL.length);
494
- }
495
-
496
- if (pathType === "path-absolute") {
497
- return normalize(aPath);
498
- }
499
- if (rootType === "path-absolute") {
500
- return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice(PROTOCOL_AND_HOST.length);
501
- }
502
-
503
- const base = buildSafeBase(aPath + aRoot);
504
- const newPath = withBase(aPath, withBase(aRoot, base));
505
- return computeRelativeURL(base, newPath);
506
- }
507
- util$4.join = join;
508
-
509
- /**
510
- * Make a path relative to a URL or another path. If returning a
511
- * relative URL is not possible, the original target will be returned.
512
- * All returned URLs will be normalized.
513
- *
514
- * @param aRoot The root path or URL.
515
- * @param aPath The path or URL to be made relative to aRoot.
516
- * @return A rootURL-relative (if possible), normalized URL value.
517
- */
518
- function relative(rootURL, targetURL) {
519
- const result = relativeIfPossible(rootURL, targetURL);
520
-
521
- return typeof result === "string" ? result : normalize(targetURL);
522
- }
523
- util$4.relative = relative;
524
-
525
- function relativeIfPossible(rootURL, targetURL) {
526
- const urlType = getURLType(rootURL);
527
- if (urlType !== getURLType(targetURL)) {
528
- return null;
529
- }
530
-
531
- const base = buildSafeBase(rootURL + targetURL);
532
- const root = new URL$1(rootURL, base);
533
- const target = new URL$1(targetURL, base);
534
-
535
- try {
536
- new URL$1("", target.toString());
537
- } catch (err) {
538
- // Bail if the URL doesn't support things being relative to it,
539
- // For example, data: and blob: URLs.
540
- return null;
541
- }
542
-
543
- if (
544
- target.protocol !== root.protocol ||
545
- target.user !== root.user ||
546
- target.password !== root.password ||
547
- target.hostname !== root.hostname ||
548
- target.port !== root.port
549
- ) {
550
- return null;
551
- }
552
-
553
- return computeRelativeURL(root, target);
554
- }
555
-
556
- /**
557
- * Compute the URL of a source given the the source root, the source's
558
- * URL, and the source map's URL.
559
- */
560
- function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
561
- // The source map spec states that "sourceRoot" and "sources" entries are to be appended. While
562
- // that is a little vague, implementations have generally interpreted that as joining the
563
- // URLs with a `/` between then, assuming the "sourceRoot" doesn't already end with one.
564
- // For example,
565
- //
566
- // sourceRoot: "some-dir",
567
- // sources: ["/some-path.js"]
568
- //
569
- // and
570
- //
571
- // sourceRoot: "some-dir/",
572
- // sources: ["/some-path.js"]
573
- //
574
- // must behave as "some-dir/some-path.js".
575
- //
576
- // With this library's the transition to a more URL-focused implementation, that behavior is
577
- // preserved here. To acheive that, we trim the "/" from absolute-path when a sourceRoot value
578
- // is present in order to make the sources entries behave as if they are relative to the
579
- // "sourceRoot", as they would have if the two strings were simply concated.
580
- if (sourceRoot && getURLType(sourceURL) === "path-absolute") {
581
- sourceURL = sourceURL.replace(/^\//, "");
582
- }
583
-
584
- let url = normalize(sourceURL || "");
585
-
586
- // Parsing URLs can be expensive, so we only perform these joins when needed.
587
- if (sourceRoot) url = join(sourceRoot, url);
588
- if (sourceMapURL) url = join(trimFilename(sourceMapURL), url);
589
- return url;
590
- }
591
- util$4.computeSourceURL = computeSourceURL;
592
-
593
- var arraySet = {};
594
-
595
- /* -*- Mode: js; js-indent-level: 2; -*- */
7
+ var sourceMap_umd = {exports: {}};
596
8
 
597
- /*
598
- * Copyright 2011 Mozilla Foundation and contributors
599
- * Licensed under the New BSD license. See LICENSE or:
600
- * http://opensource.org/licenses/BSD-3-Clause
601
- */
602
-
603
- /**
604
- * A data structure which is a combination of an array and a set. Adding a new
605
- * member is O(1), testing for membership is O(1), and finding the index of an
606
- * element is O(1). Removing elements from the set is not supported. Only
607
- * strings are supported for membership.
608
- */
609
- class ArraySet$2 {
610
- constructor() {
611
- this._array = [];
612
- this._set = new Map();
613
- }
614
-
615
- /**
616
- * Static method for creating ArraySet instances from an existing array.
617
- */
618
- static fromArray(aArray, aAllowDuplicates) {
619
- const set = new ArraySet$2();
620
- for (let i = 0, len = aArray.length; i < len; i++) {
621
- set.add(aArray[i], aAllowDuplicates);
622
- }
623
- return set;
624
- }
625
-
626
- /**
627
- * Return how many unique items are in this ArraySet. If duplicates have been
628
- * added, than those do not count towards the size.
629
- *
630
- * @returns Number
631
- */
632
- size() {
633
- return this._set.size;
634
- }
635
-
636
- /**
637
- * Add the given string to this set.
638
- *
639
- * @param String aStr
640
- */
641
- add(aStr, aAllowDuplicates) {
642
- const isDuplicate = this.has(aStr);
643
- const idx = this._array.length;
644
- if (!isDuplicate || aAllowDuplicates) {
645
- this._array.push(aStr);
646
- }
647
- if (!isDuplicate) {
648
- this._set.set(aStr, idx);
649
- }
650
- }
651
-
652
- /**
653
- * Is the given string a member of this set?
654
- *
655
- * @param String aStr
656
- */
657
- has(aStr) {
658
- return this._set.has(aStr);
659
- }
660
-
661
- /**
662
- * What is the index of the given string in the array?
663
- *
664
- * @param String aStr
665
- */
666
- indexOf(aStr) {
667
- const idx = this._set.get(aStr);
668
- if (idx >= 0) {
669
- return idx;
670
- }
671
- throw new Error('"' + aStr + '" is not in the set.');
672
- }
673
-
674
- /**
675
- * What is the element at the given index?
676
- *
677
- * @param Number aIdx
678
- */
679
- at(aIdx) {
680
- if (aIdx >= 0 && aIdx < this._array.length) {
681
- return this._array[aIdx];
682
- }
683
- throw new Error("No element indexed by " + aIdx);
684
- }
685
-
686
- /**
687
- * Returns the array representation of this set (which has the proper indices
688
- * indicated by indexOf). Note that this is a copy of the internal array used
689
- * for storing the members so that no one can mess with internal state.
690
- */
691
- toArray() {
692
- return this._array.slice();
693
- }
694
- }
695
- arraySet.ArraySet = ArraySet$2;
696
-
697
- var mappingList = {};
698
-
699
- /* -*- Mode: js; js-indent-level: 2; -*- */
700
-
701
- /*
702
- * Copyright 2014 Mozilla Foundation and contributors
703
- * Licensed under the New BSD license. See LICENSE or:
704
- * http://opensource.org/licenses/BSD-3-Clause
705
- */
706
-
707
- const util$3 = util$4;
708
-
709
- /**
710
- * Determine whether mappingB is after mappingA with respect to generated
711
- * position.
712
- */
713
- function generatedPositionAfter(mappingA, mappingB) {
714
- // Optimized for most common case
715
- const lineA = mappingA.generatedLine;
716
- const lineB = mappingB.generatedLine;
717
- const columnA = mappingA.generatedColumn;
718
- const columnB = mappingB.generatedColumn;
719
- return lineB > lineA || lineB == lineA && columnB >= columnA ||
720
- util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
721
- }
722
-
723
- /**
724
- * A data structure to provide a sorted view of accumulated mappings in a
725
- * performance conscious manner. It trades a negligible overhead in general
726
- * case for a large speedup in case of mappings being added in order.
727
- */
728
- class MappingList$1 {
729
- constructor() {
730
- this._array = [];
731
- this._sorted = true;
732
- // Serves as infimum
733
- this._last = {generatedLine: -1, generatedColumn: 0};
734
- }
735
-
736
- /**
737
- * Iterate through internal items. This method takes the same arguments that
738
- * `Array.prototype.forEach` takes.
739
- *
740
- * NOTE: The order of the mappings is NOT guaranteed.
741
- */
742
- unsortedForEach(aCallback, aThisArg) {
743
- this._array.forEach(aCallback, aThisArg);
744
- }
745
-
746
- /**
747
- * Add the given source mapping.
748
- *
749
- * @param Object aMapping
750
- */
751
- add(aMapping) {
752
- if (generatedPositionAfter(this._last, aMapping)) {
753
- this._last = aMapping;
754
- this._array.push(aMapping);
755
- } else {
756
- this._sorted = false;
757
- this._array.push(aMapping);
758
- }
759
- }
760
-
761
- /**
762
- * Returns the flat, sorted array of mappings. The mappings are sorted by
763
- * generated position.
764
- *
765
- * WARNING: This method returns internal data without copying, for
766
- * performance. The return value must NOT be mutated, and should be treated as
767
- * an immutable borrow. If you want to take ownership, you must make your own
768
- * copy.
769
- */
770
- toArray() {
771
- if (!this._sorted) {
772
- this._array.sort(util$3.compareByGeneratedPositionsInflated);
773
- this._sorted = true;
774
- }
775
- return this._array;
776
- }
777
- }
778
-
779
- mappingList.MappingList = MappingList$1;
780
-
781
- /* -*- Mode: js; js-indent-level: 2; -*- */
782
-
783
- /*
784
- * Copyright 2011 Mozilla Foundation and contributors
785
- * Licensed under the New BSD license. See LICENSE or:
786
- * http://opensource.org/licenses/BSD-3-Clause
787
- */
788
-
789
- const base64VLQ = base64Vlq;
790
- const util$2 = util$4;
791
- const ArraySet$1 = arraySet.ArraySet;
792
- const MappingList = mappingList.MappingList;
793
-
794
- /**
795
- * An instance of the SourceMapGenerator represents a source map which is
796
- * being built incrementally. You may pass an object with the following
797
- * properties:
798
- *
799
- * - file: The filename of the generated source.
800
- * - sourceRoot: A root for all relative URLs in this source map.
801
- */
802
- class SourceMapGenerator$1 {
803
- constructor(aArgs) {
804
- if (!aArgs) {
805
- aArgs = {};
806
- }
807
- this._file = util$2.getArg(aArgs, "file", null);
808
- this._sourceRoot = util$2.getArg(aArgs, "sourceRoot", null);
809
- this._skipValidation = util$2.getArg(aArgs, "skipValidation", false);
810
- this._sources = new ArraySet$1();
811
- this._names = new ArraySet$1();
812
- this._mappings = new MappingList();
813
- this._sourcesContents = null;
814
- }
815
-
816
- /**
817
- * Creates a new SourceMapGenerator based on a SourceMapConsumer
818
- *
819
- * @param aSourceMapConsumer The SourceMap.
820
- */
821
- static fromSourceMap(aSourceMapConsumer) {
822
- const sourceRoot = aSourceMapConsumer.sourceRoot;
823
- const generator = new SourceMapGenerator$1({
824
- file: aSourceMapConsumer.file,
825
- sourceRoot
826
- });
827
- aSourceMapConsumer.eachMapping(function(mapping) {
828
- const newMapping = {
829
- generated: {
830
- line: mapping.generatedLine,
831
- column: mapping.generatedColumn
832
- }
833
- };
834
-
835
- if (mapping.source != null) {
836
- newMapping.source = mapping.source;
837
- if (sourceRoot != null) {
838
- newMapping.source = util$2.relative(sourceRoot, newMapping.source);
839
- }
840
-
841
- newMapping.original = {
842
- line: mapping.originalLine,
843
- column: mapping.originalColumn
844
- };
845
-
846
- if (mapping.name != null) {
847
- newMapping.name = mapping.name;
848
- }
849
- }
850
-
851
- generator.addMapping(newMapping);
852
- });
853
- aSourceMapConsumer.sources.forEach(function(sourceFile) {
854
- let sourceRelative = sourceFile;
855
- if (sourceRoot !== null) {
856
- sourceRelative = util$2.relative(sourceRoot, sourceFile);
857
- }
858
-
859
- if (!generator._sources.has(sourceRelative)) {
860
- generator._sources.add(sourceRelative);
861
- }
862
-
863
- const content = aSourceMapConsumer.sourceContentFor(sourceFile);
864
- if (content != null) {
865
- generator.setSourceContent(sourceFile, content);
866
- }
867
- });
868
- return generator;
869
- }
870
-
871
- /**
872
- * Add a single mapping from original source line and column to the generated
873
- * source's line and column for this source map being created. The mapping
874
- * object should have the following properties:
875
- *
876
- * - generated: An object with the generated line and column positions.
877
- * - original: An object with the original line and column positions.
878
- * - source: The original source file (relative to the sourceRoot).
879
- * - name: An optional original token name for this mapping.
880
- */
881
- addMapping(aArgs) {
882
- const generated = util$2.getArg(aArgs, "generated");
883
- const original = util$2.getArg(aArgs, "original", null);
884
- let source = util$2.getArg(aArgs, "source", null);
885
- let name = util$2.getArg(aArgs, "name", null);
886
-
887
- if (!this._skipValidation) {
888
- this._validateMapping(generated, original, source, name);
889
- }
890
-
891
- if (source != null) {
892
- source = String(source);
893
- if (!this._sources.has(source)) {
894
- this._sources.add(source);
895
- }
896
- }
897
-
898
- if (name != null) {
899
- name = String(name);
900
- if (!this._names.has(name)) {
901
- this._names.add(name);
902
- }
903
- }
904
-
905
- this._mappings.add({
906
- generatedLine: generated.line,
907
- generatedColumn: generated.column,
908
- originalLine: original != null && original.line,
909
- originalColumn: original != null && original.column,
910
- source,
911
- name
912
- });
913
- }
914
-
915
- /**
916
- * Set the source content for a source file.
917
- */
918
- setSourceContent(aSourceFile, aSourceContent) {
919
- let source = aSourceFile;
920
- if (this._sourceRoot != null) {
921
- source = util$2.relative(this._sourceRoot, source);
922
- }
923
-
924
- if (aSourceContent != null) {
925
- // Add the source content to the _sourcesContents map.
926
- // Create a new _sourcesContents map if the property is null.
927
- if (!this._sourcesContents) {
928
- this._sourcesContents = Object.create(null);
929
- }
930
- this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
931
- } else if (this._sourcesContents) {
932
- // Remove the source file from the _sourcesContents map.
933
- // If the _sourcesContents map is empty, set the property to null.
934
- delete this._sourcesContents[util$2.toSetString(source)];
935
- if (Object.keys(this._sourcesContents).length === 0) {
936
- this._sourcesContents = null;
937
- }
938
- }
939
- }
940
-
941
- /**
942
- * Applies the mappings of a sub-source-map for a specific source file to the
943
- * source map being generated. Each mapping to the supplied source file is
944
- * rewritten using the supplied source map. Note: The resolution for the
945
- * resulting mappings is the minimium of this map and the supplied map.
946
- *
947
- * @param aSourceMapConsumer The source map to be applied.
948
- * @param aSourceFile Optional. The filename of the source file.
949
- * If omitted, SourceMapConsumer's file property will be used.
950
- * @param aSourceMapPath Optional. The dirname of the path to the source map
951
- * to be applied. If relative, it is relative to the SourceMapConsumer.
952
- * This parameter is needed when the two source maps aren't in the same
953
- * directory, and the source map to be applied contains relative source
954
- * paths. If so, those relative source paths need to be rewritten
955
- * relative to the SourceMapGenerator.
956
- */
957
- applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
958
- let sourceFile = aSourceFile;
959
- // If aSourceFile is omitted, we will use the file property of the SourceMap
960
- if (aSourceFile == null) {
961
- if (aSourceMapConsumer.file == null) {
962
- throw new Error(
963
- "SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, " +
964
- 'or the source map\'s "file" property. Both were omitted.'
965
- );
966
- }
967
- sourceFile = aSourceMapConsumer.file;
968
- }
969
- const sourceRoot = this._sourceRoot;
970
- // Make "sourceFile" relative if an absolute Url is passed.
971
- if (sourceRoot != null) {
972
- sourceFile = util$2.relative(sourceRoot, sourceFile);
973
- }
974
- // Applying the SourceMap can add and remove items from the sources and
975
- // the names array.
976
- const newSources = this._mappings.toArray().length > 0
977
- ? new ArraySet$1()
978
- : this._sources;
979
- const newNames = new ArraySet$1();
980
-
981
- // Find mappings for the "sourceFile"
982
- this._mappings.unsortedForEach(function(mapping) {
983
- if (mapping.source === sourceFile && mapping.originalLine != null) {
984
- // Check if it can be mapped by the source map, then update the mapping.
985
- const original = aSourceMapConsumer.originalPositionFor({
986
- line: mapping.originalLine,
987
- column: mapping.originalColumn
988
- });
989
- if (original.source != null) {
990
- // Copy mapping
991
- mapping.source = original.source;
992
- if (aSourceMapPath != null) {
993
- mapping.source = util$2.join(aSourceMapPath, mapping.source);
994
- }
995
- if (sourceRoot != null) {
996
- mapping.source = util$2.relative(sourceRoot, mapping.source);
997
- }
998
- mapping.originalLine = original.line;
999
- mapping.originalColumn = original.column;
1000
- if (original.name != null) {
1001
- mapping.name = original.name;
1002
- }
1003
- }
1004
- }
1005
-
1006
- const source = mapping.source;
1007
- if (source != null && !newSources.has(source)) {
1008
- newSources.add(source);
1009
- }
1010
-
1011
- const name = mapping.name;
1012
- if (name != null && !newNames.has(name)) {
1013
- newNames.add(name);
1014
- }
1015
-
1016
- }, this);
1017
- this._sources = newSources;
1018
- this._names = newNames;
1019
-
1020
- // Copy sourcesContents of applied map.
1021
- aSourceMapConsumer.sources.forEach(function(srcFile) {
1022
- const content = aSourceMapConsumer.sourceContentFor(srcFile);
1023
- if (content != null) {
1024
- if (aSourceMapPath != null) {
1025
- srcFile = util$2.join(aSourceMapPath, srcFile);
1026
- }
1027
- if (sourceRoot != null) {
1028
- srcFile = util$2.relative(sourceRoot, srcFile);
1029
- }
1030
- this.setSourceContent(srcFile, content);
1031
- }
1032
- }, this);
1033
- }
1034
-
1035
- /**
1036
- * A mapping can have one of the three levels of data:
1037
- *
1038
- * 1. Just the generated position.
1039
- * 2. The Generated position, original position, and original source.
1040
- * 3. Generated and original position, original source, as well as a name
1041
- * token.
1042
- *
1043
- * To maintain consistency, we validate that any new mapping being added falls
1044
- * in to one of these categories.
1045
- */
1046
- _validateMapping(aGenerated, aOriginal, aSource, aName) {
1047
- // When aOriginal is truthy but has empty values for .line and .column,
1048
- // it is most likely a programmer error. In this case we throw a very
1049
- // specific error message to try to guide them the right way.
1050
- // For example: https://github.com/Polymer/polymer-bundler/pull/519
1051
- if (aOriginal && typeof aOriginal.line !== "number" && typeof aOriginal.column !== "number") {
1052
- throw new Error(
1053
- "original.line and original.column are not numbers -- you probably meant to omit " +
1054
- "the original mapping entirely and only map the generated position. If so, pass " +
1055
- "null for the original mapping instead of an object with empty or null values."
1056
- );
1057
- }
1058
-
1059
- if (aGenerated && "line" in aGenerated && "column" in aGenerated
1060
- && aGenerated.line > 0 && aGenerated.column >= 0
1061
- && !aOriginal && !aSource && !aName) ; else if (aGenerated && "line" in aGenerated && "column" in aGenerated
1062
- && aOriginal && "line" in aOriginal && "column" in aOriginal
1063
- && aGenerated.line > 0 && aGenerated.column >= 0
1064
- && aOriginal.line > 0 && aOriginal.column >= 0
1065
- && aSource) ; else {
1066
- throw new Error("Invalid mapping: " + JSON.stringify({
1067
- generated: aGenerated,
1068
- source: aSource,
1069
- original: aOriginal,
1070
- name: aName
1071
- }));
1072
- }
1073
- }
1074
-
1075
- /**
1076
- * Serialize the accumulated mappings in to the stream of base 64 VLQs
1077
- * specified by the source map format.
1078
- */
1079
- _serializeMappings() {
1080
- let previousGeneratedColumn = 0;
1081
- let previousGeneratedLine = 1;
1082
- let previousOriginalColumn = 0;
1083
- let previousOriginalLine = 0;
1084
- let previousName = 0;
1085
- let previousSource = 0;
1086
- let result = "";
1087
- let next;
1088
- let mapping;
1089
- let nameIdx;
1090
- let sourceIdx;
1091
-
1092
- const mappings = this._mappings.toArray();
1093
- for (let i = 0, len = mappings.length; i < len; i++) {
1094
- mapping = mappings[i];
1095
- next = "";
1096
-
1097
- if (mapping.generatedLine !== previousGeneratedLine) {
1098
- previousGeneratedColumn = 0;
1099
- while (mapping.generatedLine !== previousGeneratedLine) {
1100
- next += ";";
1101
- previousGeneratedLine++;
1102
- }
1103
- } else if (i > 0) {
1104
- if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
1105
- continue;
1106
- }
1107
- next += ",";
1108
- }
1109
-
1110
- next += base64VLQ.encode(mapping.generatedColumn
1111
- - previousGeneratedColumn);
1112
- previousGeneratedColumn = mapping.generatedColumn;
1113
-
1114
- if (mapping.source != null) {
1115
- sourceIdx = this._sources.indexOf(mapping.source);
1116
- next += base64VLQ.encode(sourceIdx - previousSource);
1117
- previousSource = sourceIdx;
1118
-
1119
- // lines are stored 0-based in SourceMap spec version 3
1120
- next += base64VLQ.encode(mapping.originalLine - 1
1121
- - previousOriginalLine);
1122
- previousOriginalLine = mapping.originalLine - 1;
1123
-
1124
- next += base64VLQ.encode(mapping.originalColumn
1125
- - previousOriginalColumn);
1126
- previousOriginalColumn = mapping.originalColumn;
1127
-
1128
- if (mapping.name != null) {
1129
- nameIdx = this._names.indexOf(mapping.name);
1130
- next += base64VLQ.encode(nameIdx - previousName);
1131
- previousName = nameIdx;
1132
- }
1133
- }
1134
-
1135
- result += next;
1136
- }
1137
-
1138
- return result;
1139
- }
1140
-
1141
- _generateSourcesContent(aSources, aSourceRoot) {
1142
- return aSources.map(function(source) {
1143
- if (!this._sourcesContents) {
1144
- return null;
1145
- }
1146
- if (aSourceRoot != null) {
1147
- source = util$2.relative(aSourceRoot, source);
1148
- }
1149
- const key = util$2.toSetString(source);
1150
- return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
1151
- ? this._sourcesContents[key]
1152
- : null;
1153
- }, this);
1154
- }
1155
-
1156
- /**
1157
- * Externalize the source map.
1158
- */
1159
- toJSON() {
1160
- const map = {
1161
- version: this._version,
1162
- sources: this._sources.toArray(),
1163
- names: this._names.toArray(),
1164
- mappings: this._serializeMappings()
1165
- };
1166
- if (this._file != null) {
1167
- map.file = this._file;
1168
- }
1169
- if (this._sourceRoot != null) {
1170
- map.sourceRoot = this._sourceRoot;
1171
- }
1172
- if (this._sourcesContents) {
1173
- map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
1174
- }
1175
-
1176
- return map;
1177
- }
1178
-
1179
- /**
1180
- * Render the source map being generated to a string.
1181
- */
1182
- toString() {
1183
- return JSON.stringify(this.toJSON());
1184
- }
1185
- }
1186
-
1187
- SourceMapGenerator$1.prototype._version = 3;
1188
- sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$1;
1189
-
1190
- var sourceMapConsumer = {};
1191
-
1192
- var binarySearch$1 = {};
1193
-
1194
- /* -*- Mode: js; js-indent-level: 2; -*- */
1195
-
1196
- (function (exports) {
1197
- /*
1198
- * Copyright 2011 Mozilla Foundation and contributors
1199
- * Licensed under the New BSD license. See LICENSE or:
1200
- * http://opensource.org/licenses/BSD-3-Clause
1201
- */
1202
-
1203
- exports.GREATEST_LOWER_BOUND = 1;
1204
- exports.LEAST_UPPER_BOUND = 2;
1205
-
1206
- /**
1207
- * Recursive implementation of binary search.
1208
- *
1209
- * @param aLow Indices here and lower do not contain the needle.
1210
- * @param aHigh Indices here and higher do not contain the needle.
1211
- * @param aNeedle The element being searched for.
1212
- * @param aHaystack The non-empty array being searched.
1213
- * @param aCompare Function which takes two elements and returns -1, 0, or 1.
1214
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
1215
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
1216
- * closest element that is smaller than or greater than the one we are
1217
- * searching for, respectively, if the exact element cannot be found.
1218
- */
1219
- function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
1220
- // This function terminates when one of the following is true:
1221
- //
1222
- // 1. We find the exact element we are looking for.
1223
- //
1224
- // 2. We did not find the exact element, but we can return the index of
1225
- // the next-closest element.
1226
- //
1227
- // 3. We did not find the exact element, and there is no next-closest
1228
- // element than the one we are searching for, so we return -1.
1229
- const mid = Math.floor((aHigh - aLow) / 2) + aLow;
1230
- const cmp = aCompare(aNeedle, aHaystack[mid], true);
1231
- if (cmp === 0) {
1232
- // Found the element we are looking for.
1233
- return mid;
1234
- } else if (cmp > 0) {
1235
- // Our needle is greater than aHaystack[mid].
1236
- if (aHigh - mid > 1) {
1237
- // The element is in the upper half.
1238
- return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
1239
- }
1240
-
1241
- // The exact needle element was not found in this haystack. Determine if
1242
- // we are in termination case (3) or (2) and return the appropriate thing.
1243
- if (aBias == exports.LEAST_UPPER_BOUND) {
1244
- return aHigh < aHaystack.length ? aHigh : -1;
1245
- }
1246
- return mid;
1247
- }
1248
-
1249
- // Our needle is less than aHaystack[mid].
1250
- if (mid - aLow > 1) {
1251
- // The element is in the lower half.
1252
- return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
1253
- }
1254
-
1255
- // we are in termination case (3) or (2) and return the appropriate thing.
1256
- if (aBias == exports.LEAST_UPPER_BOUND) {
1257
- return mid;
1258
- }
1259
- return aLow < 0 ? -1 : aLow;
1260
- }
1261
-
1262
- /**
1263
- * This is an implementation of binary search which will always try and return
1264
- * the index of the closest element if there is no exact hit. This is because
1265
- * mappings between original and generated line/col pairs are single points,
1266
- * and there is an implicit region between each of them, so a miss just means
1267
- * that you aren't on the very start of a region.
1268
- *
1269
- * @param aNeedle The element you are looking for.
1270
- * @param aHaystack The array that is being searched.
1271
- * @param aCompare A function which takes the needle and an element in the
1272
- * array and returns -1, 0, or 1 depending on whether the needle is less
1273
- * than, equal to, or greater than the element, respectively.
1274
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
1275
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
1276
- * closest element that is smaller than or greater than the one we are
1277
- * searching for, respectively, if the exact element cannot be found.
1278
- * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
1279
- */
1280
- exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
1281
- if (aHaystack.length === 0) {
1282
- return -1;
1283
- }
1284
-
1285
- let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
1286
- aCompare, aBias || exports.GREATEST_LOWER_BOUND);
1287
- if (index < 0) {
1288
- return -1;
1289
- }
1290
-
1291
- // We have found either the exact element, or the next-closest element than
1292
- // the one we are searching for. However, there may be more than one such
1293
- // element. Make sure we always return the smallest of these.
1294
- while (index - 1 >= 0) {
1295
- if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
1296
- break;
1297
- }
1298
- --index;
1299
- }
1300
-
1301
- return index;
1302
- };
1303
- }(binarySearch$1));
1304
-
1305
- var readWasm$2 = {exports: {}};
1306
-
1307
- // Note: This file is replaced with "read-wasm-browser.js" when this module is
1308
- // bundled with a packager that takes package.json#browser fields into account.
1309
-
1310
- const fs = require$$0__default$1;
1311
- const path = require$$1__default;
1312
-
1313
- readWasm$2.exports = function readWasm() {
1314
- return new Promise((resolve, reject) => {
1315
- const wasmPath = path.join(__dirname, "mappings.wasm");
1316
- fs.readFile(wasmPath, null, (error, data) => {
1317
- if (error) {
1318
- reject(error);
1319
- return;
1320
- }
1321
-
1322
- resolve(data.buffer);
1323
- });
1324
- });
1325
- };
1326
-
1327
- readWasm$2.exports.initialize = _ => {
1328
- console.debug("SourceMapConsumer.initialize is a no-op when running in node.js");
1329
- };
1330
-
1331
- const readWasm$1 = readWasm$2.exports;
1332
-
1333
- /**
1334
- * Provide the JIT with a nice shape / hidden class.
1335
- */
1336
- function Mapping() {
1337
- this.generatedLine = 0;
1338
- this.generatedColumn = 0;
1339
- this.lastGeneratedColumn = null;
1340
- this.source = null;
1341
- this.originalLine = null;
1342
- this.originalColumn = null;
1343
- this.name = null;
1344
- }
1345
-
1346
- let cachedWasm = null;
1347
-
1348
- var wasm$1 = function wasm() {
1349
- if (cachedWasm) {
1350
- return cachedWasm;
1351
- }
1352
-
1353
- const callbackStack = [];
1354
-
1355
- cachedWasm = readWasm$1().then(buffer => {
1356
- return WebAssembly.instantiate(buffer, {
1357
- env: {
1358
- mapping_callback(
1359
- generatedLine,
1360
- generatedColumn,
1361
-
1362
- hasLastGeneratedColumn,
1363
- lastGeneratedColumn,
1364
-
1365
- hasOriginal,
1366
- source,
1367
- originalLine,
1368
- originalColumn,
1369
-
1370
- hasName,
1371
- name
1372
- ) {
1373
- const mapping = new Mapping();
1374
- // JS uses 1-based line numbers, wasm uses 0-based.
1375
- mapping.generatedLine = generatedLine + 1;
1376
- mapping.generatedColumn = generatedColumn;
1377
-
1378
- if (hasLastGeneratedColumn) {
1379
- // JS uses inclusive last generated column, wasm uses exclusive.
1380
- mapping.lastGeneratedColumn = lastGeneratedColumn - 1;
9
+ (function (module, exports) {
10
+ (function (global, factory) {
11
+ factory(exports) ;
12
+ })(commonjsGlobal, (function (exports) {
13
+ const comma = ','.charCodeAt(0);
14
+ const semicolon = ';'.charCodeAt(0);
15
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
16
+ const intToChar = new Uint8Array(64); // 64 possible chars.
17
+ const charToInteger = new Uint8Array(128); // z is 122 in ASCII
18
+ for (let i = 0; i < chars.length; i++) {
19
+ const c = chars.charCodeAt(i);
20
+ charToInteger[c] = i;
21
+ intToChar[i] = c;
22
+ }
23
+ // Provide a fallback for older environments.
24
+ const td = typeof TextDecoder !== 'undefined'
25
+ ? new TextDecoder()
26
+ : typeof Buffer !== 'undefined'
27
+ ? {
28
+ decode(buf) {
29
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
30
+ return out.toString();
31
+ },
1381
32
  }
1382
-
1383
- if (hasOriginal) {
1384
- mapping.source = source;
1385
- // JS uses 1-based line numbers, wasm uses 0-based.
1386
- mapping.originalLine = originalLine + 1;
1387
- mapping.originalColumn = originalColumn;
1388
-
1389
- if (hasName) {
1390
- mapping.name = name;
1391
- }
33
+ : {
34
+ decode(buf) {
35
+ let out = '';
36
+ for (let i = 0; i < buf.length; i++) {
37
+ out += String.fromCharCode(buf[i]);
38
+ }
39
+ return out;
40
+ },
41
+ };
42
+ function decode(mappings) {
43
+ const state = new Int32Array(5);
44
+ const decoded = [];
45
+ let line = [];
46
+ let sorted = true;
47
+ let lastCol = 0;
48
+ for (let i = 0; i < mappings.length;) {
49
+ const c = mappings.charCodeAt(i);
50
+ if (c === comma) {
51
+ i++;
52
+ }
53
+ else if (c === semicolon) {
54
+ state[0] = lastCol = 0;
55
+ if (!sorted)
56
+ sort(line);
57
+ sorted = true;
58
+ decoded.push(line);
59
+ line = [];
60
+ i++;
61
+ }
62
+ else {
63
+ i = decodeInteger(mappings, i, state, 0); // generatedCodeColumn
64
+ const col = state[0];
65
+ if (col < lastCol)
66
+ sorted = false;
67
+ lastCol = col;
68
+ if (!hasMoreSegments(mappings, i)) {
69
+ line.push([col]);
70
+ continue;
71
+ }
72
+ i = decodeInteger(mappings, i, state, 1); // sourceFileIndex
73
+ i = decodeInteger(mappings, i, state, 2); // sourceCodeLine
74
+ i = decodeInteger(mappings, i, state, 3); // sourceCodeColumn
75
+ if (!hasMoreSegments(mappings, i)) {
76
+ line.push([col, state[1], state[2], state[3]]);
77
+ continue;
78
+ }
79
+ i = decodeInteger(mappings, i, state, 4); // nameIndex
80
+ line.push([col, state[1], state[2], state[3], state[4]]);
1392
81
  }
1393
-
1394
- callbackStack[callbackStack.length - 1](mapping);
1395
- },
1396
-
1397
- start_all_generated_locations_for() { console.time("all_generated_locations_for"); },
1398
- end_all_generated_locations_for() { console.timeEnd("all_generated_locations_for"); },
1399
-
1400
- start_compute_column_spans() { console.time("compute_column_spans"); },
1401
- end_compute_column_spans() { console.timeEnd("compute_column_spans"); },
1402
-
1403
- start_generated_location_for() { console.time("generated_location_for"); },
1404
- end_generated_location_for() { console.timeEnd("generated_location_for"); },
1405
-
1406
- start_original_location_for() { console.time("original_location_for"); },
1407
- end_original_location_for() { console.timeEnd("original_location_for"); },
1408
-
1409
- start_parse_mappings() { console.time("parse_mappings"); },
1410
- end_parse_mappings() { console.timeEnd("parse_mappings"); },
1411
-
1412
- start_sort_by_generated_location() { console.time("sort_by_generated_location"); },
1413
- end_sort_by_generated_location() { console.timeEnd("sort_by_generated_location"); },
1414
-
1415
- start_sort_by_original_location() { console.time("sort_by_original_location"); },
1416
- end_sort_by_original_location() { console.timeEnd("sort_by_original_location"); },
1417
- }
1418
- });
1419
- }).then(Wasm => {
1420
- return {
1421
- exports: Wasm.instance.exports,
1422
- withMappingCallback: (mappingCallback, f) => {
1423
- callbackStack.push(mappingCallback);
1424
- try {
1425
- f();
1426
- } finally {
1427
- callbackStack.pop();
1428
- }
1429
- }
1430
- };
1431
- }).then(null, e => {
1432
- cachedWasm = null;
1433
- throw e;
1434
- });
1435
-
1436
- return cachedWasm;
1437
- };
1438
-
1439
- /* -*- Mode: js; js-indent-level: 2; -*- */
1440
-
1441
- /*
1442
- * Copyright 2011 Mozilla Foundation and contributors
1443
- * Licensed under the New BSD license. See LICENSE or:
1444
- * http://opensource.org/licenses/BSD-3-Clause
1445
- */
1446
-
1447
- const util$1 = util$4;
1448
- const binarySearch = binarySearch$1;
1449
- const ArraySet = arraySet.ArraySet;
1450
- const readWasm = readWasm$2.exports;
1451
- const wasm = wasm$1;
1452
-
1453
- const INTERNAL = Symbol("smcInternal");
1454
-
1455
- class SourceMapConsumer {
1456
- constructor(aSourceMap, aSourceMapURL) {
1457
- // If the constructor was called by super(), just return Promise<this>.
1458
- // Yes, this is a hack to retain the pre-existing API of the base-class
1459
- // constructor also being an async factory function.
1460
- if (aSourceMap == INTERNAL) {
1461
- return Promise.resolve(this);
1462
- }
1463
-
1464
- return _factory(aSourceMap, aSourceMapURL);
1465
- }
1466
-
1467
- static initialize(opts) {
1468
- readWasm.initialize(opts["lib/mappings.wasm"]);
1469
- }
1470
-
1471
- static fromSourceMap(aSourceMap, aSourceMapURL) {
1472
- return _factoryBSM(aSourceMap, aSourceMapURL);
1473
- }
1474
-
1475
- /**
1476
- * Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
1477
- * (see the `SourceMapConsumer` constructor for details. Then, invoke the `async
1478
- * function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
1479
- * for `f` to complete, call `destroy` on the consumer, and return `f`'s return
1480
- * value.
1481
- *
1482
- * You must not use the consumer after `f` completes!
1483
- *
1484
- * By using `with`, you do not have to remember to manually call `destroy` on
1485
- * the consumer, since it will be called automatically once `f` completes.
1486
- *
1487
- * ```js
1488
- * const xSquared = await SourceMapConsumer.with(
1489
- * myRawSourceMap,
1490
- * null,
1491
- * async function (consumer) {
1492
- * // Use `consumer` inside here and don't worry about remembering
1493
- * // to call `destroy`.
1494
- *
1495
- * const x = await whatever(consumer);
1496
- * return x * x;
1497
- * }
1498
- * );
1499
- *
1500
- * // You may not use that `consumer` anymore out here; it has
1501
- * // been destroyed. But you can use `xSquared`.
1502
- * console.log(xSquared);
1503
- * ```
1504
- */
1505
- static async with(rawSourceMap, sourceMapUrl, f) {
1506
- const consumer = await new SourceMapConsumer(rawSourceMap, sourceMapUrl);
1507
- try {
1508
- return await f(consumer);
1509
- } finally {
1510
- consumer.destroy();
1511
- }
1512
- }
1513
-
1514
- /**
1515
- * Iterate over each mapping between an original source/line/column and a
1516
- * generated line/column in this source map.
1517
- *
1518
- * @param Function aCallback
1519
- * The function that is called with each mapping.
1520
- * @param Object aContext
1521
- * Optional. If specified, this object will be the value of `this` every
1522
- * time that `aCallback` is called.
1523
- * @param aOrder
1524
- * Either `SourceMapConsumer.GENERATED_ORDER` or
1525
- * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
1526
- * iterate over the mappings sorted by the generated file's line/column
1527
- * order or the original's source/line/column order, respectively. Defaults to
1528
- * `SourceMapConsumer.GENERATED_ORDER`.
1529
- */
1530
- eachMapping(aCallback, aContext, aOrder) {
1531
- throw new Error("Subclasses must implement eachMapping");
1532
- }
1533
-
1534
- /**
1535
- * Returns all generated line and column information for the original source,
1536
- * line, and column provided. If no column is provided, returns all mappings
1537
- * corresponding to a either the line we are searching for or the next
1538
- * closest line that has any mappings. Otherwise, returns all mappings
1539
- * corresponding to the given line and either the column we are searching for
1540
- * or the next closest column that has any offsets.
1541
- *
1542
- * The only argument is an object with the following properties:
1543
- *
1544
- * - source: The filename of the original source.
1545
- * - line: The line number in the original source. The line number is 1-based.
1546
- * - column: Optional. the column number in the original source.
1547
- * The column number is 0-based.
1548
- *
1549
- * and an array of objects is returned, each with the following properties:
1550
- *
1551
- * - line: The line number in the generated source, or null. The
1552
- * line number is 1-based.
1553
- * - column: The column number in the generated source, or null.
1554
- * The column number is 0-based.
1555
- */
1556
- allGeneratedPositionsFor(aArgs) {
1557
- throw new Error("Subclasses must implement allGeneratedPositionsFor");
1558
- }
1559
-
1560
- destroy() {
1561
- throw new Error("Subclasses must implement destroy");
1562
- }
1563
- }
1564
-
1565
- /**
1566
- * The version of the source mapping spec that we are consuming.
1567
- */
1568
- SourceMapConsumer.prototype._version = 3;
1569
- SourceMapConsumer.GENERATED_ORDER = 1;
1570
- SourceMapConsumer.ORIGINAL_ORDER = 2;
1571
-
1572
- SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
1573
- SourceMapConsumer.LEAST_UPPER_BOUND = 2;
1574
-
1575
- sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
1576
-
1577
- /**
1578
- * A BasicSourceMapConsumer instance represents a parsed source map which we can
1579
- * query for information about the original file positions by giving it a file
1580
- * position in the generated source.
1581
- *
1582
- * The first parameter is the raw source map (either as a JSON string, or
1583
- * already parsed to an object). According to the spec, source maps have the
1584
- * following attributes:
1585
- *
1586
- * - version: Which version of the source map spec this map is following.
1587
- * - sources: An array of URLs to the original source files.
1588
- * - names: An array of identifiers which can be referenced by individual mappings.
1589
- * - sourceRoot: Optional. The URL root from which all sources are relative.
1590
- * - sourcesContent: Optional. An array of contents of the original source files.
1591
- * - mappings: A string of base64 VLQs which contain the actual mappings.
1592
- * - file: Optional. The generated file this source map is associated with.
1593
- *
1594
- * Here is an example source map, taken from the source map spec[0]:
1595
- *
1596
- * {
1597
- * version : 3,
1598
- * file: "out.js",
1599
- * sourceRoot : "",
1600
- * sources: ["foo.js", "bar.js"],
1601
- * names: ["src", "maps", "are", "fun"],
1602
- * mappings: "AA,AB;;ABCDE;"
1603
- * }
1604
- *
1605
- * The second parameter, if given, is a string whose value is the URL
1606
- * at which the source map was found. This URL is used to compute the
1607
- * sources array.
1608
- *
1609
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
1610
- */
1611
- class BasicSourceMapConsumer extends SourceMapConsumer {
1612
- constructor(aSourceMap, aSourceMapURL) {
1613
- return super(INTERNAL).then(that => {
1614
- let sourceMap = aSourceMap;
1615
- if (typeof aSourceMap === "string") {
1616
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
1617
- }
1618
-
1619
- const version = util$1.getArg(sourceMap, "version");
1620
- const sources = util$1.getArg(sourceMap, "sources").map(String);
1621
- // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
1622
- // requires the array) to play nice here.
1623
- const names = util$1.getArg(sourceMap, "names", []);
1624
- const sourceRoot = util$1.getArg(sourceMap, "sourceRoot", null);
1625
- const sourcesContent = util$1.getArg(sourceMap, "sourcesContent", null);
1626
- const mappings = util$1.getArg(sourceMap, "mappings");
1627
- const file = util$1.getArg(sourceMap, "file", null);
1628
-
1629
- // Once again, Sass deviates from the spec and supplies the version as a
1630
- // string rather than a number, so we use loose equality checking here.
1631
- if (version != that._version) {
1632
- throw new Error("Unsupported version: " + version);
1633
- }
1634
-
1635
- that._sourceLookupCache = new Map();
1636
-
1637
- // Pass `true` below to allow duplicate names and sources. While source maps
1638
- // are intended to be compressed and deduplicated, the TypeScript compiler
1639
- // sometimes generates source maps with duplicates in them. See Github issue
1640
- // #72 and bugzil.la/889492.
1641
- that._names = ArraySet.fromArray(names.map(String), true);
1642
- that._sources = ArraySet.fromArray(sources, true);
1643
-
1644
- that._absoluteSources = ArraySet.fromArray(that._sources.toArray().map(function(s) {
1645
- return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
1646
- }), true);
1647
-
1648
- that.sourceRoot = sourceRoot;
1649
- that.sourcesContent = sourcesContent;
1650
- that._mappings = mappings;
1651
- that._sourceMapURL = aSourceMapURL;
1652
- that.file = file;
1653
-
1654
- that._computedColumnSpans = false;
1655
- that._mappingsPtr = 0;
1656
- that._wasm = null;
1657
-
1658
- return wasm().then(w => {
1659
- that._wasm = w;
1660
- return that;
1661
- });
1662
- });
1663
- }
1664
-
1665
- /**
1666
- * Utility function to find the index of a source. Returns -1 if not
1667
- * found.
1668
- */
1669
- _findSourceIndex(aSource) {
1670
- // In the most common usecases, we'll be constantly looking up the index for the same source
1671
- // files, so we cache the index lookup to avoid constantly recomputing the full URLs.
1672
- const cachedIndex = this._sourceLookupCache.get(aSource);
1673
- if (typeof cachedIndex === "number") {
1674
- return cachedIndex;
1675
- }
1676
-
1677
- // Treat the source as map-relative overall by default.
1678
- const sourceAsMapRelative = util$1.computeSourceURL(null, aSource, this._sourceMapURL);
1679
- if (this._absoluteSources.has(sourceAsMapRelative)) {
1680
- const index = this._absoluteSources.indexOf(sourceAsMapRelative);
1681
- this._sourceLookupCache.set(aSource, index);
1682
- return index;
1683
- }
1684
-
1685
- // Fall back to treating the source as sourceRoot-relative.
1686
- const sourceAsSourceRootRelative = util$1.computeSourceURL(this.sourceRoot, aSource, this._sourceMapURL);
1687
- if (this._absoluteSources.has(sourceAsSourceRootRelative)) {
1688
- const index = this._absoluteSources.indexOf(sourceAsSourceRootRelative);
1689
- this._sourceLookupCache.set(aSource, index);
1690
- return index;
1691
- }
1692
-
1693
- // To avoid this cache growing forever, we do not cache lookup misses.
1694
- return -1;
1695
- }
1696
-
1697
- /**
1698
- * Create a BasicSourceMapConsumer from a SourceMapGenerator.
1699
- *
1700
- * @param SourceMapGenerator aSourceMap
1701
- * The source map that will be consumed.
1702
- * @param String aSourceMapURL
1703
- * The URL at which the source map can be found (optional)
1704
- * @returns BasicSourceMapConsumer
1705
- */
1706
- static fromSourceMap(aSourceMap, aSourceMapURL) {
1707
- return new BasicSourceMapConsumer(aSourceMap.toString());
1708
- }
1709
-
1710
- get sources() {
1711
- return this._absoluteSources.toArray();
1712
- }
1713
-
1714
- _getMappingsPtr() {
1715
- if (this._mappingsPtr === 0) {
1716
- this._parseMappings();
1717
- }
1718
-
1719
- return this._mappingsPtr;
1720
- }
1721
-
1722
- /**
1723
- * Parse the mappings in a string in to a data structure which we can easily
1724
- * query (the ordered arrays in the `this.__generatedMappings` and
1725
- * `this.__originalMappings` properties).
1726
- */
1727
- _parseMappings() {
1728
- const aStr = this._mappings;
1729
- const size = aStr.length;
1730
-
1731
- const mappingsBufPtr = this._wasm.exports.allocate_mappings(size);
1732
- const mappingsBuf = new Uint8Array(this._wasm.exports.memory.buffer, mappingsBufPtr, size);
1733
- for (let i = 0; i < size; i++) {
1734
- mappingsBuf[i] = aStr.charCodeAt(i);
1735
- }
1736
-
1737
- const mappingsPtr = this._wasm.exports.parse_mappings(mappingsBufPtr);
1738
-
1739
- if (!mappingsPtr) {
1740
- const error = this._wasm.exports.get_last_error();
1741
- let msg = `Error parsing mappings (code ${error}): `;
1742
-
1743
- // XXX: keep these error codes in sync with `fitzgen/source-map-mappings`.
1744
- switch (error) {
1745
- case 1:
1746
- msg += "the mappings contained a negative line, column, source index, or name index";
1747
- break;
1748
- case 2:
1749
- msg += "the mappings contained a number larger than 2**32";
1750
- break;
1751
- case 3:
1752
- msg += "reached EOF while in the middle of parsing a VLQ";
1753
- break;
1754
- case 4:
1755
- msg += "invalid base 64 character while parsing a VLQ";
1756
- break;
1757
- default:
1758
- msg += "unknown error code";
1759
- break;
1760
- }
1761
-
1762
- throw new Error(msg);
1763
- }
1764
-
1765
- this._mappingsPtr = mappingsPtr;
1766
- }
1767
-
1768
- eachMapping(aCallback, aContext, aOrder) {
1769
- const context = aContext || null;
1770
- const order = aOrder || SourceMapConsumer.GENERATED_ORDER;
1771
-
1772
- this._wasm.withMappingCallback(
1773
- mapping => {
1774
- if (mapping.source !== null) {
1775
- mapping.source = this._absoluteSources.at(mapping.source);
1776
-
1777
- if (mapping.name !== null) {
1778
- mapping.name = this._names.at(mapping.name);
1779
- }
1780
- }
1781
- if (this._computedColumnSpans && mapping.lastGeneratedColumn === null) {
1782
- mapping.lastGeneratedColumn = Infinity;
1783
- }
1784
-
1785
- aCallback.call(context, mapping);
1786
- },
1787
- () => {
1788
- switch (order) {
1789
- case SourceMapConsumer.GENERATED_ORDER:
1790
- this._wasm.exports.by_generated_location(this._getMappingsPtr());
1791
- break;
1792
- case SourceMapConsumer.ORIGINAL_ORDER:
1793
- this._wasm.exports.by_original_location(this._getMappingsPtr());
1794
- break;
1795
- default:
1796
- throw new Error("Unknown order of iteration.");
1797
82
  }
1798
- }
1799
- );
1800
- }
1801
-
1802
- allGeneratedPositionsFor(aArgs) {
1803
- let source = util$1.getArg(aArgs, "source");
1804
- const originalLine = util$1.getArg(aArgs, "line");
1805
- const originalColumn = aArgs.column || 0;
1806
-
1807
- source = this._findSourceIndex(source);
1808
- if (source < 0) {
1809
- return [];
83
+ if (!sorted)
84
+ sort(line);
85
+ decoded.push(line);
86
+ return decoded;
1810
87
  }
1811
-
1812
- if (originalLine < 1) {
1813
- throw new Error("Line numbers must be >= 1");
88
+ function decodeInteger(mappings, pos, state, j) {
89
+ let value = 0;
90
+ let shift = 0;
91
+ let integer = 0;
92
+ do {
93
+ const c = mappings.charCodeAt(pos++);
94
+ integer = charToInteger[c];
95
+ value |= (integer & 31) << shift;
96
+ shift += 5;
97
+ } while (integer & 32);
98
+ const shouldNegate = value & 1;
99
+ value >>>= 1;
100
+ if (shouldNegate) {
101
+ value = -0x80000000 | -value;
102
+ }
103
+ state[j] += value;
104
+ return pos;
1814
105
  }
1815
-
1816
- if (originalColumn < 0) {
1817
- throw new Error("Column numbers must be >= 0");
106
+ function hasMoreSegments(mappings, i) {
107
+ if (i >= mappings.length)
108
+ return false;
109
+ const c = mappings.charCodeAt(i);
110
+ if (c === comma || c === semicolon)
111
+ return false;
112
+ return true;
1818
113
  }
1819
-
1820
- const mappings = [];
1821
-
1822
- this._wasm.withMappingCallback(
1823
- m => {
1824
- let lastColumn = m.lastGeneratedColumn;
1825
- if (this._computedColumnSpans && lastColumn === null) {
1826
- lastColumn = Infinity;
114
+ function sort(line) {
115
+ line.sort(sortComparator$1);
116
+ }
117
+ function sortComparator$1(a, b) {
118
+ return a[0] - b[0];
119
+ }
120
+ function encode(decoded) {
121
+ const state = new Int32Array(5);
122
+ let buf = new Uint8Array(1024);
123
+ let pos = 0;
124
+ for (let i = 0; i < decoded.length; i++) {
125
+ const line = decoded[i];
126
+ if (i > 0) {
127
+ buf = reserve(buf, pos, 1);
128
+ buf[pos++] = semicolon;
129
+ }
130
+ if (line.length === 0)
131
+ continue;
132
+ state[0] = 0;
133
+ for (let j = 0; j < line.length; j++) {
134
+ const segment = line[j];
135
+ // We can push up to 5 ints, each int can take at most 7 chars, and we
136
+ // may push a comma.
137
+ buf = reserve(buf, pos, 36);
138
+ if (j > 0)
139
+ buf[pos++] = comma;
140
+ pos = encodeInteger(buf, pos, state, segment, 0); // generatedCodeColumn
141
+ if (segment.length === 1)
142
+ continue;
143
+ pos = encodeInteger(buf, pos, state, segment, 1); // sourceFileIndex
144
+ pos = encodeInteger(buf, pos, state, segment, 2); // sourceCodeLine
145
+ pos = encodeInteger(buf, pos, state, segment, 3); // sourceCodeColumn
146
+ if (segment.length === 4)
147
+ continue;
148
+ pos = encodeInteger(buf, pos, state, segment, 4); // nameIndex
149
+ }
1827
150
  }
1828
- mappings.push({
1829
- line: m.generatedLine,
1830
- column: m.generatedColumn,
1831
- lastColumn,
1832
- });
1833
- }, () => {
1834
- this._wasm.exports.all_generated_locations_for(
1835
- this._getMappingsPtr(),
1836
- source,
1837
- originalLine - 1,
1838
- "column" in aArgs,
1839
- originalColumn
1840
- );
1841
- }
1842
- );
1843
-
1844
- return mappings;
1845
- }
1846
-
1847
- destroy() {
1848
- if (this._mappingsPtr !== 0) {
1849
- this._wasm.exports.free_mappings(this._mappingsPtr);
1850
- this._mappingsPtr = 0;
1851
- }
1852
- }
1853
-
1854
- /**
1855
- * Compute the last column for each generated mapping. The last column is
1856
- * inclusive.
1857
- */
1858
- computeColumnSpans() {
1859
- if (this._computedColumnSpans) {
1860
- return;
1861
- }
1862
-
1863
- this._wasm.exports.compute_column_spans(this._getMappingsPtr());
1864
- this._computedColumnSpans = true;
1865
- }
1866
-
1867
- /**
1868
- * Returns the original source, line, and column information for the generated
1869
- * source's line and column positions provided. The only argument is an object
1870
- * with the following properties:
1871
- *
1872
- * - line: The line number in the generated source. The line number
1873
- * is 1-based.
1874
- * - column: The column number in the generated source. The column
1875
- * number is 0-based.
1876
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1877
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1878
- * closest element that is smaller than or greater than the one we are
1879
- * searching for, respectively, if the exact element cannot be found.
1880
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
1881
- *
1882
- * and an object is returned with the following properties:
1883
- *
1884
- * - source: The original source file, or null.
1885
- * - line: The line number in the original source, or null. The
1886
- * line number is 1-based.
1887
- * - column: The column number in the original source, or null. The
1888
- * column number is 0-based.
1889
- * - name: The original identifier, or null.
1890
- */
1891
- originalPositionFor(aArgs) {
1892
- const needle = {
1893
- generatedLine: util$1.getArg(aArgs, "line"),
1894
- generatedColumn: util$1.getArg(aArgs, "column")
1895
- };
1896
-
1897
- if (needle.generatedLine < 1) {
1898
- throw new Error("Line numbers must be >= 1");
151
+ return td.decode(buf.subarray(0, pos));
1899
152
  }
1900
-
1901
- if (needle.generatedColumn < 0) {
1902
- throw new Error("Column numbers must be >= 0");
153
+ function reserve(buf, pos, count) {
154
+ if (buf.length > pos + count)
155
+ return buf;
156
+ const swap = new Uint8Array(buf.length * 2);
157
+ swap.set(buf);
158
+ return swap;
1903
159
  }
1904
-
1905
- let bias = util$1.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND);
1906
- if (bias == null) {
1907
- bias = SourceMapConsumer.GREATEST_LOWER_BOUND;
160
+ function encodeInteger(buf, pos, state, segment, j) {
161
+ const next = segment[j];
162
+ let num = next - state[j];
163
+ state[j] = next;
164
+ num = num < 0 ? (-num << 1) | 1 : num << 1;
165
+ do {
166
+ let clamped = num & 0b011111;
167
+ num >>>= 5;
168
+ if (num > 0)
169
+ clamped |= 0b100000;
170
+ buf[pos++] = intToChar[clamped];
171
+ } while (num > 0);
172
+ return pos;
1908
173
  }
1909
174
 
1910
- let mapping;
1911
- this._wasm.withMappingCallback(m => mapping = m, () => {
1912
- this._wasm.exports.original_location_for(
1913
- this._getMappingsPtr(),
1914
- needle.generatedLine - 1,
1915
- needle.generatedColumn,
1916
- bias
1917
- );
1918
- });
1919
-
1920
- if (mapping) {
1921
- if (mapping.generatedLine === needle.generatedLine) {
1922
- let source = util$1.getArg(mapping, "source", null);
1923
- if (source !== null) {
1924
- source = this._absoluteSources.at(source);
1925
- }
1926
-
1927
- let name = util$1.getArg(mapping, "name", null);
1928
- if (name !== null) {
1929
- name = this._names.at(name);
1930
- }
1931
-
175
+ // Matches the scheme of a URL, eg "http://"
176
+ const schemeRegex = /^[\w+.-]+:\/\//;
177
+ /**
178
+ * Matches the parts of a URL:
179
+ * 1. Scheme, including ":", guaranteed.
180
+ * 2. User/password, including "@", optional.
181
+ * 3. Host, guaranteed.
182
+ * 4. Port, including ":", optional.
183
+ * 5. Path, including "/", optional.
184
+ */
185
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?/;
186
+ /**
187
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
188
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
189
+ *
190
+ * 1. Host, optional.
191
+ * 2. Path, which may inclue "/", guaranteed.
192
+ */
193
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/]*)?)?(\/?.*)/i;
194
+ function isAbsoluteUrl(input) {
195
+ return schemeRegex.test(input);
196
+ }
197
+ function isSchemeRelativeUrl(input) {
198
+ return input.startsWith('//');
199
+ }
200
+ function isAbsolutePath(input) {
201
+ return input.startsWith('/');
202
+ }
203
+ function isFileUrl(input) {
204
+ return input.startsWith('file:');
205
+ }
206
+ function parseAbsoluteUrl(input) {
207
+ const match = urlRegex.exec(input);
208
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/');
209
+ }
210
+ function parseFileUrl(input) {
211
+ const match = fileRegex.exec(input);
212
+ const path = match[2];
213
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path);
214
+ }
215
+ function makeUrl(scheme, user, host, port, path) {
1932
216
  return {
1933
- source,
1934
- line: util$1.getArg(mapping, "originalLine", null),
1935
- column: util$1.getArg(mapping, "originalColumn", null),
1936
- name
217
+ scheme,
218
+ user,
219
+ host,
220
+ port,
221
+ path,
222
+ relativePath: false,
1937
223
  };
1938
- }
1939
- }
1940
-
1941
- return {
1942
- source: null,
1943
- line: null,
1944
- column: null,
1945
- name: null
1946
- };
1947
- }
1948
-
1949
- /**
1950
- * Return true if we have the source content for every source in the source
1951
- * map, false otherwise.
1952
- */
1953
- hasContentsOfAllSources() {
1954
- if (!this.sourcesContent) {
1955
- return false;
1956
- }
1957
- return this.sourcesContent.length >= this._sources.size() &&
1958
- !this.sourcesContent.some(function(sc) { return sc == null; });
1959
- }
1960
-
1961
- /**
1962
- * Returns the original source content. The only argument is the url of the
1963
- * original source file. Returns null if no original source content is
1964
- * available.
1965
- */
1966
- sourceContentFor(aSource, nullOnMissing) {
1967
- if (!this.sourcesContent) {
1968
- return null;
1969
- }
1970
-
1971
- const index = this._findSourceIndex(aSource);
1972
- if (index >= 0) {
1973
- return this.sourcesContent[index];
1974
- }
1975
-
1976
- // This function is used recursively from
1977
- // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
1978
- // don't want to throw if we can't find the source - we just want to
1979
- // return null, so we provide a flag to exit gracefully.
1980
- if (nullOnMissing) {
1981
- return null;
1982
- }
1983
-
1984
- throw new Error('"' + aSource + '" is not in the SourceMap.');
1985
- }
1986
-
1987
- /**
1988
- * Returns the generated line and column information for the original source,
1989
- * line, and column positions provided. The only argument is an object with
1990
- * the following properties:
1991
- *
1992
- * - source: The filename of the original source.
1993
- * - line: The line number in the original source. The line number
1994
- * is 1-based.
1995
- * - column: The column number in the original source. The column
1996
- * number is 0-based.
1997
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1998
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1999
- * closest element that is smaller than or greater than the one we are
2000
- * searching for, respectively, if the exact element cannot be found.
2001
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
2002
- *
2003
- * and an object is returned with the following properties:
2004
- *
2005
- * - line: The line number in the generated source, or null. The
2006
- * line number is 1-based.
2007
- * - column: The column number in the generated source, or null.
2008
- * The column number is 0-based.
2009
- */
2010
- generatedPositionFor(aArgs) {
2011
- let source = util$1.getArg(aArgs, "source");
2012
- source = this._findSourceIndex(source);
2013
- if (source < 0) {
2014
- return {
2015
- line: null,
2016
- column: null,
2017
- lastColumn: null
2018
- };
2019
224
  }
2020
-
2021
- const needle = {
2022
- source,
2023
- originalLine: util$1.getArg(aArgs, "line"),
2024
- originalColumn: util$1.getArg(aArgs, "column")
2025
- };
2026
-
2027
- if (needle.originalLine < 1) {
2028
- throw new Error("Line numbers must be >= 1");
225
+ function parseUrl(input) {
226
+ if (isSchemeRelativeUrl(input)) {
227
+ const url = parseAbsoluteUrl('http:' + input);
228
+ url.scheme = '';
229
+ return url;
230
+ }
231
+ if (isAbsolutePath(input)) {
232
+ const url = parseAbsoluteUrl('http://foo.com' + input);
233
+ url.scheme = '';
234
+ url.host = '';
235
+ return url;
236
+ }
237
+ if (isFileUrl(input))
238
+ return parseFileUrl(input);
239
+ if (isAbsoluteUrl(input))
240
+ return parseAbsoluteUrl(input);
241
+ const url = parseAbsoluteUrl('http://foo.com/' + input);
242
+ url.scheme = '';
243
+ url.host = '';
244
+ url.relativePath = true;
245
+ return url;
246
+ }
247
+ function stripPathFilename(path) {
248
+ // If a path ends with a parent directory "..", then it's a relative path with excess parent
249
+ // paths. It's not a file, so we can't strip it.
250
+ if (path.endsWith('/..'))
251
+ return path;
252
+ const index = path.lastIndexOf('/');
253
+ return path.slice(0, index + 1);
254
+ }
255
+ function mergePaths(url, base) {
256
+ // If we're not a relative path, then we're an absolute path, and it doesn't matter what base is.
257
+ if (!url.relativePath)
258
+ return;
259
+ normalizePath(base);
260
+ // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
261
+ // path).
262
+ if (url.path === '/') {
263
+ url.path = base.path;
264
+ }
265
+ else {
266
+ // Resolution happens relative to the base path's directory, not the file.
267
+ url.path = stripPathFilename(base.path) + url.path;
268
+ }
269
+ // If the base path is absolute, then our path is now absolute too.
270
+ url.relativePath = base.relativePath;
271
+ }
272
+ /**
273
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
274
+ * "foo/.". We need to normalize to a standard representation.
275
+ */
276
+ function normalizePath(url) {
277
+ const { relativePath } = url;
278
+ const pieces = url.path.split('/');
279
+ // We need to preserve the first piece always, so that we output a leading slash. The item at
280
+ // pieces[0] is an empty string.
281
+ let pointer = 1;
282
+ // Positive is the number of real directories we've output, used for popping a parent directory.
283
+ // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
284
+ let positive = 0;
285
+ // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
286
+ // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
287
+ // real directory, we won't need to append, unless the other conditions happen again.
288
+ let addTrailingSlash = false;
289
+ for (let i = 1; i < pieces.length; i++) {
290
+ const piece = pieces[i];
291
+ // An empty directory, could be a trailing slash, or just a double "//" in the path.
292
+ if (!piece) {
293
+ addTrailingSlash = true;
294
+ continue;
295
+ }
296
+ // If we encounter a real directory, then we don't need to append anymore.
297
+ addTrailingSlash = false;
298
+ // A current directory, which we can always drop.
299
+ if (piece === '.')
300
+ continue;
301
+ // A parent directory, we need to see if there are any real directories we can pop. Else, we
302
+ // have an excess of parents, and we'll need to keep the "..".
303
+ if (piece === '..') {
304
+ if (positive) {
305
+ addTrailingSlash = true;
306
+ positive--;
307
+ pointer--;
308
+ }
309
+ else if (relativePath) {
310
+ // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
311
+ // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
312
+ pieces[pointer++] = piece;
313
+ }
314
+ continue;
315
+ }
316
+ // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
317
+ // any popped or dropped directories.
318
+ pieces[pointer++] = piece;
319
+ positive++;
320
+ }
321
+ let path = '';
322
+ for (let i = 1; i < pointer; i++) {
323
+ path += '/' + pieces[i];
324
+ }
325
+ if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
326
+ path += '/';
327
+ }
328
+ url.path = path;
329
+ }
330
+ /**
331
+ * Attempts to resolve `input` URL/path relative to `base`.
332
+ */
333
+ function resolve$1(input, base) {
334
+ if (!input && !base)
335
+ return '';
336
+ const url = parseUrl(input);
337
+ // If we have a base, and the input isn't already an absolute URL, then we need to merge.
338
+ if (base && !url.scheme) {
339
+ const baseUrl = parseUrl(base);
340
+ url.scheme = baseUrl.scheme;
341
+ // If there's no host, then we were just a path.
342
+ if (!url.host) {
343
+ // The host, user, and port are joined, you can't copy one without the others.
344
+ url.user = baseUrl.user;
345
+ url.host = baseUrl.host;
346
+ url.port = baseUrl.port;
347
+ }
348
+ mergePaths(url, baseUrl);
349
+ }
350
+ normalizePath(url);
351
+ // If the input (and base, if there was one) are both relative, then we need to output a relative.
352
+ if (url.relativePath) {
353
+ // The first char is always a "/".
354
+ const path = url.path.slice(1);
355
+ if (!path)
356
+ return '.';
357
+ // If base started with a leading ".", or there is no base and input started with a ".", then we
358
+ // need to ensure that the relative path starts with a ".". We don't know if relative starts
359
+ // with a "..", though, so check before prepending.
360
+ const keepRelative = (base || input).startsWith('.');
361
+ return !keepRelative || path.startsWith('.') ? path : './' + path;
362
+ }
363
+ // If there's no host (and no scheme/user/port), then we need to output an absolute path.
364
+ if (!url.scheme && !url.host)
365
+ return url.path;
366
+ // We're outputting either an absolute URL, or a protocol relative one.
367
+ return `${url.scheme}//${url.user}${url.host}${url.port}${url.path}`;
368
+ }
369
+
370
+ function resolve(input, base) {
371
+ // The base is always treated as a directory, if it's not empty.
372
+ // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
373
+ // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
374
+ if (base && !base.endsWith('/'))
375
+ base += '/';
376
+ return resolve$1(input, base);
377
+ }
378
+
379
+ /**
380
+ * Removes everything after the last "/", but leaves the slash.
381
+ */
382
+ function stripFilename(path) {
383
+ if (!path)
384
+ return '';
385
+ const index = path.lastIndexOf('/');
386
+ return path.slice(0, index + 1);
387
+ }
388
+
389
+ const COLUMN$1 = 0;
390
+ const SOURCES_INDEX$1 = 1;
391
+ const SOURCE_LINE$1 = 2;
392
+ const SOURCE_COLUMN$1 = 3;
393
+ const NAMES_INDEX$1 = 4;
394
+
395
+ function maybeSort(mappings, owned) {
396
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
397
+ if (unsortedIndex === mappings.length)
398
+ return mappings;
399
+ // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
400
+ // not, we do not want to modify the consumer's input array.
401
+ if (!owned)
402
+ mappings = mappings.slice();
403
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
404
+ mappings[i] = sortSegments(mappings[i], owned);
405
+ }
406
+ return mappings;
407
+ }
408
+ function nextUnsortedSegmentLine(mappings, start) {
409
+ for (let i = start; i < mappings.length; i++) {
410
+ if (!isSorted(mappings[i]))
411
+ return i;
412
+ }
413
+ return mappings.length;
2029
414
  }
2030
-
2031
- if (needle.originalColumn < 0) {
2032
- throw new Error("Column numbers must be >= 0");
415
+ function isSorted(line) {
416
+ for (let j = 1; j < line.length; j++) {
417
+ if (line[j][COLUMN$1] < line[j - 1][COLUMN$1]) {
418
+ return false;
419
+ }
420
+ }
421
+ return true;
2033
422
  }
2034
-
2035
- let bias = util$1.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND);
2036
- if (bias == null) {
2037
- bias = SourceMapConsumer.GREATEST_LOWER_BOUND;
423
+ function sortSegments(line, owned) {
424
+ if (!owned)
425
+ line = line.slice();
426
+ return line.sort(sortComparator);
427
+ }
428
+ function sortComparator(a, b) {
429
+ return a[COLUMN$1] - b[COLUMN$1];
430
+ }
431
+
432
+ let found = false;
433
+ /**
434
+ * A binary search implementation that returns the index if a match is found.
435
+ * If no match is found, then the left-index (the index associated with the item that comes just
436
+ * before the desired index) is returned. To maintain proper sort order, a splice would happen at
437
+ * the next index:
438
+ *
439
+ * ```js
440
+ * const array = [1, 3];
441
+ * const needle = 2;
442
+ * const index = binarySearch(array, needle, (item, needle) => item - needle);
443
+ *
444
+ * assert.equal(index, 0);
445
+ * array.splice(index + 1, 0, needle);
446
+ * assert.deepEqual(array, [1, 2, 3]);
447
+ * ```
448
+ */
449
+ function binarySearch(haystack, needle, low, high) {
450
+ while (low <= high) {
451
+ const mid = low + ((high - low) >> 1);
452
+ const cmp = haystack[mid][COLUMN$1] - needle;
453
+ if (cmp === 0) {
454
+ found = true;
455
+ return mid;
456
+ }
457
+ if (cmp < 0) {
458
+ low = mid + 1;
459
+ }
460
+ else {
461
+ high = mid - 1;
462
+ }
463
+ }
464
+ found = false;
465
+ return low - 1;
466
+ }
467
+ function upperBound(haystack, needle, index) {
468
+ for (let i = index + 1; i < haystack.length; i++, index++) {
469
+ if (haystack[i][COLUMN$1] !== needle)
470
+ break;
471
+ }
472
+ return index;
2038
473
  }
2039
-
2040
- let mapping;
2041
- this._wasm.withMappingCallback(m => mapping = m, () => {
2042
- this._wasm.exports.generated_location_for(
2043
- this._getMappingsPtr(),
2044
- needle.source,
2045
- needle.originalLine - 1,
2046
- needle.originalColumn,
2047
- bias
2048
- );
2049
- });
2050
-
2051
- if (mapping) {
2052
- if (mapping.source === needle.source) {
2053
- let lastColumn = mapping.lastGeneratedColumn;
2054
- if (this._computedColumnSpans && lastColumn === null) {
2055
- lastColumn = Infinity;
474
+ function lowerBound(haystack, needle, index) {
475
+ for (let i = index - 1; i >= 0; i--, index--) {
476
+ if (haystack[i][COLUMN$1] !== needle)
477
+ break;
2056
478
  }
479
+ return index;
480
+ }
481
+ function memoizedState() {
2057
482
  return {
2058
- line: util$1.getArg(mapping, "generatedLine", null),
2059
- column: util$1.getArg(mapping, "generatedColumn", null),
2060
- lastColumn,
483
+ lastKey: -1,
484
+ lastNeedle: -1,
485
+ lastIndex: -1,
2061
486
  };
2062
- }
2063
487
  }
2064
-
2065
- return {
2066
- line: null,
2067
- column: null,
2068
- lastColumn: null
2069
- };
2070
- }
2071
- }
2072
-
2073
- BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
2074
- sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
2075
-
2076
- /**
2077
- * An IndexedSourceMapConsumer instance represents a parsed source map which
2078
- * we can query for information. It differs from BasicSourceMapConsumer in
2079
- * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
2080
- * input.
2081
- *
2082
- * The first parameter is a raw source map (either as a JSON string, or already
2083
- * parsed to an object). According to the spec for indexed source maps, they
2084
- * have the following attributes:
2085
- *
2086
- * - version: Which version of the source map spec this map is following.
2087
- * - file: Optional. The generated file this source map is associated with.
2088
- * - sections: A list of section definitions.
2089
- *
2090
- * Each value under the "sections" field has two fields:
2091
- * - offset: The offset into the original specified at which this section
2092
- * begins to apply, defined as an object with a "line" and "column"
2093
- * field.
2094
- * - map: A source map definition. This source map could also be indexed,
2095
- * but doesn't have to be.
2096
- *
2097
- * Instead of the "map" field, it's also possible to have a "url" field
2098
- * specifying a URL to retrieve a source map from, but that's currently
2099
- * unsupported.
2100
- *
2101
- * Here's an example source map, taken from the source map spec[0], but
2102
- * modified to omit a section which uses the "url" field.
2103
- *
2104
- * {
2105
- * version : 3,
2106
- * file: "app.js",
2107
- * sections: [{
2108
- * offset: {line:100, column:10},
2109
- * map: {
2110
- * version : 3,
2111
- * file: "section.js",
2112
- * sources: ["foo.js", "bar.js"],
2113
- * names: ["src", "maps", "are", "fun"],
2114
- * mappings: "AAAA,E;;ABCDE;"
2115
- * }
2116
- * }],
2117
- * }
2118
- *
2119
- * The second parameter, if given, is a string whose value is the URL
2120
- * at which the source map was found. This URL is used to compute the
2121
- * sources array.
2122
- *
2123
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
2124
- */
2125
- class IndexedSourceMapConsumer extends SourceMapConsumer {
2126
- constructor(aSourceMap, aSourceMapURL) {
2127
- return super(INTERNAL).then(that => {
2128
- let sourceMap = aSourceMap;
2129
- if (typeof aSourceMap === "string") {
2130
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
2131
- }
2132
-
2133
- const version = util$1.getArg(sourceMap, "version");
2134
- const sections = util$1.getArg(sourceMap, "sections");
2135
-
2136
- if (version != that._version) {
2137
- throw new Error("Unsupported version: " + version);
2138
- }
2139
-
2140
- let lastOffset = {
2141
- line: -1,
2142
- column: 0
2143
- };
2144
- return Promise.all(sections.map(s => {
2145
- if (s.url) {
2146
- // The url field will require support for asynchronicity.
2147
- // See https://github.com/mozilla/source-map/issues/16
2148
- throw new Error("Support for url field in sections not implemented.");
2149
- }
2150
- const offset = util$1.getArg(s, "offset");
2151
- const offsetLine = util$1.getArg(offset, "line");
2152
- const offsetColumn = util$1.getArg(offset, "column");
2153
-
2154
- if (offsetLine < lastOffset.line ||
2155
- (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
2156
- throw new Error("Section offsets must be ordered and non-overlapping.");
2157
- }
2158
- lastOffset = offset;
2159
-
2160
- const cons = new SourceMapConsumer(util$1.getArg(s, "map"), aSourceMapURL);
2161
- return cons.then(consumer => {
2162
- return {
2163
- generatedOffset: {
2164
- // The offset fields are 0-based, but we use 1-based indices when
2165
- // encoding/decoding from VLQ.
2166
- generatedLine: offsetLine + 1,
2167
- generatedColumn: offsetColumn + 1
2168
- },
2169
- consumer
2170
- };
2171
- });
2172
- })).then(s => {
2173
- that._sections = s;
2174
- return that;
2175
- });
2176
- });
2177
- }
2178
-
2179
- /**
2180
- * The list of original sources.
2181
- */
2182
- get sources() {
2183
- const sources = [];
2184
- for (let i = 0; i < this._sections.length; i++) {
2185
- for (let j = 0; j < this._sections[i].consumer.sources.length; j++) {
2186
- sources.push(this._sections[i].consumer.sources[j]);
2187
- }
2188
- }
2189
- return sources;
2190
- }
2191
-
2192
- /**
2193
- * Returns the original source, line, and column information for the generated
2194
- * source's line and column positions provided. The only argument is an object
2195
- * with the following properties:
2196
- *
2197
- * - line: The line number in the generated source. The line number
2198
- * is 1-based.
2199
- * - column: The column number in the generated source. The column
2200
- * number is 0-based.
2201
- *
2202
- * and an object is returned with the following properties:
2203
- *
2204
- * - source: The original source file, or null.
2205
- * - line: The line number in the original source, or null. The
2206
- * line number is 1-based.
2207
- * - column: The column number in the original source, or null. The
2208
- * column number is 0-based.
2209
- * - name: The original identifier, or null.
2210
- */
2211
- originalPositionFor(aArgs) {
2212
- const needle = {
2213
- generatedLine: util$1.getArg(aArgs, "line"),
2214
- generatedColumn: util$1.getArg(aArgs, "column")
488
+ /**
489
+ * This overly complicated beast is just to record the last tested line/column and the resulting
490
+ * index, allowing us to skip a few tests if mappings are monotonically increasing.
491
+ */
492
+ function memoizedBinarySearch(haystack, needle, state, key) {
493
+ const { lastKey, lastNeedle, lastIndex } = state;
494
+ let low = 0;
495
+ let high = haystack.length - 1;
496
+ if (key === lastKey) {
497
+ if (needle === lastNeedle) {
498
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN$1] === needle;
499
+ return lastIndex;
500
+ }
501
+ if (needle >= lastNeedle) {
502
+ // lastIndex may be -1 if the previous needle was not found.
503
+ low = lastIndex === -1 ? 0 : lastIndex;
504
+ }
505
+ else {
506
+ high = lastIndex;
507
+ }
508
+ }
509
+ state.lastKey = key;
510
+ state.lastNeedle = needle;
511
+ return (state.lastIndex = binarySearch(haystack, needle, low, high));
512
+ }
513
+
514
+ const AnyMap = function (map, mapUrl) {
515
+ const parsed = typeof map === 'string' ? JSON.parse(map) : map;
516
+ if (!('sections' in parsed))
517
+ return new TraceMap(parsed, mapUrl);
518
+ const mappings = [];
519
+ const sources = [];
520
+ const sourcesContent = [];
521
+ const names = [];
522
+ const { sections } = parsed;
523
+ let i = 0;
524
+ for (; i < sections.length - 1; i++) {
525
+ const no = sections[i + 1].offset;
526
+ addSection(sections[i], mapUrl, mappings, sources, sourcesContent, names, no.line, no.column);
527
+ }
528
+ if (sections.length > 0) {
529
+ addSection(sections[i], mapUrl, mappings, sources, sourcesContent, names, Infinity, Infinity);
530
+ }
531
+ const joined = {
532
+ version: 3,
533
+ file: parsed.file,
534
+ names,
535
+ sources,
536
+ sourcesContent,
537
+ mappings,
538
+ };
539
+ return presortedDecodedMap(joined);
2215
540
  };
2216
-
2217
- // Find the section containing the generated position we're trying to map
2218
- // to an original position.
2219
- const sectionIndex = binarySearch.search(needle, this._sections,
2220
- function(aNeedle, section) {
2221
- const cmp = aNeedle.generatedLine - section.generatedOffset.generatedLine;
2222
- if (cmp) {
2223
- return cmp;
541
+ function addSection(section, mapUrl, mappings, sources, sourcesContent, names, stopLine, stopColumn) {
542
+ const map = AnyMap(section.map, mapUrl);
543
+ const { line: lineOffset, column: columnOffset } = section.offset;
544
+ const sourcesOffset = sources.length;
545
+ const namesOffset = names.length;
546
+ const decoded = decodedMappings(map);
547
+ const { resolvedSources } = map;
548
+ append(sources, resolvedSources);
549
+ append(sourcesContent, map.sourcesContent || fillSourcesContent(resolvedSources.length));
550
+ append(names, map.names);
551
+ // If this section jumps forwards several lines, we need to add lines to the output mappings catch up.
552
+ for (let i = mappings.length; i <= lineOffset; i++)
553
+ mappings.push([]);
554
+ // We can only add so many lines before we step into the range that the next section's map
555
+ // controls. When we get to the last line, then we'll start checking the segments to see if
556
+ // they've crossed into the column range.
557
+ const stopI = stopLine - lineOffset;
558
+ const len = Math.min(decoded.length, stopI + 1);
559
+ for (let i = 0; i < len; i++) {
560
+ const line = decoded[i];
561
+ // On the 0th loop, the line will already exist due to a previous section, or the line catch up
562
+ // loop above.
563
+ const out = i === 0 ? mappings[lineOffset] : (mappings[lineOffset + i] = []);
564
+ // On the 0th loop, the section's column offset shifts us forward. On all other lines (since the
565
+ // map can be multiple lines), it doesn't.
566
+ const cOffset = i === 0 ? columnOffset : 0;
567
+ for (let j = 0; j < line.length; j++) {
568
+ const seg = line[j];
569
+ const column = cOffset + seg[COLUMN$1];
570
+ // If this segment steps into the column range that the next section's map controls, we need
571
+ // to stop early.
572
+ if (i === stopI && column >= stopColumn)
573
+ break;
574
+ if (seg.length === 1) {
575
+ out.push([column]);
576
+ continue;
577
+ }
578
+ const sourcesIndex = sourcesOffset + seg[SOURCES_INDEX$1];
579
+ const sourceLine = seg[SOURCE_LINE$1];
580
+ const sourceColumn = seg[SOURCE_COLUMN$1];
581
+ if (seg.length === 4) {
582
+ out.push([column, sourcesIndex, sourceLine, sourceColumn]);
583
+ continue;
584
+ }
585
+ out.push([column, sourcesIndex, sourceLine, sourceColumn, namesOffset + seg[NAMES_INDEX$1]]);
586
+ }
2224
587
  }
588
+ }
589
+ function append(arr, other) {
590
+ for (let i = 0; i < other.length; i++)
591
+ arr.push(other[i]);
592
+ }
593
+ // Sourcemaps don't need to have sourcesContent, and if they don't, we need to create an array of
594
+ // equal length to the sources. This is because the sources and sourcesContent are paired arrays,
595
+ // where `sourcesContent[i]` is the content of the `sources[i]` file. If we didn't, then joined
596
+ // sourcemap would desynchronize the sources/contents.
597
+ function fillSourcesContent(len) {
598
+ const sourcesContent = [];
599
+ for (let i = 0; i < len; i++)
600
+ sourcesContent[i] = null;
601
+ return sourcesContent;
602
+ }
2225
603
 
2226
- return (aNeedle.generatedColumn -
2227
- section.generatedOffset.generatedColumn);
2228
- });
2229
- const section = this._sections[sectionIndex];
2230
-
2231
- if (!section) {
2232
- return {
604
+ const INVALID_ORIGINAL_MAPPING = Object.freeze({
2233
605
  source: null,
2234
606
  line: null,
2235
607
  column: null,
2236
- name: null
2237
- };
2238
- }
2239
-
2240
- return section.consumer.originalPositionFor({
2241
- line: needle.generatedLine -
2242
- (section.generatedOffset.generatedLine - 1),
2243
- column: needle.generatedColumn -
2244
- (section.generatedOffset.generatedLine === needle.generatedLine
2245
- ? section.generatedOffset.generatedColumn - 1
2246
- : 0),
2247
- bias: aArgs.bias
2248
- });
2249
- }
2250
-
2251
- /**
2252
- * Return true if we have the source content for every source in the source
2253
- * map, false otherwise.
2254
- */
2255
- hasContentsOfAllSources() {
2256
- return this._sections.every(function(s) {
2257
- return s.consumer.hasContentsOfAllSources();
2258
- });
2259
- }
2260
-
2261
- /**
2262
- * Returns the original source content. The only argument is the url of the
2263
- * original source file. Returns null if no original source content is
2264
- * available.
2265
- */
2266
- sourceContentFor(aSource, nullOnMissing) {
2267
- for (let i = 0; i < this._sections.length; i++) {
2268
- const section = this._sections[i];
2269
-
2270
- const content = section.consumer.sourceContentFor(aSource, true);
2271
- if (content) {
2272
- return content;
2273
- }
2274
- }
2275
- if (nullOnMissing) {
2276
- return null;
2277
- }
2278
- throw new Error('"' + aSource + '" is not in the SourceMap.');
2279
- }
2280
-
2281
- _findSectionIndex(source) {
2282
- for (let i = 0; i < this._sections.length; i++) {
2283
- const { consumer } = this._sections[i];
2284
- if (consumer._findSourceIndex(source) !== -1) {
2285
- return i;
2286
- }
2287
- }
2288
- return -1;
2289
- }
2290
-
2291
- /**
2292
- * Returns the generated line and column information for the original source,
2293
- * line, and column positions provided. The only argument is an object with
2294
- * the following properties:
2295
- *
2296
- * - source: The filename of the original source.
2297
- * - line: The line number in the original source. The line number
2298
- * is 1-based.
2299
- * - column: The column number in the original source. The column
2300
- * number is 0-based.
2301
- *
2302
- * and an object is returned with the following properties:
2303
- *
2304
- * - line: The line number in the generated source, or null. The
2305
- * line number is 1-based.
2306
- * - column: The column number in the generated source, or null.
2307
- * The column number is 0-based.
2308
- */
2309
- generatedPositionFor(aArgs) {
2310
- const index = this._findSectionIndex(util$1.getArg(aArgs, "source"));
2311
- const section = index >= 0 ? this._sections[index] : null;
2312
- const nextSection =
2313
- index >= 0 && index + 1 < this._sections.length
2314
- ? this._sections[index + 1]
2315
- : null;
2316
-
2317
- const generatedPosition =
2318
- section && section.consumer.generatedPositionFor(aArgs);
2319
- if (generatedPosition && generatedPosition.line !== null) {
2320
- const lineShift = section.generatedOffset.generatedLine - 1;
2321
- const columnShift = section.generatedOffset.generatedColumn - 1;
2322
-
2323
- if (generatedPosition.line === 1) {
2324
- generatedPosition.column += columnShift;
2325
- if (typeof generatedPosition.lastColumn === "number") {
2326
- generatedPosition.lastColumn += columnShift;
2327
- }
2328
- }
2329
-
2330
- if (
2331
- generatedPosition.lastColumn === Infinity &&
2332
- nextSection &&
2333
- generatedPosition.line === nextSection.generatedOffset.generatedLine
2334
- ) {
2335
- generatedPosition.lastColumn =
2336
- nextSection.generatedOffset.generatedColumn - 2;
2337
- }
2338
- generatedPosition.line += lineShift;
2339
-
2340
- return generatedPosition;
2341
- }
2342
-
2343
- return {
2344
- line: null,
2345
- column: null,
2346
- lastColumn: null
2347
- };
2348
- }
2349
-
2350
- allGeneratedPositionsFor(aArgs) {
2351
- const index = this._findSectionIndex(util$1.getArg(aArgs, "source"));
2352
- const section = index >= 0 ? this._sections[index] : null;
2353
- const nextSection =
2354
- index >= 0 && index + 1 < this._sections.length
2355
- ? this._sections[index + 1]
2356
- : null;
2357
-
2358
- if (!section) return [];
2359
-
2360
- return section.consumer.allGeneratedPositionsFor(aArgs).map(
2361
- generatedPosition => {
2362
- const lineShift = section.generatedOffset.generatedLine - 1;
2363
- const columnShift = section.generatedOffset.generatedColumn - 1;
2364
-
2365
- if (generatedPosition.line === 1) {
2366
- generatedPosition.column += columnShift;
2367
- if (typeof generatedPosition.lastColumn === "number") {
2368
- generatedPosition.lastColumn += columnShift;
2369
- }
2370
- }
2371
-
2372
- if (
2373
- generatedPosition.lastColumn === Infinity &&
2374
- nextSection &&
2375
- generatedPosition.line === nextSection.generatedOffset.generatedLine
2376
- ) {
2377
- generatedPosition.lastColumn =
2378
- nextSection.generatedOffset.generatedColumn - 2;
2379
- }
2380
- generatedPosition.line += lineShift;
2381
-
2382
- return generatedPosition;
2383
- }
2384
- );
2385
- }
2386
-
2387
- eachMapping(aCallback, aContext, aOrder) {
2388
- this._sections.forEach((section, index) => {
2389
- const nextSection =
2390
- index + 1 < this._sections.length
2391
- ? this._sections[index + 1]
2392
- : null;
2393
- const { generatedOffset } = section;
2394
-
2395
- const lineShift = generatedOffset.generatedLine - 1;
2396
- const columnShift = generatedOffset.generatedColumn - 1;
2397
-
2398
- section.consumer.eachMapping(function(mapping) {
2399
- if (mapping.generatedLine === 1) {
2400
- mapping.generatedColumn += columnShift;
608
+ name: null,
609
+ });
610
+ Object.freeze({
611
+ line: null,
612
+ column: null,
613
+ });
614
+ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
615
+ const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
616
+ const LEAST_UPPER_BOUND = -1;
617
+ const GREATEST_LOWER_BOUND = 1;
618
+ /**
619
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
620
+ */
621
+ let decodedMappings;
622
+ /**
623
+ * A higher-level API to find the source/line/column associated with a generated line/column
624
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
625
+ * `source-map` library.
626
+ */
627
+ let originalPositionFor;
628
+ /**
629
+ * A helper that skips sorting of the input map's mappings array, which can be expensive for larger
630
+ * maps.
631
+ */
632
+ let presortedDecodedMap;
633
+ class TraceMap {
634
+ constructor(map, mapUrl) {
635
+ this._decodedMemo = memoizedState();
636
+ this._bySources = undefined;
637
+ this._bySourceMemos = undefined;
638
+ const isString = typeof map === 'string';
639
+ if (!isString && map.constructor === TraceMap)
640
+ return map;
641
+ const parsed = (isString ? JSON.parse(map) : map);
642
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
643
+ this.version = version;
644
+ this.file = file;
645
+ this.names = names;
646
+ this.sourceRoot = sourceRoot;
647
+ this.sources = sources;
648
+ this.sourcesContent = sourcesContent;
649
+ if (sourceRoot || mapUrl) {
650
+ const from = resolve(sourceRoot || '', stripFilename(mapUrl));
651
+ this.resolvedSources = sources.map((s) => resolve(s || '', from));
652
+ }
653
+ else {
654
+ this.resolvedSources = sources.map((s) => s || '');
655
+ }
656
+ const { mappings } = parsed;
657
+ if (typeof mappings === 'string') {
658
+ this._encoded = mappings;
659
+ this._decoded = undefined;
660
+ }
661
+ else {
662
+ this._encoded = undefined;
663
+ this._decoded = maybeSort(mappings, isString);
664
+ }
665
+ }
666
+ }
667
+ (() => {
668
+ decodedMappings = (map) => {
669
+ return (map._decoded || (map._decoded = decode(map._encoded)));
670
+ };
671
+ originalPositionFor = (map, { line, column, bias }) => {
672
+ line--;
673
+ if (line < 0)
674
+ throw new Error(LINE_GTR_ZERO);
675
+ if (column < 0)
676
+ throw new Error(COL_GTR_EQ_ZERO);
677
+ const decoded = decodedMappings(map);
678
+ // It's common for parent source maps to have pointers to lines that have no
679
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
680
+ if (line >= decoded.length)
681
+ return INVALID_ORIGINAL_MAPPING;
682
+ const segment = traceSegmentInternal(decoded[line], map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
683
+ if (segment == null)
684
+ return INVALID_ORIGINAL_MAPPING;
685
+ if (segment.length == 1)
686
+ return INVALID_ORIGINAL_MAPPING;
687
+ const { names, resolvedSources } = map;
688
+ return {
689
+ source: resolvedSources[segment[SOURCES_INDEX$1]],
690
+ line: segment[SOURCE_LINE$1] + 1,
691
+ column: segment[SOURCE_COLUMN$1],
692
+ name: segment.length === 5 ? names[segment[NAMES_INDEX$1]] : null,
693
+ };
694
+ };
695
+ presortedDecodedMap = (map, mapUrl) => {
696
+ const clone = Object.assign({}, map);
697
+ clone.mappings = [];
698
+ const tracer = new TraceMap(clone, mapUrl);
699
+ tracer._decoded = map.mappings;
700
+ return tracer;
701
+ };
702
+ })();
703
+ function traceSegmentInternal(segments, memo, line, column, bias) {
704
+ let index = memoizedBinarySearch(segments, column, memo, line);
705
+ if (found) {
706
+ index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
707
+ }
708
+ else if (bias === LEAST_UPPER_BOUND)
709
+ index++;
710
+ if (index === -1 || index === segments.length)
711
+ return null;
712
+ return segments[index];
713
+ }
714
+
715
+ /**
716
+ * Gets the index associated with `key` in the backing array, if it is already present.
717
+ */
718
+ let get;
719
+ /**
720
+ * Puts `key` into the backing array, if it is not already present. Returns
721
+ * the index of the `key` in the backing array.
722
+ */
723
+ let put;
724
+ /**
725
+ * SetArray acts like a `Set` (allowing only one occurrence of a string `key`), but provides the
726
+ * index of the `key` in the backing array.
727
+ *
728
+ * This is designed to allow synchronizing a second array with the contents of the backing array,
729
+ * like how in a sourcemap `sourcesContent[i]` is the source content associated with `source[i]`,
730
+ * and there are never duplicates.
731
+ */
732
+ class SetArray {
733
+ constructor() {
734
+ this._indexes = { __proto__: null };
735
+ this.array = [];
736
+ }
737
+ }
738
+ (() => {
739
+ get = (strarr, key) => strarr._indexes[key];
740
+ put = (strarr, key) => {
741
+ // The key may or may not be present. If it is present, it's a number.
742
+ const index = get(strarr, key);
743
+ if (index !== undefined)
744
+ return index;
745
+ const { array, _indexes: indexes } = strarr;
746
+ return (indexes[key] = array.push(key) - 1);
747
+ };
748
+ })();
2401
749
 
2402
- if (typeof mapping.lastGeneratedColumn === "number") {
2403
- mapping.lastGeneratedColumn += columnShift;
2404
- }
750
+ const COLUMN = 0;
751
+ const SOURCES_INDEX = 1;
752
+ const SOURCE_LINE = 2;
753
+ const SOURCE_COLUMN = 3;
754
+ const NAMES_INDEX = 4;
755
+
756
+ const NO_NAME = -1;
757
+ /**
758
+ * Same as `addMapping`, but will only add the mapping if it generates useful information in the
759
+ * resulting map. This only works correctly if mappings are added **in order**, meaning you should
760
+ * not add a mapping with a lower generated line/column than one that came before.
761
+ */
762
+ let maybeAddMapping;
763
+ /**
764
+ * Adds/removes the content of the source file to the source map.
765
+ */
766
+ let setSourceContent;
767
+ /**
768
+ * Returns a sourcemap object (with decoded mappings) suitable for passing to a library that expects
769
+ * a sourcemap, or to JSON.stringify.
770
+ */
771
+ let toDecodedMap;
772
+ /**
773
+ * Returns a sourcemap object (with encoded mappings) suitable for passing to a library that expects
774
+ * a sourcemap, or to JSON.stringify.
775
+ */
776
+ let toEncodedMap;
777
+ // This split declaration is only so that terser can elminiate the static initialization block.
778
+ let addSegmentInternal;
779
+ /**
780
+ * Provides the state to generate a sourcemap.
781
+ */
782
+ class GenMapping {
783
+ constructor({ file, sourceRoot } = {}) {
784
+ this._names = new SetArray();
785
+ this._sources = new SetArray();
786
+ this._sourcesContent = [];
787
+ this._mappings = [];
788
+ this.file = file;
789
+ this.sourceRoot = sourceRoot;
790
+ }
791
+ }
792
+ (() => {
793
+ maybeAddMapping = (map, mapping) => {
794
+ return addMappingInternal(true, map, mapping);
795
+ };
796
+ setSourceContent = (map, source, content) => {
797
+ const { _sources: sources, _sourcesContent: sourcesContent } = map;
798
+ sourcesContent[put(sources, source)] = content;
799
+ };
800
+ toDecodedMap = (map) => {
801
+ const { file, sourceRoot, _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
802
+ removeEmptyFinalLines(mappings);
803
+ return {
804
+ version: 3,
805
+ file: file || undefined,
806
+ names: names.array,
807
+ sourceRoot: sourceRoot || undefined,
808
+ sources: sources.array,
809
+ sourcesContent,
810
+ mappings,
811
+ };
812
+ };
813
+ toEncodedMap = (map) => {
814
+ const decoded = toDecodedMap(map);
815
+ return Object.assign(Object.assign({}, decoded), { mappings: encode(decoded.mappings) });
816
+ };
817
+ // Internal helpers
818
+ addSegmentInternal = (skipable, map, genLine, genColumn, source, sourceLine, sourceColumn, name) => {
819
+ const { _mappings: mappings, _sources: sources, _sourcesContent: sourcesContent, _names: names, } = map;
820
+ const line = getLine(mappings, genLine);
821
+ const index = getColumnIndex(line, genColumn);
822
+ if (!source) {
823
+ if (skipable && skipSourceless(line, index))
824
+ return;
825
+ return insert(line, index, [genColumn]);
826
+ }
827
+ const sourcesIndex = put(sources, source);
828
+ const namesIndex = name ? put(names, name) : NO_NAME;
829
+ if (sourcesIndex === sourcesContent.length)
830
+ sourcesContent[sourcesIndex] = null;
831
+ if (skipable && skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex)) {
832
+ return;
833
+ }
834
+ return insert(line, index, name
835
+ ? [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex]
836
+ : [genColumn, sourcesIndex, sourceLine, sourceColumn]);
837
+ };
838
+ })();
839
+ function getLine(mappings, index) {
840
+ for (let i = mappings.length; i <= index; i++) {
841
+ mappings[i] = [];
2405
842
  }
2406
-
2407
- if (
2408
- mapping.lastGeneratedColumn === Infinity &&
2409
- nextSection &&
2410
- mapping.generatedLine === nextSection.generatedOffset.generatedLine
2411
- ) {
2412
- mapping.lastGeneratedColumn =
2413
- nextSection.generatedOffset.generatedColumn - 2;
843
+ return mappings[index];
844
+ }
845
+ function getColumnIndex(line, genColumn) {
846
+ let index = line.length;
847
+ for (let i = index - 1; i >= 0; index = i--) {
848
+ const current = line[i];
849
+ if (genColumn >= current[COLUMN])
850
+ break;
2414
851
  }
2415
- mapping.generatedLine += lineShift;
2416
-
2417
- aCallback.call(this, mapping);
2418
- }, aContext, aOrder);
2419
- });
2420
- }
2421
-
2422
- computeColumnSpans() {
2423
- for (let i = 0; i < this._sections.length; i++) {
2424
- this._sections[i].consumer.computeColumnSpans();
852
+ return index;
2425
853
  }
2426
- }
2427
-
2428
- destroy() {
2429
- for (let i = 0; i < this._sections.length; i++) {
2430
- this._sections[i].consumer.destroy();
854
+ function insert(array, index, value) {
855
+ for (let i = array.length; i > index; i--) {
856
+ array[i] = array[i - 1];
857
+ }
858
+ array[index] = value;
2431
859
  }
2432
- }
2433
- }
2434
- sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
2435
-
2436
- /*
2437
- * Cheat to get around inter-twingled classes. `factory()` can be at the end
2438
- * where it has access to non-hoisted classes, but it gets hoisted itself.
2439
- */
2440
- function _factory(aSourceMap, aSourceMapURL) {
2441
- let sourceMap = aSourceMap;
2442
- if (typeof aSourceMap === "string") {
2443
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
2444
- }
2445
-
2446
- const consumer = sourceMap.sections != null
2447
- ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
2448
- : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
2449
- return Promise.resolve(consumer);
2450
- }
2451
-
2452
- function _factoryBSM(aSourceMap, aSourceMapURL) {
2453
- return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
2454
- }
2455
-
2456
- var sourceNode = {};
2457
-
2458
- /* -*- Mode: js; js-indent-level: 2; -*- */
2459
-
2460
- /*
2461
- * Copyright 2011 Mozilla Foundation and contributors
2462
- * Licensed under the New BSD license. See LICENSE or:
2463
- * http://opensource.org/licenses/BSD-3-Clause
2464
- */
2465
-
2466
- const SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
2467
- const util = util$4;
2468
-
2469
- // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
2470
- // operating systems these days (capturing the result).
2471
- const REGEX_NEWLINE = /(\r?\n)/;
2472
-
2473
- // Newline character code for charCodeAt() comparisons
2474
- const NEWLINE_CODE = 10;
2475
-
2476
- // Private symbol for identifying `SourceNode`s when multiple versions of
2477
- // the source-map library are loaded. This MUST NOT CHANGE across
2478
- // versions!
2479
- const isSourceNode = "$$$isSourceNode$$$";
2480
-
2481
- /**
2482
- * SourceNodes provide a way to abstract over interpolating/concatenating
2483
- * snippets of generated JavaScript source code while maintaining the line and
2484
- * column information associated with the original source code.
2485
- *
2486
- * @param aLine The original line number.
2487
- * @param aColumn The original column number.
2488
- * @param aSource The original source's filename.
2489
- * @param aChunks Optional. An array of strings which are snippets of
2490
- * generated JS, or other SourceNodes.
2491
- * @param aName The original identifier.
2492
- */
2493
- class SourceNode {
2494
- constructor(aLine, aColumn, aSource, aChunks, aName) {
2495
- this.children = [];
2496
- this.sourceContents = {};
2497
- this.line = aLine == null ? null : aLine;
2498
- this.column = aColumn == null ? null : aColumn;
2499
- this.source = aSource == null ? null : aSource;
2500
- this.name = aName == null ? null : aName;
2501
- this[isSourceNode] = true;
2502
- if (aChunks != null) this.add(aChunks);
2503
- }
2504
-
2505
- /**
2506
- * Creates a SourceNode from generated code and a SourceMapConsumer.
2507
- *
2508
- * @param aGeneratedCode The generated code
2509
- * @param aSourceMapConsumer The SourceMap for the generated code
2510
- * @param aRelativePath Optional. The path that relative sources in the
2511
- * SourceMapConsumer should be relative to.
2512
- */
2513
- static fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
2514
- // The SourceNode we want to fill with the generated code
2515
- // and the SourceMap
2516
- const node = new SourceNode();
2517
-
2518
- // All even indices of this array are one line of the generated code,
2519
- // while all odd indices are the newlines between two adjacent lines
2520
- // (since `REGEX_NEWLINE` captures its match).
2521
- // Processed fragments are accessed by calling `shiftNextLine`.
2522
- const remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
2523
- let remainingLinesIndex = 0;
2524
- const shiftNextLine = function() {
2525
- const lineContents = getNextLine();
2526
- // The last line of a file might not have a newline.
2527
- const newLine = getNextLine() || "";
2528
- return lineContents + newLine;
2529
-
2530
- function getNextLine() {
2531
- return remainingLinesIndex < remainingLines.length ?
2532
- remainingLines[remainingLinesIndex++] : undefined;
2533
- }
2534
- };
2535
-
2536
- // We need to remember the position of "remainingLines"
2537
- let lastGeneratedLine = 1, lastGeneratedColumn = 0;
2538
-
2539
- // The generate SourceNodes we need a code range.
2540
- // To extract it current and last mapping is used.
2541
- // Here we store the last mapping.
2542
- let lastMapping = null;
2543
- let nextLine;
2544
-
2545
- aSourceMapConsumer.eachMapping(function(mapping) {
2546
- if (lastMapping !== null) {
2547
- // We add the code from "lastMapping" to "mapping":
2548
- // First check if there is a new line in between.
2549
- if (lastGeneratedLine < mapping.generatedLine) {
2550
- // Associate first line with "lastMapping"
2551
- addMappingWithCode(lastMapping, shiftNextLine());
2552
- lastGeneratedLine++;
2553
- lastGeneratedColumn = 0;
2554
- // The remaining code is added without mapping
2555
- } else {
2556
- // There is no new line in between.
2557
- // Associate the code between "lastGeneratedColumn" and
2558
- // "mapping.generatedColumn" with "lastMapping"
2559
- nextLine = remainingLines[remainingLinesIndex] || "";
2560
- const code = nextLine.substr(0, mapping.generatedColumn -
2561
- lastGeneratedColumn);
2562
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
2563
- lastGeneratedColumn);
2564
- lastGeneratedColumn = mapping.generatedColumn;
2565
- addMappingWithCode(lastMapping, code);
2566
- // No more remaining code, continue
2567
- lastMapping = mapping;
2568
- return;
2569
- }
2570
- }
2571
- // We add the generated code until the first mapping
2572
- // to the SourceNode without any mapping.
2573
- // Each line is added as separate string.
2574
- while (lastGeneratedLine < mapping.generatedLine) {
2575
- node.add(shiftNextLine());
2576
- lastGeneratedLine++;
2577
- }
2578
- if (lastGeneratedColumn < mapping.generatedColumn) {
2579
- nextLine = remainingLines[remainingLinesIndex] || "";
2580
- node.add(nextLine.substr(0, mapping.generatedColumn));
2581
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
2582
- lastGeneratedColumn = mapping.generatedColumn;
2583
- }
2584
- lastMapping = mapping;
2585
- }, this);
2586
- // We have processed all mappings.
2587
- if (remainingLinesIndex < remainingLines.length) {
2588
- if (lastMapping) {
2589
- // Associate the remaining code in the current line with "lastMapping"
2590
- addMappingWithCode(lastMapping, shiftNextLine());
2591
- }
2592
- // and add the remaining lines without any mapping
2593
- node.add(remainingLines.splice(remainingLinesIndex).join(""));
2594
- }
2595
-
2596
- // Copy sourcesContent into SourceNode
2597
- aSourceMapConsumer.sources.forEach(function(sourceFile) {
2598
- const content = aSourceMapConsumer.sourceContentFor(sourceFile);
2599
- if (content != null) {
2600
- if (aRelativePath != null) {
2601
- sourceFile = util.join(aRelativePath, sourceFile);
2602
- }
2603
- node.setSourceContent(sourceFile, content);
2604
- }
2605
- });
2606
-
2607
- return node;
2608
-
2609
- function addMappingWithCode(mapping, code) {
2610
- if (mapping === null || mapping.source === undefined) {
2611
- node.add(code);
2612
- } else {
2613
- const source = aRelativePath
2614
- ? util.join(aRelativePath, mapping.source)
2615
- : mapping.source;
2616
- node.add(new SourceNode(mapping.originalLine,
2617
- mapping.originalColumn,
2618
- source,
2619
- code,
2620
- mapping.name));
2621
- }
2622
- }
2623
- }
2624
-
2625
- /**
2626
- * Add a chunk of generated JS to this source node.
2627
- *
2628
- * @param aChunk A string snippet of generated JS code, another instance of
2629
- * SourceNode, or an array where each member is one of those things.
2630
- */
2631
- add(aChunk) {
2632
- if (Array.isArray(aChunk)) {
2633
- aChunk.forEach(function(chunk) {
2634
- this.add(chunk);
2635
- }, this);
2636
- } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2637
- if (aChunk) {
2638
- this.children.push(aChunk);
2639
- }
2640
- } else {
2641
- throw new TypeError(
2642
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2643
- );
860
+ function removeEmptyFinalLines(mappings) {
861
+ const { length } = mappings;
862
+ let len = length;
863
+ for (let i = len - 1; i >= 0; len = i, i--) {
864
+ if (mappings[i].length > 0)
865
+ break;
866
+ }
867
+ if (len < length)
868
+ mappings.length = len;
2644
869
  }
2645
- return this;
2646
- }
2647
-
2648
- /**
2649
- * Add a chunk of generated JS to the beginning of this source node.
2650
- *
2651
- * @param aChunk A string snippet of generated JS code, another instance of
2652
- * SourceNode, or an array where each member is one of those things.
2653
- */
2654
- prepend(aChunk) {
2655
- if (Array.isArray(aChunk)) {
2656
- for (let i = aChunk.length - 1; i >= 0; i--) {
2657
- this.prepend(aChunk[i]);
2658
- }
2659
- } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2660
- this.children.unshift(aChunk);
2661
- } else {
2662
- throw new TypeError(
2663
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2664
- );
870
+ function skipSourceless(line, index) {
871
+ // The start of a line is already sourceless, so adding a sourceless segment to the beginning
872
+ // doesn't generate any useful information.
873
+ if (index === 0)
874
+ return true;
875
+ const prev = line[index - 1];
876
+ // If the previous segment is also sourceless, then adding another sourceless segment doesn't
877
+ // genrate any new information. Else, this segment will end the source/named segment and point to
878
+ // a sourceless position, which is useful.
879
+ return prev.length === 1;
880
+ }
881
+ function skipSource(line, index, sourcesIndex, sourceLine, sourceColumn, namesIndex) {
882
+ // A source/named segment at the start of a line gives position at that genColumn
883
+ if (index === 0)
884
+ return false;
885
+ const prev = line[index - 1];
886
+ // If the previous segment is sourceless, then we're transitioning to a source.
887
+ if (prev.length === 1)
888
+ return false;
889
+ // If the previous segment maps to the exact same source position, then this segment doesn't
890
+ // provide any new position information.
891
+ return (sourcesIndex === prev[SOURCES_INDEX] &&
892
+ sourceLine === prev[SOURCE_LINE] &&
893
+ sourceColumn === prev[SOURCE_COLUMN] &&
894
+ namesIndex === (prev.length === 5 ? prev[NAMES_INDEX] : NO_NAME));
2665
895
  }
2666
- return this;
2667
- }
2668
-
2669
- /**
2670
- * Walk over the tree of JS snippets in this node and its children. The
2671
- * walking function is called once for each snippet of JS and is passed that
2672
- * snippet and the its original associated source's line/column location.
2673
- *
2674
- * @param aFn The traversal function.
2675
- */
2676
- walk(aFn) {
2677
- let chunk;
2678
- for (let i = 0, len = this.children.length; i < len; i++) {
2679
- chunk = this.children[i];
2680
- if (chunk[isSourceNode]) {
2681
- chunk.walk(aFn);
2682
- } else if (chunk !== "") {
2683
- aFn(chunk, { source: this.source,
2684
- line: this.line,
2685
- column: this.column,
2686
- name: this.name });
2687
- }
2688
- }
2689
- }
2690
-
2691
- /**
2692
- * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
2693
- * each of `this.children`.
2694
- *
2695
- * @param aSep The separator.
2696
- */
2697
- join(aSep) {
2698
- let newChildren;
2699
- let i;
2700
- const len = this.children.length;
2701
- if (len > 0) {
2702
- newChildren = [];
2703
- for (i = 0; i < len - 1; i++) {
2704
- newChildren.push(this.children[i]);
2705
- newChildren.push(aSep);
2706
- }
2707
- newChildren.push(this.children[i]);
2708
- this.children = newChildren;
896
+ function addMappingInternal(skipable, map, mapping) {
897
+ const { generated, source, original, name } = mapping;
898
+ if (!source) {
899
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, null, null, null, null);
900
+ }
901
+ const s = source;
902
+ return addSegmentInternal(skipable, map, generated.line - 1, generated.column, s, original.line - 1, original.column, name);
2709
903
  }
2710
- return this;
2711
- }
2712
-
2713
- /**
2714
- * Call String.prototype.replace on the very right-most source snippet. Useful
2715
- * for trimming whitespace from the end of a source node, etc.
2716
- *
2717
- * @param aPattern The pattern to replace.
2718
- * @param aReplacement The thing to replace the pattern with.
2719
- */
2720
- replaceRight(aPattern, aReplacement) {
2721
- const lastChild = this.children[this.children.length - 1];
2722
- if (lastChild[isSourceNode]) {
2723
- lastChild.replaceRight(aPattern, aReplacement);
2724
- } else if (typeof lastChild === "string") {
2725
- this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
2726
- } else {
2727
- this.children.push("".replace(aPattern, aReplacement));
904
+
905
+ class SourceMapConsumer {
906
+ constructor(map, mapUrl) {
907
+ const trace = (this._map = new AnyMap(map, mapUrl));
908
+ this.file = trace.file;
909
+ this.names = trace.names;
910
+ this.sourceRoot = trace.sourceRoot;
911
+ this.sources = trace.resolvedSources;
912
+ this.sourcesContent = trace.sourcesContent;
913
+ }
914
+ originalPositionFor(needle) {
915
+ return originalPositionFor(this._map, needle);
916
+ }
917
+ destroy() {
918
+ // noop.
919
+ }
2728
920
  }
2729
- return this;
2730
- }
2731
-
2732
- /**
2733
- * Set the source content for a source file. This will be added to the SourceMapGenerator
2734
- * in the sourcesContent field.
2735
- *
2736
- * @param aSourceFile The filename of the source file
2737
- * @param aSourceContent The content of the source file
2738
- */
2739
- setSourceContent(aSourceFile, aSourceContent) {
2740
- this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
2741
- }
2742
-
2743
- /**
2744
- * Walk over the tree of SourceNodes. The walking function is called for each
2745
- * source file content and is passed the filename and source content.
2746
- *
2747
- * @param aFn The traversal function.
2748
- */
2749
- walkSourceContents(aFn) {
2750
- for (let i = 0, len = this.children.length; i < len; i++) {
2751
- if (this.children[i][isSourceNode]) {
2752
- this.children[i].walkSourceContents(aFn);
2753
- }
2754
- }
2755
-
2756
- const sources = Object.keys(this.sourceContents);
2757
- for (let i = 0, len = sources.length; i < len; i++) {
2758
- aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
2759
- }
2760
- }
2761
-
2762
- /**
2763
- * Return the string representation of this source node. Walks over the tree
2764
- * and concatenates all the various snippets together to one string.
2765
- */
2766
- toString() {
2767
- let str = "";
2768
- this.walk(function(chunk) {
2769
- str += chunk;
2770
- });
2771
- return str;
2772
- }
2773
-
2774
- /**
2775
- * Returns the string representation of this source node along with a source
2776
- * map.
2777
- */
2778
- toStringWithSourceMap(aArgs) {
2779
- const generated = {
2780
- code: "",
2781
- line: 1,
2782
- column: 0
2783
- };
2784
- const map = new SourceMapGenerator(aArgs);
2785
- let sourceMappingActive = false;
2786
- let lastOriginalSource = null;
2787
- let lastOriginalLine = null;
2788
- let lastOriginalColumn = null;
2789
- let lastOriginalName = null;
2790
- this.walk(function(chunk, original) {
2791
- generated.code += chunk;
2792
- if (original.source !== null
2793
- && original.line !== null
2794
- && original.column !== null) {
2795
- if (lastOriginalSource !== original.source
2796
- || lastOriginalLine !== original.line
2797
- || lastOriginalColumn !== original.column
2798
- || lastOriginalName !== original.name) {
2799
- map.addMapping({
2800
- source: original.source,
2801
- original: {
2802
- line: original.line,
2803
- column: original.column
2804
- },
2805
- generated: {
2806
- line: generated.line,
2807
- column: generated.column
2808
- },
2809
- name: original.name
2810
- });
2811
- }
2812
- lastOriginalSource = original.source;
2813
- lastOriginalLine = original.line;
2814
- lastOriginalColumn = original.column;
2815
- lastOriginalName = original.name;
2816
- sourceMappingActive = true;
2817
- } else if (sourceMappingActive) {
2818
- map.addMapping({
2819
- generated: {
2820
- line: generated.line,
2821
- column: generated.column
2822
- }
2823
- });
2824
- lastOriginalSource = null;
2825
- sourceMappingActive = false;
2826
- }
2827
- for (let idx = 0, length = chunk.length; idx < length; idx++) {
2828
- if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
2829
- generated.line++;
2830
- generated.column = 0;
2831
- // Mappings end at eol
2832
- if (idx + 1 === length) {
2833
- lastOriginalSource = null;
2834
- sourceMappingActive = false;
2835
- } else if (sourceMappingActive) {
2836
- map.addMapping({
2837
- source: original.source,
2838
- original: {
2839
- line: original.line,
2840
- column: original.column
2841
- },
2842
- generated: {
2843
- line: generated.line,
2844
- column: generated.column
2845
- },
2846
- name: original.name
2847
- });
2848
- }
2849
- } else {
2850
- generated.column++;
921
+ class SourceMapGenerator {
922
+ constructor(opts) {
923
+ this._map = new GenMapping(opts);
2851
924
  }
2852
- }
2853
- });
2854
- this.walkSourceContents(function(sourceFile, sourceContent) {
2855
- map.setSourceContent(sourceFile, sourceContent);
2856
- });
925
+ addMapping(mapping) {
926
+ maybeAddMapping(this._map, mapping);
927
+ }
928
+ setSourceContent(source, content) {
929
+ setSourceContent(this._map, source, content);
930
+ }
931
+ toJSON() {
932
+ return toEncodedMap(this._map);
933
+ }
934
+ toDecodedMap() {
935
+ return toDecodedMap(this._map);
936
+ }
937
+ }
2857
938
 
2858
- return { code: generated.code, map };
2859
- }
2860
- }
939
+ exports.SourceMapConsumer = SourceMapConsumer;
940
+ exports.SourceMapGenerator = SourceMapGenerator;
2861
941
 
2862
- sourceNode.SourceNode = SourceNode;
942
+ Object.defineProperty(exports, '__esModule', { value: true });
2863
943
 
2864
- /*
2865
- * Copyright 2009-2011 Mozilla Foundation and contributors
2866
- * Licensed under the New BSD license. See LICENSE.txt or:
2867
- * http://opensource.org/licenses/BSD-3-Clause
2868
- */
944
+ }));
2869
945
 
2870
- sourceMap.SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
2871
- sourceMap.SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
2872
- sourceMap.SourceNode = sourceNode.SourceNode;
946
+ }(sourceMap_umd, sourceMap_umd.exports));
2873
947
 
2874
948
  (function (module, exports) {
2875
949
  (function (global, factory) {
2876
- factory(exports, sourceMap) ;
2877
- }(commonjsGlobal, (function (exports, MOZ_SourceMap) {
2878
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
2879
-
2880
- var MOZ_SourceMap__default = /*#__PURE__*/_interopDefaultLegacy(MOZ_SourceMap);
2881
-
950
+ factory(exports, sourceMap_umd.exports) ;
951
+ }(commonjsGlobal, (function (exports, sourceMap) {
2882
952
  /***********************************************************************
2883
953
 
2884
954
  A JavaScript tokenizer / parser / beautifier / compressor.
@@ -6930,11 +5000,10 @@ var AST_With = DEFNODE("With", "expression", function AST_With(props) {
6930
5000
 
6931
5001
  var AST_Scope = DEFNODE(
6932
5002
  "Scope",
6933
- "variables functions uses_with uses_eval parent_scope enclosed cname",
5003
+ "variables uses_with uses_eval parent_scope enclosed cname",
6934
5004
  function AST_Scope(props) {
6935
5005
  if (props) {
6936
5006
  this.variables = props.variables;
6937
- this.functions = props.functions;
6938
5007
  this.uses_with = props.uses_with;
6939
5008
  this.uses_eval = props.uses_eval;
6940
5009
  this.parent_scope = props.parent_scope;
@@ -6990,7 +5059,6 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", function AST_Toplevel(props) {
6990
5059
  if (props) {
6991
5060
  this.globals = props.globals;
6992
5061
  this.variables = props.variables;
6993
- this.functions = props.functions;
6994
5062
  this.uses_with = props.uses_with;
6995
5063
  this.uses_eval = props.uses_eval;
6996
5064
  this.parent_scope = props.parent_scope;
@@ -7072,7 +5140,6 @@ var AST_Lambda = DEFNODE(
7072
5140
  this.is_generator = props.is_generator;
7073
5141
  this.async = props.async;
7074
5142
  this.variables = props.variables;
7075
- this.functions = props.functions;
7076
5143
  this.uses_with = props.uses_with;
7077
5144
  this.uses_eval = props.uses_eval;
7078
5145
  this.parent_scope = props.parent_scope;
@@ -7152,7 +5219,6 @@ var AST_Accessor = DEFNODE("Accessor", null, function AST_Accessor(props) {
7152
5219
  this.is_generator = props.is_generator;
7153
5220
  this.async = props.async;
7154
5221
  this.variables = props.variables;
7155
- this.functions = props.functions;
7156
5222
  this.uses_with = props.uses_with;
7157
5223
  this.uses_eval = props.uses_eval;
7158
5224
  this.parent_scope = props.parent_scope;
@@ -7177,7 +5243,6 @@ var AST_Function = DEFNODE("Function", null, function AST_Function(props) {
7177
5243
  this.is_generator = props.is_generator;
7178
5244
  this.async = props.async;
7179
5245
  this.variables = props.variables;
7180
- this.functions = props.functions;
7181
5246
  this.uses_with = props.uses_with;
7182
5247
  this.uses_eval = props.uses_eval;
7183
5248
  this.parent_scope = props.parent_scope;
@@ -7202,7 +5267,6 @@ var AST_Arrow = DEFNODE("Arrow", null, function AST_Arrow(props) {
7202
5267
  this.is_generator = props.is_generator;
7203
5268
  this.async = props.async;
7204
5269
  this.variables = props.variables;
7205
- this.functions = props.functions;
7206
5270
  this.uses_with = props.uses_with;
7207
5271
  this.uses_eval = props.uses_eval;
7208
5272
  this.parent_scope = props.parent_scope;
@@ -7227,7 +5291,6 @@ var AST_Defun = DEFNODE("Defun", null, function AST_Defun(props) {
7227
5291
  this.is_generator = props.is_generator;
7228
5292
  this.async = props.async;
7229
5293
  this.variables = props.variables;
7230
- this.functions = props.functions;
7231
5294
  this.uses_with = props.uses_with;
7232
5295
  this.uses_eval = props.uses_eval;
7233
5296
  this.parent_scope = props.parent_scope;
@@ -8539,7 +6602,6 @@ var AST_Class = DEFNODE("Class", "name extends properties", function AST_Class(p
8539
6602
  this.extends = props.extends;
8540
6603
  this.properties = props.properties;
8541
6604
  this.variables = props.variables;
8542
- this.functions = props.functions;
8543
6605
  this.uses_with = props.uses_with;
8544
6606
  this.uses_eval = props.uses_eval;
8545
6607
  this.parent_scope = props.parent_scope;
@@ -8633,7 +6695,6 @@ var AST_DefClass = DEFNODE("DefClass", null, function AST_DefClass(props) {
8633
6695
  this.extends = props.extends;
8634
6696
  this.properties = props.properties;
8635
6697
  this.variables = props.variables;
8636
- this.functions = props.functions;
8637
6698
  this.uses_with = props.uses_with;
8638
6699
  this.uses_eval = props.uses_eval;
8639
6700
  this.parent_scope = props.parent_scope;
@@ -8656,7 +6717,6 @@ var AST_ClassExpression = DEFNODE("ClassExpression", null, function AST_ClassExp
8656
6717
  this.extends = props.extends;
8657
6718
  this.properties = props.properties;
8658
6719
  this.variables = props.variables;
8659
- this.functions = props.functions;
8660
6720
  this.uses_with = props.uses_with;
8661
6721
  this.uses_eval = props.uses_eval;
8662
6722
  this.parent_scope = props.parent_scope;
@@ -11515,6 +9575,8 @@ function OutputStream(options) {
11515
9575
  width : 80,
11516
9576
  wrap_iife : false,
11517
9577
  wrap_func_args : true,
9578
+
9579
+ _destroy_ast : false
11518
9580
  }, true);
11519
9581
 
11520
9582
  if (options.shorthand === undefined)
@@ -12064,6 +10126,18 @@ function OutputStream(options) {
12064
10126
  if (OUTPUT.length() > insert) newline_insert = insert;
12065
10127
  }
12066
10128
 
10129
+ /**
10130
+ * When output.option("_destroy_ast") is enabled, destroy the function.
10131
+ * Call this after printing it.
10132
+ */
10133
+ const gc_scope =
10134
+ options["_destroy_ast"]
10135
+ ? function gc_scope(scope) {
10136
+ scope.body.length = 0;
10137
+ scope.argnames.length = 0;
10138
+ }
10139
+ : noop;
10140
+
12067
10141
  var stack = [];
12068
10142
  return {
12069
10143
  get : get,
@@ -12110,6 +10184,7 @@ function OutputStream(options) {
12110
10184
  with_square : with_square,
12111
10185
  add_mapping : add_mapping,
12112
10186
  option : function(opt) { return options[opt]; },
10187
+ gc_scope,
12113
10188
  printed_comments: printed_comments,
12114
10189
  prepend_comments: readonly ? noop : prepend_comments,
12115
10190
  append_comments : readonly || comment_filter === return_false ? noop : append_comments,
@@ -12626,6 +10701,7 @@ function OutputStream(options) {
12626
10701
  });
12627
10702
  DEFPRINT(AST_Lambda, function(self, output) {
12628
10703
  self._do_print(output);
10704
+ output.gc_scope(self);
12629
10705
  });
12630
10706
 
12631
10707
  DEFPRINT(AST_PrefixedTemplateString, function(self, output) {
@@ -12705,6 +10781,7 @@ function OutputStream(options) {
12705
10781
  print_braced(self, output);
12706
10782
  }
12707
10783
  if (needs_parens) { output.print(")"); }
10784
+ output.gc_scope(self);
12708
10785
  });
12709
10786
 
12710
10787
  /* -----[ exits ]----- */
@@ -23892,40 +21969,56 @@ def_optimize(AST_Destructuring, function(self, compressor) {
23892
21969
 
23893
21970
  ***********************************************************************/
23894
21971
 
23895
- // a small wrapper around fitzgen's source-map library
21972
+ // a small wrapper around source-map and @jridgewell/source-map
23896
21973
  async function SourceMap(options) {
23897
21974
  options = defaults(options, {
23898
21975
  file : null,
23899
21976
  root : null,
23900
21977
  orig : null,
23901
-
23902
- orig_line_diff : 0,
23903
- dest_line_diff : 0,
21978
+ files: {},
23904
21979
  });
23905
21980
 
23906
21981
  var orig_map;
23907
- var generator = new MOZ_SourceMap__default['default'].SourceMapGenerator({
21982
+ var generator = new sourceMap.SourceMapGenerator({
23908
21983
  file : options.file,
23909
21984
  sourceRoot : options.root
23910
21985
  });
23911
21986
 
21987
+ let sourcesContent = {__proto__: null};
21988
+ let files = options.files;
21989
+ for (var name in files) if (HOP(files, name)) {
21990
+ sourcesContent[name] = files[name];
21991
+ }
23912
21992
  if (options.orig) {
23913
- orig_map = await new MOZ_SourceMap__default['default'].SourceMapConsumer(options.orig);
23914
- orig_map.sources.forEach(function(source) {
23915
- var sourceContent = orig_map.sourceContentFor(source, true);
23916
- if (sourceContent) {
23917
- generator.setSourceContent(source, sourceContent);
23918
- }
23919
- });
21993
+ // We support both @jridgewell/source-map (which has a sync
21994
+ // SourceMapConsumer) and source-map (which has an async
21995
+ // SourceMapConsumer).
21996
+ orig_map = await new sourceMap.SourceMapConsumer(options.orig);
21997
+ if (orig_map.sourcesContent) {
21998
+ orig_map.sources.forEach(function(source, i) {
21999
+ var content = orig_map.sourcesContent[i];
22000
+ if (content) {
22001
+ sourcesContent[source] = content;
22002
+ }
22003
+ });
22004
+ }
23920
22005
  }
23921
22006
 
23922
22007
  function add(source, gen_line, gen_col, orig_line, orig_col, name) {
22008
+ let generatedPos = { line: gen_line, column: gen_col };
22009
+
23923
22010
  if (orig_map) {
23924
22011
  var info = orig_map.originalPositionFor({
23925
22012
  line: orig_line,
23926
22013
  column: orig_col
23927
22014
  });
23928
22015
  if (info.source === null) {
22016
+ generator.addMapping({
22017
+ generated: generatedPos,
22018
+ original: null,
22019
+ source: null,
22020
+ name: null
22021
+ });
23929
22022
  return;
23930
22023
  }
23931
22024
  source = info.source;
@@ -23934,22 +22027,42 @@ async function SourceMap(options) {
23934
22027
  name = info.name || name;
23935
22028
  }
23936
22029
  generator.addMapping({
23937
- generated : { line: gen_line + options.dest_line_diff, column: gen_col },
23938
- original : { line: orig_line + options.orig_line_diff, column: orig_col },
22030
+ generated : generatedPos,
22031
+ original : { line: orig_line, column: orig_col },
23939
22032
  source : source,
23940
22033
  name : name
23941
22034
  });
22035
+ generator.setSourceContent(source, sourcesContent[source]);
22036
+ }
22037
+
22038
+ function clean(map) {
22039
+ const allNull = map.sourcesContent && map.sourcesContent.every(c => c == null);
22040
+ if (allNull) delete map.sourcesContent;
22041
+ if (map.file === undefined) delete map.file;
22042
+ if (map.sourceRoot === undefined) delete map.sourceRoot;
22043
+ return map;
22044
+ }
22045
+
22046
+ function getDecoded() {
22047
+ if (!generator.toDecodedMap) return null;
22048
+ return clean(generator.toDecodedMap());
22049
+ }
22050
+
22051
+ function getEncoded() {
22052
+ return clean(generator.toJSON());
22053
+ }
22054
+
22055
+ function destroy() {
22056
+ // @jridgewell/source-map's SourceMapConsumer does not need to be
22057
+ // manually freed.
22058
+ if (orig_map && orig_map.destroy) orig_map.destroy();
23942
22059
  }
23943
22060
 
23944
22061
  return {
23945
- add : add,
23946
- get : function() { return generator; },
23947
- toString : function() { return generator.toString(); },
23948
- destroy : function () {
23949
- if (orig_map && orig_map.destroy) {
23950
- orig_map.destroy();
23951
- }
23952
- }
22062
+ add,
22063
+ getDecoded,
22064
+ getEncoded,
22065
+ destroy,
23953
22066
  };
23954
22067
  }
23955
22068
 
@@ -24275,6 +22388,7 @@ var domprops = [
24275
22388
  "COMMENT_NODE",
24276
22389
  "COMPARE_REF_TO_TEXTURE",
24277
22390
  "COMPILE_STATUS",
22391
+ "COMPLETION_STATUS_KHR",
24278
22392
  "COMPRESSED_RGBA_S3TC_DXT1_EXT",
24279
22393
  "COMPRESSED_RGBA_S3TC_DXT3_EXT",
24280
22394
  "COMPRESSED_RGBA_S3TC_DXT5_EXT",
@@ -32250,6 +30364,8 @@ async function minify(files, options, _fs_module) {
32250
30364
  url: null,
32251
30365
  }, true);
32252
30366
  }
30367
+
30368
+ // -- Parse phase --
32253
30369
  if (timings) timings.parse = Date.now();
32254
30370
  var toplevel;
32255
30371
  if (files instanceof AST_Toplevel) {
@@ -32293,12 +30409,16 @@ async function minify(files, options, _fs_module) {
32293
30409
  toplevel = toplevel.wrap_enclose(options.enclose);
32294
30410
  }
32295
30411
  if (timings) timings.rename = Date.now();
30412
+
30413
+ // -- Compress phase --
32296
30414
  if (timings) timings.compress = Date.now();
32297
30415
  if (options.compress) {
32298
30416
  toplevel = new Compressor(options.compress, {
32299
30417
  mangle_options: options.mangle
32300
30418
  }).compress(toplevel);
32301
30419
  }
30420
+
30421
+ // -- Mangle phase --
32302
30422
  if (timings) timings.scope = Date.now();
32303
30423
  if (options.mangle) toplevel.figure_out_scope(options.mangle);
32304
30424
  if (timings) timings.mangle = Date.now();
@@ -32311,6 +30431,8 @@ async function minify(files, options, _fs_module) {
32311
30431
  if (options.mangle && options.mangle.properties) {
32312
30432
  toplevel = mangle_properties(toplevel, options.mangle.properties);
32313
30433
  }
30434
+
30435
+ // Format phase
32314
30436
  if (timings) timings.format = Date.now();
32315
30437
  var result = {};
32316
30438
  if (options.format.ast) {
@@ -32320,19 +30442,34 @@ async function minify(files, options, _fs_module) {
32320
30442
  result.ast = toplevel.to_mozilla_ast();
32321
30443
  }
32322
30444
  if (!HOP(options.format, "code") || options.format.code) {
30445
+ if (!options.format.ast) {
30446
+ // Destroy stuff to save RAM. (unless the deprecated `ast` option is on)
30447
+ options.format._destroy_ast = true;
30448
+
30449
+ walk(toplevel, node => {
30450
+ if (node instanceof AST_Scope) {
30451
+ node.variables = undefined;
30452
+ node.enclosed = undefined;
30453
+ node.parent_scope = undefined;
30454
+ }
30455
+ if (node.block_scope) {
30456
+ node.block_scope.variables = undefined;
30457
+ node.block_scope.enclosed = undefined;
30458
+ node.parent_scope = undefined;
30459
+ }
30460
+ });
30461
+ }
30462
+
32323
30463
  if (options.sourceMap) {
30464
+ if (options.sourceMap.includeSources && files instanceof AST_Toplevel) {
30465
+ throw new Error("original source content unavailable");
30466
+ }
32324
30467
  options.format.source_map = await SourceMap({
32325
30468
  file: options.sourceMap.filename,
32326
30469
  orig: options.sourceMap.content,
32327
- root: options.sourceMap.root
30470
+ root: options.sourceMap.root,
30471
+ files: options.sourceMap.includeSources ? files : null,
32328
30472
  });
32329
- if (options.sourceMap.includeSources) {
32330
- if (files instanceof AST_Toplevel) {
32331
- throw new Error("original source content unavailable");
32332
- } else for (var name in files) if (HOP(files, name)) {
32333
- options.format.source_map.get().setSourceContent(name, files[name]);
32334
- }
32335
- }
32336
30473
  }
32337
30474
  delete options.format.ast;
32338
30475
  delete options.format.code;
@@ -32341,11 +30478,21 @@ async function minify(files, options, _fs_module) {
32341
30478
  toplevel.print(stream);
32342
30479
  result.code = stream.get();
32343
30480
  if (options.sourceMap) {
32344
- if(options.sourceMap.asObject) {
32345
- result.map = options.format.source_map.get().toJSON();
32346
- } else {
32347
- result.map = options.format.source_map.toString();
32348
- }
30481
+ Object.defineProperty(result, "map", {
30482
+ configurable: true,
30483
+ enumerable: true,
30484
+ get() {
30485
+ const map = options.format.source_map.getEncoded();
30486
+ return (result.map = options.sourceMap.asObject ? map : JSON.stringify(map));
30487
+ },
30488
+ set(value) {
30489
+ Object.defineProperty(result, "map", {
30490
+ value,
30491
+ writable: true,
30492
+ });
30493
+ }
30494
+ });
30495
+ result.decoded_map = options.format.source_map.getDecoded();
32349
30496
  if (options.sourceMap.url == "inline") {
32350
30497
  var sourceMap = typeof result.map === "object" ? JSON.stringify(result.map) : result.map;
32351
30498
  result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(sourceMap);