@intlify/message-compiler 9.2.0-beta.3 → 9.2.0-beta.30

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,6 +1,6 @@
1
1
  /*!
2
- * message-compiler v9.2.0-beta.3
3
- * (c) 2021 kazuya kawaguchi
2
+ * message-compiler v9.2.0-beta.30
3
+ * (c) 2022 kazuya kawaguchi
4
4
  * Released under the MIT License.
5
5
  */
6
6
  /**
@@ -447,49 +447,44 @@ function createTokenizer(source, options = {}) {
447
447
  return num;
448
448
  }
449
449
  function readText(scnr) {
450
- const fn = (buf) => {
450
+ let buf = '';
451
+ while (true) {
451
452
  const ch = scnr.currentChar();
452
453
  if (ch === "{" /* BraceLeft */ ||
453
454
  ch === "}" /* BraceRight */ ||
454
455
  ch === "@" /* LinkedAlias */ ||
456
+ ch === "|" /* Pipe */ ||
455
457
  !ch) {
456
- return buf;
458
+ break;
457
459
  }
458
460
  else if (ch === "%" /* Modulo */) {
459
461
  if (isTextStart(scnr)) {
460
462
  buf += ch;
461
463
  scnr.next();
462
- return fn(buf);
463
464
  }
464
465
  else {
465
- return buf;
466
+ break;
466
467
  }
467
468
  }
468
- else if (ch === "|" /* Pipe */) {
469
- return buf;
470
- }
471
469
  else if (ch === CHAR_SP || ch === CHAR_LF) {
472
470
  if (isTextStart(scnr)) {
473
471
  buf += ch;
474
472
  scnr.next();
475
- return fn(buf);
476
473
  }
477
474
  else if (isPluralStart(scnr)) {
478
- return buf;
475
+ break;
479
476
  }
480
477
  else {
481
478
  buf += ch;
482
479
  scnr.next();
483
- return fn(buf);
484
480
  }
485
481
  }
486
482
  else {
487
483
  buf += ch;
488
484
  scnr.next();
489
- return fn(buf);
490
485
  }
491
- };
492
- return fn('');
486
+ }
487
+ return buf;
493
488
  }
494
489
  function readNamedIdentifier(scnr) {
495
490
  skipSpaces(scnr);
@@ -1181,3165 +1176,6 @@ function transform(ast, options = {} // eslint-disable-line
1181
1176
  ast.helpers = Array.from(context.helpers);
1182
1177
  }
1183
1178
 
1184
- var sourceMap = {};
1185
-
1186
- var sourceMapGenerator = {};
1187
-
1188
- var base64Vlq = {};
1189
-
1190
- var base64$1 = {};
1191
-
1192
- /* -*- Mode: js; js-indent-level: 2; -*- */
1193
-
1194
- /*
1195
- * Copyright 2011 Mozilla Foundation and contributors
1196
- * Licensed under the New BSD license. See LICENSE or:
1197
- * http://opensource.org/licenses/BSD-3-Clause
1198
- */
1199
-
1200
- var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
1201
-
1202
- /**
1203
- * Encode an integer in the range of 0 to 63 to a single base 64 digit.
1204
- */
1205
- base64$1.encode = function (number) {
1206
- if (0 <= number && number < intToCharMap.length) {
1207
- return intToCharMap[number];
1208
- }
1209
- throw new TypeError("Must be between 0 and 63: " + number);
1210
- };
1211
-
1212
- /**
1213
- * Decode a single base 64 character code digit to an integer. Returns -1 on
1214
- * failure.
1215
- */
1216
- base64$1.decode = function (charCode) {
1217
- var bigA = 65; // 'A'
1218
- var bigZ = 90; // 'Z'
1219
-
1220
- var littleA = 97; // 'a'
1221
- var littleZ = 122; // 'z'
1222
-
1223
- var zero = 48; // '0'
1224
- var nine = 57; // '9'
1225
-
1226
- var plus = 43; // '+'
1227
- var slash = 47; // '/'
1228
-
1229
- var littleOffset = 26;
1230
- var numberOffset = 52;
1231
-
1232
- // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
1233
- if (bigA <= charCode && charCode <= bigZ) {
1234
- return (charCode - bigA);
1235
- }
1236
-
1237
- // 26 - 51: abcdefghijklmnopqrstuvwxyz
1238
- if (littleA <= charCode && charCode <= littleZ) {
1239
- return (charCode - littleA + littleOffset);
1240
- }
1241
-
1242
- // 52 - 61: 0123456789
1243
- if (zero <= charCode && charCode <= nine) {
1244
- return (charCode - zero + numberOffset);
1245
- }
1246
-
1247
- // 62: +
1248
- if (charCode == plus) {
1249
- return 62;
1250
- }
1251
-
1252
- // 63: /
1253
- if (charCode == slash) {
1254
- return 63;
1255
- }
1256
-
1257
- // Invalid base64 digit.
1258
- return -1;
1259
- };
1260
-
1261
- /* -*- Mode: js; js-indent-level: 2; -*- */
1262
-
1263
- /*
1264
- * Copyright 2011 Mozilla Foundation and contributors
1265
- * Licensed under the New BSD license. See LICENSE or:
1266
- * http://opensource.org/licenses/BSD-3-Clause
1267
- *
1268
- * Based on the Base 64 VLQ implementation in Closure Compiler:
1269
- * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
1270
- *
1271
- * Copyright 2011 The Closure Compiler Authors. All rights reserved.
1272
- * Redistribution and use in source and binary forms, with or without
1273
- * modification, are permitted provided that the following conditions are
1274
- * met:
1275
- *
1276
- * * Redistributions of source code must retain the above copyright
1277
- * notice, this list of conditions and the following disclaimer.
1278
- * * Redistributions in binary form must reproduce the above
1279
- * copyright notice, this list of conditions and the following
1280
- * disclaimer in the documentation and/or other materials provided
1281
- * with the distribution.
1282
- * * Neither the name of Google Inc. nor the names of its
1283
- * contributors may be used to endorse or promote products derived
1284
- * from this software without specific prior written permission.
1285
- *
1286
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1287
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1288
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1289
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1290
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1291
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1292
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1293
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1294
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1295
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1296
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1297
- */
1298
-
1299
- var base64 = base64$1;
1300
-
1301
- // A single base 64 digit can contain 6 bits of data. For the base 64 variable
1302
- // length quantities we use in the source map spec, the first bit is the sign,
1303
- // the next four bits are the actual value, and the 6th bit is the
1304
- // continuation bit. The continuation bit tells us whether there are more
1305
- // digits in this value following this digit.
1306
- //
1307
- // Continuation
1308
- // | Sign
1309
- // | |
1310
- // V V
1311
- // 101011
1312
-
1313
- var VLQ_BASE_SHIFT = 5;
1314
-
1315
- // binary: 100000
1316
- var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
1317
-
1318
- // binary: 011111
1319
- var VLQ_BASE_MASK = VLQ_BASE - 1;
1320
-
1321
- // binary: 100000
1322
- var VLQ_CONTINUATION_BIT = VLQ_BASE;
1323
-
1324
- /**
1325
- * Converts from a two-complement value to a value where the sign bit is
1326
- * placed in the least significant bit. For example, as decimals:
1327
- * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
1328
- * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
1329
- */
1330
- function toVLQSigned(aValue) {
1331
- return aValue < 0
1332
- ? ((-aValue) << 1) + 1
1333
- : (aValue << 1) + 0;
1334
- }
1335
-
1336
- /**
1337
- * Converts to a two-complement value from a value where the sign bit is
1338
- * placed in the least significant bit. For example, as decimals:
1339
- * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
1340
- * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
1341
- */
1342
- function fromVLQSigned(aValue) {
1343
- var isNegative = (aValue & 1) === 1;
1344
- var shifted = aValue >> 1;
1345
- return isNegative
1346
- ? -shifted
1347
- : shifted;
1348
- }
1349
-
1350
- /**
1351
- * Returns the base 64 VLQ encoded value.
1352
- */
1353
- base64Vlq.encode = function base64VLQ_encode(aValue) {
1354
- var encoded = "";
1355
- var digit;
1356
-
1357
- var vlq = toVLQSigned(aValue);
1358
-
1359
- do {
1360
- digit = vlq & VLQ_BASE_MASK;
1361
- vlq >>>= VLQ_BASE_SHIFT;
1362
- if (vlq > 0) {
1363
- // There are still more digits in this value, so we must make sure the
1364
- // continuation bit is marked.
1365
- digit |= VLQ_CONTINUATION_BIT;
1366
- }
1367
- encoded += base64.encode(digit);
1368
- } while (vlq > 0);
1369
-
1370
- return encoded;
1371
- };
1372
-
1373
- /**
1374
- * Decodes the next base 64 VLQ value from the given string and returns the
1375
- * value and the rest of the string via the out parameter.
1376
- */
1377
- base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
1378
- var strLen = aStr.length;
1379
- var result = 0;
1380
- var shift = 0;
1381
- var continuation, digit;
1382
-
1383
- do {
1384
- if (aIndex >= strLen) {
1385
- throw new Error("Expected more digits in base 64 VLQ value.");
1386
- }
1387
-
1388
- digit = base64.decode(aStr.charCodeAt(aIndex++));
1389
- if (digit === -1) {
1390
- throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
1391
- }
1392
-
1393
- continuation = !!(digit & VLQ_CONTINUATION_BIT);
1394
- digit &= VLQ_BASE_MASK;
1395
- result = result + (digit << shift);
1396
- shift += VLQ_BASE_SHIFT;
1397
- } while (continuation);
1398
-
1399
- aOutParam.value = fromVLQSigned(result);
1400
- aOutParam.rest = aIndex;
1401
- };
1402
-
1403
- var util$5 = {};
1404
-
1405
- /* -*- Mode: js; js-indent-level: 2; -*- */
1406
-
1407
- (function (exports) {
1408
- /*
1409
- * Copyright 2011 Mozilla Foundation and contributors
1410
- * Licensed under the New BSD license. See LICENSE or:
1411
- * http://opensource.org/licenses/BSD-3-Clause
1412
- */
1413
-
1414
- /**
1415
- * This is a helper function for getting values from parameter/options
1416
- * objects.
1417
- *
1418
- * @param args The object we are extracting values from
1419
- * @param name The name of the property we are getting.
1420
- * @param defaultValue An optional value to return if the property is missing
1421
- * from the object. If this is not specified and the property is missing, an
1422
- * error will be thrown.
1423
- */
1424
- function getArg(aArgs, aName, aDefaultValue) {
1425
- if (aName in aArgs) {
1426
- return aArgs[aName];
1427
- } else if (arguments.length === 3) {
1428
- return aDefaultValue;
1429
- } else {
1430
- throw new Error('"' + aName + '" is a required argument.');
1431
- }
1432
- }
1433
- exports.getArg = getArg;
1434
-
1435
- var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
1436
- var dataUrlRegexp = /^data:.+\,.+$/;
1437
-
1438
- function urlParse(aUrl) {
1439
- var match = aUrl.match(urlRegexp);
1440
- if (!match) {
1441
- return null;
1442
- }
1443
- return {
1444
- scheme: match[1],
1445
- auth: match[2],
1446
- host: match[3],
1447
- port: match[4],
1448
- path: match[5]
1449
- };
1450
- }
1451
- exports.urlParse = urlParse;
1452
-
1453
- function urlGenerate(aParsedUrl) {
1454
- var url = '';
1455
- if (aParsedUrl.scheme) {
1456
- url += aParsedUrl.scheme + ':';
1457
- }
1458
- url += '//';
1459
- if (aParsedUrl.auth) {
1460
- url += aParsedUrl.auth + '@';
1461
- }
1462
- if (aParsedUrl.host) {
1463
- url += aParsedUrl.host;
1464
- }
1465
- if (aParsedUrl.port) {
1466
- url += ":" + aParsedUrl.port;
1467
- }
1468
- if (aParsedUrl.path) {
1469
- url += aParsedUrl.path;
1470
- }
1471
- return url;
1472
- }
1473
- exports.urlGenerate = urlGenerate;
1474
-
1475
- /**
1476
- * Normalizes a path, or the path portion of a URL:
1477
- *
1478
- * - Replaces consecutive slashes with one slash.
1479
- * - Removes unnecessary '.' parts.
1480
- * - Removes unnecessary '<dir>/..' parts.
1481
- *
1482
- * Based on code in the Node.js 'path' core module.
1483
- *
1484
- * @param aPath The path or url to normalize.
1485
- */
1486
- function normalize(aPath) {
1487
- var path = aPath;
1488
- var url = urlParse(aPath);
1489
- if (url) {
1490
- if (!url.path) {
1491
- return aPath;
1492
- }
1493
- path = url.path;
1494
- }
1495
- var isAbsolute = exports.isAbsolute(path);
1496
-
1497
- var parts = path.split(/\/+/);
1498
- for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
1499
- part = parts[i];
1500
- if (part === '.') {
1501
- parts.splice(i, 1);
1502
- } else if (part === '..') {
1503
- up++;
1504
- } else if (up > 0) {
1505
- if (part === '') {
1506
- // The first part is blank if the path is absolute. Trying to go
1507
- // above the root is a no-op. Therefore we can remove all '..' parts
1508
- // directly after the root.
1509
- parts.splice(i + 1, up);
1510
- up = 0;
1511
- } else {
1512
- parts.splice(i, 2);
1513
- up--;
1514
- }
1515
- }
1516
- }
1517
- path = parts.join('/');
1518
-
1519
- if (path === '') {
1520
- path = isAbsolute ? '/' : '.';
1521
- }
1522
-
1523
- if (url) {
1524
- url.path = path;
1525
- return urlGenerate(url);
1526
- }
1527
- return path;
1528
- }
1529
- exports.normalize = normalize;
1530
-
1531
- /**
1532
- * Joins two paths/URLs.
1533
- *
1534
- * @param aRoot The root path or URL.
1535
- * @param aPath The path or URL to be joined with the root.
1536
- *
1537
- * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
1538
- * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
1539
- * first.
1540
- * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
1541
- * is updated with the result and aRoot is returned. Otherwise the result
1542
- * is returned.
1543
- * - If aPath is absolute, the result is aPath.
1544
- * - Otherwise the two paths are joined with a slash.
1545
- * - Joining for example 'http://' and 'www.example.com' is also supported.
1546
- */
1547
- function join(aRoot, aPath) {
1548
- if (aRoot === "") {
1549
- aRoot = ".";
1550
- }
1551
- if (aPath === "") {
1552
- aPath = ".";
1553
- }
1554
- var aPathUrl = urlParse(aPath);
1555
- var aRootUrl = urlParse(aRoot);
1556
- if (aRootUrl) {
1557
- aRoot = aRootUrl.path || '/';
1558
- }
1559
-
1560
- // `join(foo, '//www.example.org')`
1561
- if (aPathUrl && !aPathUrl.scheme) {
1562
- if (aRootUrl) {
1563
- aPathUrl.scheme = aRootUrl.scheme;
1564
- }
1565
- return urlGenerate(aPathUrl);
1566
- }
1567
-
1568
- if (aPathUrl || aPath.match(dataUrlRegexp)) {
1569
- return aPath;
1570
- }
1571
-
1572
- // `join('http://', 'www.example.com')`
1573
- if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
1574
- aRootUrl.host = aPath;
1575
- return urlGenerate(aRootUrl);
1576
- }
1577
-
1578
- var joined = aPath.charAt(0) === '/'
1579
- ? aPath
1580
- : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
1581
-
1582
- if (aRootUrl) {
1583
- aRootUrl.path = joined;
1584
- return urlGenerate(aRootUrl);
1585
- }
1586
- return joined;
1587
- }
1588
- exports.join = join;
1589
-
1590
- exports.isAbsolute = function (aPath) {
1591
- return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
1592
- };
1593
-
1594
- /**
1595
- * Make a path relative to a URL or another path.
1596
- *
1597
- * @param aRoot The root path or URL.
1598
- * @param aPath The path or URL to be made relative to aRoot.
1599
- */
1600
- function relative(aRoot, aPath) {
1601
- if (aRoot === "") {
1602
- aRoot = ".";
1603
- }
1604
-
1605
- aRoot = aRoot.replace(/\/$/, '');
1606
-
1607
- // It is possible for the path to be above the root. In this case, simply
1608
- // checking whether the root is a prefix of the path won't work. Instead, we
1609
- // need to remove components from the root one by one, until either we find
1610
- // a prefix that fits, or we run out of components to remove.
1611
- var level = 0;
1612
- while (aPath.indexOf(aRoot + '/') !== 0) {
1613
- var index = aRoot.lastIndexOf("/");
1614
- if (index < 0) {
1615
- return aPath;
1616
- }
1617
-
1618
- // If the only part of the root that is left is the scheme (i.e. http://,
1619
- // file:///, etc.), one or more slashes (/), or simply nothing at all, we
1620
- // have exhausted all components, so the path is not relative to the root.
1621
- aRoot = aRoot.slice(0, index);
1622
- if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
1623
- return aPath;
1624
- }
1625
-
1626
- ++level;
1627
- }
1628
-
1629
- // Make sure we add a "../" for each component we removed from the root.
1630
- return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
1631
- }
1632
- exports.relative = relative;
1633
-
1634
- var supportsNullProto = (function () {
1635
- var obj = Object.create(null);
1636
- return !('__proto__' in obj);
1637
- }());
1638
-
1639
- function identity (s) {
1640
- return s;
1641
- }
1642
-
1643
- /**
1644
- * Because behavior goes wacky when you set `__proto__` on objects, we
1645
- * have to prefix all the strings in our set with an arbitrary character.
1646
- *
1647
- * See https://github.com/mozilla/source-map/pull/31 and
1648
- * https://github.com/mozilla/source-map/issues/30
1649
- *
1650
- * @param String aStr
1651
- */
1652
- function toSetString(aStr) {
1653
- if (isProtoString(aStr)) {
1654
- return '$' + aStr;
1655
- }
1656
-
1657
- return aStr;
1658
- }
1659
- exports.toSetString = supportsNullProto ? identity : toSetString;
1660
-
1661
- function fromSetString(aStr) {
1662
- if (isProtoString(aStr)) {
1663
- return aStr.slice(1);
1664
- }
1665
-
1666
- return aStr;
1667
- }
1668
- exports.fromSetString = supportsNullProto ? identity : fromSetString;
1669
-
1670
- function isProtoString(s) {
1671
- if (!s) {
1672
- return false;
1673
- }
1674
-
1675
- var length = s.length;
1676
-
1677
- if (length < 9 /* "__proto__".length */) {
1678
- return false;
1679
- }
1680
-
1681
- if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
1682
- s.charCodeAt(length - 2) !== 95 /* '_' */ ||
1683
- s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
1684
- s.charCodeAt(length - 4) !== 116 /* 't' */ ||
1685
- s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
1686
- s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
1687
- s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
1688
- s.charCodeAt(length - 8) !== 95 /* '_' */ ||
1689
- s.charCodeAt(length - 9) !== 95 /* '_' */) {
1690
- return false;
1691
- }
1692
-
1693
- for (var i = length - 10; i >= 0; i--) {
1694
- if (s.charCodeAt(i) !== 36 /* '$' */) {
1695
- return false;
1696
- }
1697
- }
1698
-
1699
- return true;
1700
- }
1701
-
1702
- /**
1703
- * Comparator between two mappings where the original positions are compared.
1704
- *
1705
- * Optionally pass in `true` as `onlyCompareGenerated` to consider two
1706
- * mappings with the same original source/line/column, but different generated
1707
- * line and column the same. Useful when searching for a mapping with a
1708
- * stubbed out mapping.
1709
- */
1710
- function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
1711
- var cmp = strcmp(mappingA.source, mappingB.source);
1712
- if (cmp !== 0) {
1713
- return cmp;
1714
- }
1715
-
1716
- cmp = mappingA.originalLine - mappingB.originalLine;
1717
- if (cmp !== 0) {
1718
- return cmp;
1719
- }
1720
-
1721
- cmp = mappingA.originalColumn - mappingB.originalColumn;
1722
- if (cmp !== 0 || onlyCompareOriginal) {
1723
- return cmp;
1724
- }
1725
-
1726
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1727
- if (cmp !== 0) {
1728
- return cmp;
1729
- }
1730
-
1731
- cmp = mappingA.generatedLine - mappingB.generatedLine;
1732
- if (cmp !== 0) {
1733
- return cmp;
1734
- }
1735
-
1736
- return strcmp(mappingA.name, mappingB.name);
1737
- }
1738
- exports.compareByOriginalPositions = compareByOriginalPositions;
1739
-
1740
- /**
1741
- * Comparator between two mappings with deflated source and name indices where
1742
- * the generated positions are compared.
1743
- *
1744
- * Optionally pass in `true` as `onlyCompareGenerated` to consider two
1745
- * mappings with the same generated line and column, but different
1746
- * source/name/original line and column the same. Useful when searching for a
1747
- * mapping with a stubbed out mapping.
1748
- */
1749
- function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
1750
- var cmp = mappingA.generatedLine - mappingB.generatedLine;
1751
- if (cmp !== 0) {
1752
- return cmp;
1753
- }
1754
-
1755
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1756
- if (cmp !== 0 || onlyCompareGenerated) {
1757
- return cmp;
1758
- }
1759
-
1760
- cmp = strcmp(mappingA.source, mappingB.source);
1761
- if (cmp !== 0) {
1762
- return cmp;
1763
- }
1764
-
1765
- cmp = mappingA.originalLine - mappingB.originalLine;
1766
- if (cmp !== 0) {
1767
- return cmp;
1768
- }
1769
-
1770
- cmp = mappingA.originalColumn - mappingB.originalColumn;
1771
- if (cmp !== 0) {
1772
- return cmp;
1773
- }
1774
-
1775
- return strcmp(mappingA.name, mappingB.name);
1776
- }
1777
- exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
1778
-
1779
- function strcmp(aStr1, aStr2) {
1780
- if (aStr1 === aStr2) {
1781
- return 0;
1782
- }
1783
-
1784
- if (aStr1 === null) {
1785
- return 1; // aStr2 !== null
1786
- }
1787
-
1788
- if (aStr2 === null) {
1789
- return -1; // aStr1 !== null
1790
- }
1791
-
1792
- if (aStr1 > aStr2) {
1793
- return 1;
1794
- }
1795
-
1796
- return -1;
1797
- }
1798
-
1799
- /**
1800
- * Comparator between two mappings with inflated source and name strings where
1801
- * the generated positions are compared.
1802
- */
1803
- function compareByGeneratedPositionsInflated(mappingA, mappingB) {
1804
- var cmp = mappingA.generatedLine - mappingB.generatedLine;
1805
- if (cmp !== 0) {
1806
- return cmp;
1807
- }
1808
-
1809
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1810
- if (cmp !== 0) {
1811
- return cmp;
1812
- }
1813
-
1814
- cmp = strcmp(mappingA.source, mappingB.source);
1815
- if (cmp !== 0) {
1816
- return cmp;
1817
- }
1818
-
1819
- cmp = mappingA.originalLine - mappingB.originalLine;
1820
- if (cmp !== 0) {
1821
- return cmp;
1822
- }
1823
-
1824
- cmp = mappingA.originalColumn - mappingB.originalColumn;
1825
- if (cmp !== 0) {
1826
- return cmp;
1827
- }
1828
-
1829
- return strcmp(mappingA.name, mappingB.name);
1830
- }
1831
- exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
1832
-
1833
- /**
1834
- * Strip any JSON XSSI avoidance prefix from the string (as documented
1835
- * in the source maps specification), and then parse the string as
1836
- * JSON.
1837
- */
1838
- function parseSourceMapInput(str) {
1839
- return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
1840
- }
1841
- exports.parseSourceMapInput = parseSourceMapInput;
1842
-
1843
- /**
1844
- * Compute the URL of a source given the the source root, the source's
1845
- * URL, and the source map's URL.
1846
- */
1847
- function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
1848
- sourceURL = sourceURL || '';
1849
-
1850
- if (sourceRoot) {
1851
- // This follows what Chrome does.
1852
- if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
1853
- sourceRoot += '/';
1854
- }
1855
- // The spec says:
1856
- // Line 4: An optional source root, useful for relocating source
1857
- // files on a server or removing repeated values in the
1858
- // “sources” entry. This value is prepended to the individual
1859
- // entries in the “source” field.
1860
- sourceURL = sourceRoot + sourceURL;
1861
- }
1862
-
1863
- // Historically, SourceMapConsumer did not take the sourceMapURL as
1864
- // a parameter. This mode is still somewhat supported, which is why
1865
- // this code block is conditional. However, it's preferable to pass
1866
- // the source map URL to SourceMapConsumer, so that this function
1867
- // can implement the source URL resolution algorithm as outlined in
1868
- // the spec. This block is basically the equivalent of:
1869
- // new URL(sourceURL, sourceMapURL).toString()
1870
- // ... except it avoids using URL, which wasn't available in the
1871
- // older releases of node still supported by this library.
1872
- //
1873
- // The spec says:
1874
- // If the sources are not absolute URLs after prepending of the
1875
- // “sourceRoot”, the sources are resolved relative to the
1876
- // SourceMap (like resolving script src in a html document).
1877
- if (sourceMapURL) {
1878
- var parsed = urlParse(sourceMapURL);
1879
- if (!parsed) {
1880
- throw new Error("sourceMapURL could not be parsed");
1881
- }
1882
- if (parsed.path) {
1883
- // Strip the last path component, but keep the "/".
1884
- var index = parsed.path.lastIndexOf('/');
1885
- if (index >= 0) {
1886
- parsed.path = parsed.path.substring(0, index + 1);
1887
- }
1888
- }
1889
- sourceURL = join(urlGenerate(parsed), sourceURL);
1890
- }
1891
-
1892
- return normalize(sourceURL);
1893
- }
1894
- exports.computeSourceURL = computeSourceURL;
1895
- }(util$5));
1896
-
1897
- var arraySet = {};
1898
-
1899
- /* -*- Mode: js; js-indent-level: 2; -*- */
1900
-
1901
- /*
1902
- * Copyright 2011 Mozilla Foundation and contributors
1903
- * Licensed under the New BSD license. See LICENSE or:
1904
- * http://opensource.org/licenses/BSD-3-Clause
1905
- */
1906
-
1907
- var util$4 = util$5;
1908
- var has = Object.prototype.hasOwnProperty;
1909
- var hasNativeMap = typeof Map !== "undefined";
1910
-
1911
- /**
1912
- * A data structure which is a combination of an array and a set. Adding a new
1913
- * member is O(1), testing for membership is O(1), and finding the index of an
1914
- * element is O(1). Removing elements from the set is not supported. Only
1915
- * strings are supported for membership.
1916
- */
1917
- function ArraySet$2() {
1918
- this._array = [];
1919
- this._set = hasNativeMap ? new Map() : Object.create(null);
1920
- }
1921
-
1922
- /**
1923
- * Static method for creating ArraySet instances from an existing array.
1924
- */
1925
- ArraySet$2.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
1926
- var set = new ArraySet$2();
1927
- for (var i = 0, len = aArray.length; i < len; i++) {
1928
- set.add(aArray[i], aAllowDuplicates);
1929
- }
1930
- return set;
1931
- };
1932
-
1933
- /**
1934
- * Return how many unique items are in this ArraySet. If duplicates have been
1935
- * added, than those do not count towards the size.
1936
- *
1937
- * @returns Number
1938
- */
1939
- ArraySet$2.prototype.size = function ArraySet_size() {
1940
- return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
1941
- };
1942
-
1943
- /**
1944
- * Add the given string to this set.
1945
- *
1946
- * @param String aStr
1947
- */
1948
- ArraySet$2.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
1949
- var sStr = hasNativeMap ? aStr : util$4.toSetString(aStr);
1950
- var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
1951
- var idx = this._array.length;
1952
- if (!isDuplicate || aAllowDuplicates) {
1953
- this._array.push(aStr);
1954
- }
1955
- if (!isDuplicate) {
1956
- if (hasNativeMap) {
1957
- this._set.set(aStr, idx);
1958
- } else {
1959
- this._set[sStr] = idx;
1960
- }
1961
- }
1962
- };
1963
-
1964
- /**
1965
- * Is the given string a member of this set?
1966
- *
1967
- * @param String aStr
1968
- */
1969
- ArraySet$2.prototype.has = function ArraySet_has(aStr) {
1970
- if (hasNativeMap) {
1971
- return this._set.has(aStr);
1972
- } else {
1973
- var sStr = util$4.toSetString(aStr);
1974
- return has.call(this._set, sStr);
1975
- }
1976
- };
1977
-
1978
- /**
1979
- * What is the index of the given string in the array?
1980
- *
1981
- * @param String aStr
1982
- */
1983
- ArraySet$2.prototype.indexOf = function ArraySet_indexOf(aStr) {
1984
- if (hasNativeMap) {
1985
- var idx = this._set.get(aStr);
1986
- if (idx >= 0) {
1987
- return idx;
1988
- }
1989
- } else {
1990
- var sStr = util$4.toSetString(aStr);
1991
- if (has.call(this._set, sStr)) {
1992
- return this._set[sStr];
1993
- }
1994
- }
1995
-
1996
- throw new Error('"' + aStr + '" is not in the set.');
1997
- };
1998
-
1999
- /**
2000
- * What is the element at the given index?
2001
- *
2002
- * @param Number aIdx
2003
- */
2004
- ArraySet$2.prototype.at = function ArraySet_at(aIdx) {
2005
- if (aIdx >= 0 && aIdx < this._array.length) {
2006
- return this._array[aIdx];
2007
- }
2008
- throw new Error('No element indexed by ' + aIdx);
2009
- };
2010
-
2011
- /**
2012
- * Returns the array representation of this set (which has the proper indices
2013
- * indicated by indexOf). Note that this is a copy of the internal array used
2014
- * for storing the members so that no one can mess with internal state.
2015
- */
2016
- ArraySet$2.prototype.toArray = function ArraySet_toArray() {
2017
- return this._array.slice();
2018
- };
2019
-
2020
- arraySet.ArraySet = ArraySet$2;
2021
-
2022
- var mappingList = {};
2023
-
2024
- /* -*- Mode: js; js-indent-level: 2; -*- */
2025
-
2026
- /*
2027
- * Copyright 2014 Mozilla Foundation and contributors
2028
- * Licensed under the New BSD license. See LICENSE or:
2029
- * http://opensource.org/licenses/BSD-3-Clause
2030
- */
2031
-
2032
- var util$3 = util$5;
2033
-
2034
- /**
2035
- * Determine whether mappingB is after mappingA with respect to generated
2036
- * position.
2037
- */
2038
- function generatedPositionAfter(mappingA, mappingB) {
2039
- // Optimized for most common case
2040
- var lineA = mappingA.generatedLine;
2041
- var lineB = mappingB.generatedLine;
2042
- var columnA = mappingA.generatedColumn;
2043
- var columnB = mappingB.generatedColumn;
2044
- return lineB > lineA || lineB == lineA && columnB >= columnA ||
2045
- util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
2046
- }
2047
-
2048
- /**
2049
- * A data structure to provide a sorted view of accumulated mappings in a
2050
- * performance conscious manner. It trades a neglibable overhead in general
2051
- * case for a large speedup in case of mappings being added in order.
2052
- */
2053
- function MappingList$1() {
2054
- this._array = [];
2055
- this._sorted = true;
2056
- // Serves as infimum
2057
- this._last = {generatedLine: -1, generatedColumn: 0};
2058
- }
2059
-
2060
- /**
2061
- * Iterate through internal items. This method takes the same arguments that
2062
- * `Array.prototype.forEach` takes.
2063
- *
2064
- * NOTE: The order of the mappings is NOT guaranteed.
2065
- */
2066
- MappingList$1.prototype.unsortedForEach =
2067
- function MappingList_forEach(aCallback, aThisArg) {
2068
- this._array.forEach(aCallback, aThisArg);
2069
- };
2070
-
2071
- /**
2072
- * Add the given source mapping.
2073
- *
2074
- * @param Object aMapping
2075
- */
2076
- MappingList$1.prototype.add = function MappingList_add(aMapping) {
2077
- if (generatedPositionAfter(this._last, aMapping)) {
2078
- this._last = aMapping;
2079
- this._array.push(aMapping);
2080
- } else {
2081
- this._sorted = false;
2082
- this._array.push(aMapping);
2083
- }
2084
- };
2085
-
2086
- /**
2087
- * Returns the flat, sorted array of mappings. The mappings are sorted by
2088
- * generated position.
2089
- *
2090
- * WARNING: This method returns internal data without copying, for
2091
- * performance. The return value must NOT be mutated, and should be treated as
2092
- * an immutable borrow. If you want to take ownership, you must make your own
2093
- * copy.
2094
- */
2095
- MappingList$1.prototype.toArray = function MappingList_toArray() {
2096
- if (!this._sorted) {
2097
- this._array.sort(util$3.compareByGeneratedPositionsInflated);
2098
- this._sorted = true;
2099
- }
2100
- return this._array;
2101
- };
2102
-
2103
- mappingList.MappingList = MappingList$1;
2104
-
2105
- /* -*- Mode: js; js-indent-level: 2; -*- */
2106
-
2107
- /*
2108
- * Copyright 2011 Mozilla Foundation and contributors
2109
- * Licensed under the New BSD license. See LICENSE or:
2110
- * http://opensource.org/licenses/BSD-3-Clause
2111
- */
2112
-
2113
- var base64VLQ$1 = base64Vlq;
2114
- var util$2 = util$5;
2115
- var ArraySet$1 = arraySet.ArraySet;
2116
- var MappingList = mappingList.MappingList;
2117
-
2118
- /**
2119
- * An instance of the SourceMapGenerator represents a source map which is
2120
- * being built incrementally. You may pass an object with the following
2121
- * properties:
2122
- *
2123
- * - file: The filename of the generated source.
2124
- * - sourceRoot: A root for all relative URLs in this source map.
2125
- */
2126
- function SourceMapGenerator$2(aArgs) {
2127
- if (!aArgs) {
2128
- aArgs = {};
2129
- }
2130
- this._file = util$2.getArg(aArgs, 'file', null);
2131
- this._sourceRoot = util$2.getArg(aArgs, 'sourceRoot', null);
2132
- this._skipValidation = util$2.getArg(aArgs, 'skipValidation', false);
2133
- this._sources = new ArraySet$1();
2134
- this._names = new ArraySet$1();
2135
- this._mappings = new MappingList();
2136
- this._sourcesContents = null;
2137
- }
2138
-
2139
- SourceMapGenerator$2.prototype._version = 3;
2140
-
2141
- /**
2142
- * Creates a new SourceMapGenerator based on a SourceMapConsumer
2143
- *
2144
- * @param aSourceMapConsumer The SourceMap.
2145
- */
2146
- SourceMapGenerator$2.fromSourceMap =
2147
- function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
2148
- var sourceRoot = aSourceMapConsumer.sourceRoot;
2149
- var generator = new SourceMapGenerator$2({
2150
- file: aSourceMapConsumer.file,
2151
- sourceRoot: sourceRoot
2152
- });
2153
- aSourceMapConsumer.eachMapping(function (mapping) {
2154
- var newMapping = {
2155
- generated: {
2156
- line: mapping.generatedLine,
2157
- column: mapping.generatedColumn
2158
- }
2159
- };
2160
-
2161
- if (mapping.source != null) {
2162
- newMapping.source = mapping.source;
2163
- if (sourceRoot != null) {
2164
- newMapping.source = util$2.relative(sourceRoot, newMapping.source);
2165
- }
2166
-
2167
- newMapping.original = {
2168
- line: mapping.originalLine,
2169
- column: mapping.originalColumn
2170
- };
2171
-
2172
- if (mapping.name != null) {
2173
- newMapping.name = mapping.name;
2174
- }
2175
- }
2176
-
2177
- generator.addMapping(newMapping);
2178
- });
2179
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
2180
- var sourceRelative = sourceFile;
2181
- if (sourceRoot !== null) {
2182
- sourceRelative = util$2.relative(sourceRoot, sourceFile);
2183
- }
2184
-
2185
- if (!generator._sources.has(sourceRelative)) {
2186
- generator._sources.add(sourceRelative);
2187
- }
2188
-
2189
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
2190
- if (content != null) {
2191
- generator.setSourceContent(sourceFile, content);
2192
- }
2193
- });
2194
- return generator;
2195
- };
2196
-
2197
- /**
2198
- * Add a single mapping from original source line and column to the generated
2199
- * source's line and column for this source map being created. The mapping
2200
- * object should have the following properties:
2201
- *
2202
- * - generated: An object with the generated line and column positions.
2203
- * - original: An object with the original line and column positions.
2204
- * - source: The original source file (relative to the sourceRoot).
2205
- * - name: An optional original token name for this mapping.
2206
- */
2207
- SourceMapGenerator$2.prototype.addMapping =
2208
- function SourceMapGenerator_addMapping(aArgs) {
2209
- var generated = util$2.getArg(aArgs, 'generated');
2210
- var original = util$2.getArg(aArgs, 'original', null);
2211
- var source = util$2.getArg(aArgs, 'source', null);
2212
- var name = util$2.getArg(aArgs, 'name', null);
2213
-
2214
- if (!this._skipValidation) {
2215
- this._validateMapping(generated, original, source, name);
2216
- }
2217
-
2218
- if (source != null) {
2219
- source = String(source);
2220
- if (!this._sources.has(source)) {
2221
- this._sources.add(source);
2222
- }
2223
- }
2224
-
2225
- if (name != null) {
2226
- name = String(name);
2227
- if (!this._names.has(name)) {
2228
- this._names.add(name);
2229
- }
2230
- }
2231
-
2232
- this._mappings.add({
2233
- generatedLine: generated.line,
2234
- generatedColumn: generated.column,
2235
- originalLine: original != null && original.line,
2236
- originalColumn: original != null && original.column,
2237
- source: source,
2238
- name: name
2239
- });
2240
- };
2241
-
2242
- /**
2243
- * Set the source content for a source file.
2244
- */
2245
- SourceMapGenerator$2.prototype.setSourceContent =
2246
- function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
2247
- var source = aSourceFile;
2248
- if (this._sourceRoot != null) {
2249
- source = util$2.relative(this._sourceRoot, source);
2250
- }
2251
-
2252
- if (aSourceContent != null) {
2253
- // Add the source content to the _sourcesContents map.
2254
- // Create a new _sourcesContents map if the property is null.
2255
- if (!this._sourcesContents) {
2256
- this._sourcesContents = Object.create(null);
2257
- }
2258
- this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
2259
- } else if (this._sourcesContents) {
2260
- // Remove the source file from the _sourcesContents map.
2261
- // If the _sourcesContents map is empty, set the property to null.
2262
- delete this._sourcesContents[util$2.toSetString(source)];
2263
- if (Object.keys(this._sourcesContents).length === 0) {
2264
- this._sourcesContents = null;
2265
- }
2266
- }
2267
- };
2268
-
2269
- /**
2270
- * Applies the mappings of a sub-source-map for a specific source file to the
2271
- * source map being generated. Each mapping to the supplied source file is
2272
- * rewritten using the supplied source map. Note: The resolution for the
2273
- * resulting mappings is the minimium of this map and the supplied map.
2274
- *
2275
- * @param aSourceMapConsumer The source map to be applied.
2276
- * @param aSourceFile Optional. The filename of the source file.
2277
- * If omitted, SourceMapConsumer's file property will be used.
2278
- * @param aSourceMapPath Optional. The dirname of the path to the source map
2279
- * to be applied. If relative, it is relative to the SourceMapConsumer.
2280
- * This parameter is needed when the two source maps aren't in the same
2281
- * directory, and the source map to be applied contains relative source
2282
- * paths. If so, those relative source paths need to be rewritten
2283
- * relative to the SourceMapGenerator.
2284
- */
2285
- SourceMapGenerator$2.prototype.applySourceMap =
2286
- function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
2287
- var sourceFile = aSourceFile;
2288
- // If aSourceFile is omitted, we will use the file property of the SourceMap
2289
- if (aSourceFile == null) {
2290
- if (aSourceMapConsumer.file == null) {
2291
- throw new Error(
2292
- 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
2293
- 'or the source map\'s "file" property. Both were omitted.'
2294
- );
2295
- }
2296
- sourceFile = aSourceMapConsumer.file;
2297
- }
2298
- var sourceRoot = this._sourceRoot;
2299
- // Make "sourceFile" relative if an absolute Url is passed.
2300
- if (sourceRoot != null) {
2301
- sourceFile = util$2.relative(sourceRoot, sourceFile);
2302
- }
2303
- // Applying the SourceMap can add and remove items from the sources and
2304
- // the names array.
2305
- var newSources = new ArraySet$1();
2306
- var newNames = new ArraySet$1();
2307
-
2308
- // Find mappings for the "sourceFile"
2309
- this._mappings.unsortedForEach(function (mapping) {
2310
- if (mapping.source === sourceFile && mapping.originalLine != null) {
2311
- // Check if it can be mapped by the source map, then update the mapping.
2312
- var original = aSourceMapConsumer.originalPositionFor({
2313
- line: mapping.originalLine,
2314
- column: mapping.originalColumn
2315
- });
2316
- if (original.source != null) {
2317
- // Copy mapping
2318
- mapping.source = original.source;
2319
- if (aSourceMapPath != null) {
2320
- mapping.source = util$2.join(aSourceMapPath, mapping.source);
2321
- }
2322
- if (sourceRoot != null) {
2323
- mapping.source = util$2.relative(sourceRoot, mapping.source);
2324
- }
2325
- mapping.originalLine = original.line;
2326
- mapping.originalColumn = original.column;
2327
- if (original.name != null) {
2328
- mapping.name = original.name;
2329
- }
2330
- }
2331
- }
2332
-
2333
- var source = mapping.source;
2334
- if (source != null && !newSources.has(source)) {
2335
- newSources.add(source);
2336
- }
2337
-
2338
- var name = mapping.name;
2339
- if (name != null && !newNames.has(name)) {
2340
- newNames.add(name);
2341
- }
2342
-
2343
- }, this);
2344
- this._sources = newSources;
2345
- this._names = newNames;
2346
-
2347
- // Copy sourcesContents of applied map.
2348
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
2349
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
2350
- if (content != null) {
2351
- if (aSourceMapPath != null) {
2352
- sourceFile = util$2.join(aSourceMapPath, sourceFile);
2353
- }
2354
- if (sourceRoot != null) {
2355
- sourceFile = util$2.relative(sourceRoot, sourceFile);
2356
- }
2357
- this.setSourceContent(sourceFile, content);
2358
- }
2359
- }, this);
2360
- };
2361
-
2362
- /**
2363
- * A mapping can have one of the three levels of data:
2364
- *
2365
- * 1. Just the generated position.
2366
- * 2. The Generated position, original position, and original source.
2367
- * 3. Generated and original position, original source, as well as a name
2368
- * token.
2369
- *
2370
- * To maintain consistency, we validate that any new mapping being added falls
2371
- * in to one of these categories.
2372
- */
2373
- SourceMapGenerator$2.prototype._validateMapping =
2374
- function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
2375
- aName) {
2376
- // When aOriginal is truthy but has empty values for .line and .column,
2377
- // it is most likely a programmer error. In this case we throw a very
2378
- // specific error message to try to guide them the right way.
2379
- // For example: https://github.com/Polymer/polymer-bundler/pull/519
2380
- if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
2381
- throw new Error(
2382
- 'original.line and original.column are not numbers -- you probably meant to omit ' +
2383
- 'the original mapping entirely and only map the generated position. If so, pass ' +
2384
- 'null for the original mapping instead of an object with empty or null values.'
2385
- );
2386
- }
2387
-
2388
- if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
2389
- && aGenerated.line > 0 && aGenerated.column >= 0
2390
- && !aOriginal && !aSource && !aName) {
2391
- // Case 1.
2392
- return;
2393
- }
2394
- else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
2395
- && aOriginal && 'line' in aOriginal && 'column' in aOriginal
2396
- && aGenerated.line > 0 && aGenerated.column >= 0
2397
- && aOriginal.line > 0 && aOriginal.column >= 0
2398
- && aSource) {
2399
- // Cases 2 and 3.
2400
- return;
2401
- }
2402
- else {
2403
- throw new Error('Invalid mapping: ' + JSON.stringify({
2404
- generated: aGenerated,
2405
- source: aSource,
2406
- original: aOriginal,
2407
- name: aName
2408
- }));
2409
- }
2410
- };
2411
-
2412
- /**
2413
- * Serialize the accumulated mappings in to the stream of base 64 VLQs
2414
- * specified by the source map format.
2415
- */
2416
- SourceMapGenerator$2.prototype._serializeMappings =
2417
- function SourceMapGenerator_serializeMappings() {
2418
- var previousGeneratedColumn = 0;
2419
- var previousGeneratedLine = 1;
2420
- var previousOriginalColumn = 0;
2421
- var previousOriginalLine = 0;
2422
- var previousName = 0;
2423
- var previousSource = 0;
2424
- var result = '';
2425
- var next;
2426
- var mapping;
2427
- var nameIdx;
2428
- var sourceIdx;
2429
-
2430
- var mappings = this._mappings.toArray();
2431
- for (var i = 0, len = mappings.length; i < len; i++) {
2432
- mapping = mappings[i];
2433
- next = '';
2434
-
2435
- if (mapping.generatedLine !== previousGeneratedLine) {
2436
- previousGeneratedColumn = 0;
2437
- while (mapping.generatedLine !== previousGeneratedLine) {
2438
- next += ';';
2439
- previousGeneratedLine++;
2440
- }
2441
- }
2442
- else {
2443
- if (i > 0) {
2444
- if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
2445
- continue;
2446
- }
2447
- next += ',';
2448
- }
2449
- }
2450
-
2451
- next += base64VLQ$1.encode(mapping.generatedColumn
2452
- - previousGeneratedColumn);
2453
- previousGeneratedColumn = mapping.generatedColumn;
2454
-
2455
- if (mapping.source != null) {
2456
- sourceIdx = this._sources.indexOf(mapping.source);
2457
- next += base64VLQ$1.encode(sourceIdx - previousSource);
2458
- previousSource = sourceIdx;
2459
-
2460
- // lines are stored 0-based in SourceMap spec version 3
2461
- next += base64VLQ$1.encode(mapping.originalLine - 1
2462
- - previousOriginalLine);
2463
- previousOriginalLine = mapping.originalLine - 1;
2464
-
2465
- next += base64VLQ$1.encode(mapping.originalColumn
2466
- - previousOriginalColumn);
2467
- previousOriginalColumn = mapping.originalColumn;
2468
-
2469
- if (mapping.name != null) {
2470
- nameIdx = this._names.indexOf(mapping.name);
2471
- next += base64VLQ$1.encode(nameIdx - previousName);
2472
- previousName = nameIdx;
2473
- }
2474
- }
2475
-
2476
- result += next;
2477
- }
2478
-
2479
- return result;
2480
- };
2481
-
2482
- SourceMapGenerator$2.prototype._generateSourcesContent =
2483
- function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
2484
- return aSources.map(function (source) {
2485
- if (!this._sourcesContents) {
2486
- return null;
2487
- }
2488
- if (aSourceRoot != null) {
2489
- source = util$2.relative(aSourceRoot, source);
2490
- }
2491
- var key = util$2.toSetString(source);
2492
- return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
2493
- ? this._sourcesContents[key]
2494
- : null;
2495
- }, this);
2496
- };
2497
-
2498
- /**
2499
- * Externalize the source map.
2500
- */
2501
- SourceMapGenerator$2.prototype.toJSON =
2502
- function SourceMapGenerator_toJSON() {
2503
- var map = {
2504
- version: this._version,
2505
- sources: this._sources.toArray(),
2506
- names: this._names.toArray(),
2507
- mappings: this._serializeMappings()
2508
- };
2509
- if (this._file != null) {
2510
- map.file = this._file;
2511
- }
2512
- if (this._sourceRoot != null) {
2513
- map.sourceRoot = this._sourceRoot;
2514
- }
2515
- if (this._sourcesContents) {
2516
- map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
2517
- }
2518
-
2519
- return map;
2520
- };
2521
-
2522
- /**
2523
- * Render the source map being generated to a string.
2524
- */
2525
- SourceMapGenerator$2.prototype.toString =
2526
- function SourceMapGenerator_toString() {
2527
- return JSON.stringify(this.toJSON());
2528
- };
2529
-
2530
- sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$2;
2531
-
2532
- var sourceMapConsumer = {};
2533
-
2534
- var binarySearch$1 = {};
2535
-
2536
- /* -*- Mode: js; js-indent-level: 2; -*- */
2537
-
2538
- (function (exports) {
2539
- /*
2540
- * Copyright 2011 Mozilla Foundation and contributors
2541
- * Licensed under the New BSD license. See LICENSE or:
2542
- * http://opensource.org/licenses/BSD-3-Clause
2543
- */
2544
-
2545
- exports.GREATEST_LOWER_BOUND = 1;
2546
- exports.LEAST_UPPER_BOUND = 2;
2547
-
2548
- /**
2549
- * Recursive implementation of binary search.
2550
- *
2551
- * @param aLow Indices here and lower do not contain the needle.
2552
- * @param aHigh Indices here and higher do not contain the needle.
2553
- * @param aNeedle The element being searched for.
2554
- * @param aHaystack The non-empty array being searched.
2555
- * @param aCompare Function which takes two elements and returns -1, 0, or 1.
2556
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2557
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2558
- * closest element that is smaller than or greater than the one we are
2559
- * searching for, respectively, if the exact element cannot be found.
2560
- */
2561
- function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
2562
- // This function terminates when one of the following is true:
2563
- //
2564
- // 1. We find the exact element we are looking for.
2565
- //
2566
- // 2. We did not find the exact element, but we can return the index of
2567
- // the next-closest element.
2568
- //
2569
- // 3. We did not find the exact element, and there is no next-closest
2570
- // element than the one we are searching for, so we return -1.
2571
- var mid = Math.floor((aHigh - aLow) / 2) + aLow;
2572
- var cmp = aCompare(aNeedle, aHaystack[mid], true);
2573
- if (cmp === 0) {
2574
- // Found the element we are looking for.
2575
- return mid;
2576
- }
2577
- else if (cmp > 0) {
2578
- // Our needle is greater than aHaystack[mid].
2579
- if (aHigh - mid > 1) {
2580
- // The element is in the upper half.
2581
- return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
2582
- }
2583
-
2584
- // The exact needle element was not found in this haystack. Determine if
2585
- // we are in termination case (3) or (2) and return the appropriate thing.
2586
- if (aBias == exports.LEAST_UPPER_BOUND) {
2587
- return aHigh < aHaystack.length ? aHigh : -1;
2588
- } else {
2589
- return mid;
2590
- }
2591
- }
2592
- else {
2593
- // Our needle is less than aHaystack[mid].
2594
- if (mid - aLow > 1) {
2595
- // The element is in the lower half.
2596
- return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
2597
- }
2598
-
2599
- // we are in termination case (3) or (2) and return the appropriate thing.
2600
- if (aBias == exports.LEAST_UPPER_BOUND) {
2601
- return mid;
2602
- } else {
2603
- return aLow < 0 ? -1 : aLow;
2604
- }
2605
- }
2606
- }
2607
-
2608
- /**
2609
- * This is an implementation of binary search which will always try and return
2610
- * the index of the closest element if there is no exact hit. This is because
2611
- * mappings between original and generated line/col pairs are single points,
2612
- * and there is an implicit region between each of them, so a miss just means
2613
- * that you aren't on the very start of a region.
2614
- *
2615
- * @param aNeedle The element you are looking for.
2616
- * @param aHaystack The array that is being searched.
2617
- * @param aCompare A function which takes the needle and an element in the
2618
- * array and returns -1, 0, or 1 depending on whether the needle is less
2619
- * than, equal to, or greater than the element, respectively.
2620
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2621
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2622
- * closest element that is smaller than or greater than the one we are
2623
- * searching for, respectively, if the exact element cannot be found.
2624
- * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
2625
- */
2626
- exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
2627
- if (aHaystack.length === 0) {
2628
- return -1;
2629
- }
2630
-
2631
- var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
2632
- aCompare, aBias || exports.GREATEST_LOWER_BOUND);
2633
- if (index < 0) {
2634
- return -1;
2635
- }
2636
-
2637
- // We have found either the exact element, or the next-closest element than
2638
- // the one we are searching for. However, there may be more than one such
2639
- // element. Make sure we always return the smallest of these.
2640
- while (index - 1 >= 0) {
2641
- if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
2642
- break;
2643
- }
2644
- --index;
2645
- }
2646
-
2647
- return index;
2648
- };
2649
- }(binarySearch$1));
2650
-
2651
- var quickSort$1 = {};
2652
-
2653
- /* -*- Mode: js; js-indent-level: 2; -*- */
2654
-
2655
- /*
2656
- * Copyright 2011 Mozilla Foundation and contributors
2657
- * Licensed under the New BSD license. See LICENSE or:
2658
- * http://opensource.org/licenses/BSD-3-Clause
2659
- */
2660
-
2661
- // It turns out that some (most?) JavaScript engines don't self-host
2662
- // `Array.prototype.sort`. This makes sense because C++ will likely remain
2663
- // faster than JS when doing raw CPU-intensive sorting. However, when using a
2664
- // custom comparator function, calling back and forth between the VM's C++ and
2665
- // JIT'd JS is rather slow *and* loses JIT type information, resulting in
2666
- // worse generated code for the comparator function than would be optimal. In
2667
- // fact, when sorting with a comparator, these costs outweigh the benefits of
2668
- // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
2669
- // a ~3500ms mean speed-up in `bench/bench.html`.
2670
-
2671
- /**
2672
- * Swap the elements indexed by `x` and `y` in the array `ary`.
2673
- *
2674
- * @param {Array} ary
2675
- * The array.
2676
- * @param {Number} x
2677
- * The index of the first item.
2678
- * @param {Number} y
2679
- * The index of the second item.
2680
- */
2681
- function swap(ary, x, y) {
2682
- var temp = ary[x];
2683
- ary[x] = ary[y];
2684
- ary[y] = temp;
2685
- }
2686
-
2687
- /**
2688
- * Returns a random integer within the range `low .. high` inclusive.
2689
- *
2690
- * @param {Number} low
2691
- * The lower bound on the range.
2692
- * @param {Number} high
2693
- * The upper bound on the range.
2694
- */
2695
- function randomIntInRange(low, high) {
2696
- return Math.round(low + (Math.random() * (high - low)));
2697
- }
2698
-
2699
- /**
2700
- * The Quick Sort algorithm.
2701
- *
2702
- * @param {Array} ary
2703
- * An array to sort.
2704
- * @param {function} comparator
2705
- * Function to use to compare two items.
2706
- * @param {Number} p
2707
- * Start index of the array
2708
- * @param {Number} r
2709
- * End index of the array
2710
- */
2711
- function doQuickSort(ary, comparator, p, r) {
2712
- // If our lower bound is less than our upper bound, we (1) partition the
2713
- // array into two pieces and (2) recurse on each half. If it is not, this is
2714
- // the empty array and our base case.
2715
-
2716
- if (p < r) {
2717
- // (1) Partitioning.
2718
- //
2719
- // The partitioning chooses a pivot between `p` and `r` and moves all
2720
- // elements that are less than or equal to the pivot to the before it, and
2721
- // all the elements that are greater than it after it. The effect is that
2722
- // once partition is done, the pivot is in the exact place it will be when
2723
- // the array is put in sorted order, and it will not need to be moved
2724
- // again. This runs in O(n) time.
2725
-
2726
- // Always choose a random pivot so that an input array which is reverse
2727
- // sorted does not cause O(n^2) running time.
2728
- var pivotIndex = randomIntInRange(p, r);
2729
- var i = p - 1;
2730
-
2731
- swap(ary, pivotIndex, r);
2732
- var pivot = ary[r];
2733
-
2734
- // Immediately after `j` is incremented in this loop, the following hold
2735
- // true:
2736
- //
2737
- // * Every element in `ary[p .. i]` is less than or equal to the pivot.
2738
- //
2739
- // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
2740
- for (var j = p; j < r; j++) {
2741
- if (comparator(ary[j], pivot) <= 0) {
2742
- i += 1;
2743
- swap(ary, i, j);
2744
- }
2745
- }
2746
-
2747
- swap(ary, i + 1, j);
2748
- var q = i + 1;
2749
-
2750
- // (2) Recurse on each half.
2751
-
2752
- doQuickSort(ary, comparator, p, q - 1);
2753
- doQuickSort(ary, comparator, q + 1, r);
2754
- }
2755
- }
2756
-
2757
- /**
2758
- * Sort the given array in-place with the given comparator function.
2759
- *
2760
- * @param {Array} ary
2761
- * An array to sort.
2762
- * @param {function} comparator
2763
- * Function to use to compare two items.
2764
- */
2765
- quickSort$1.quickSort = function (ary, comparator) {
2766
- doQuickSort(ary, comparator, 0, ary.length - 1);
2767
- };
2768
-
2769
- /* -*- Mode: js; js-indent-level: 2; -*- */
2770
-
2771
- /*
2772
- * Copyright 2011 Mozilla Foundation and contributors
2773
- * Licensed under the New BSD license. See LICENSE or:
2774
- * http://opensource.org/licenses/BSD-3-Clause
2775
- */
2776
-
2777
- var util$1 = util$5;
2778
- var binarySearch = binarySearch$1;
2779
- var ArraySet = arraySet.ArraySet;
2780
- var base64VLQ = base64Vlq;
2781
- var quickSort = quickSort$1.quickSort;
2782
-
2783
- function SourceMapConsumer(aSourceMap, aSourceMapURL) {
2784
- var sourceMap = aSourceMap;
2785
- if (typeof aSourceMap === 'string') {
2786
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
2787
- }
2788
-
2789
- return sourceMap.sections != null
2790
- ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
2791
- : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
2792
- }
2793
-
2794
- SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
2795
- return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
2796
- };
2797
-
2798
- /**
2799
- * The version of the source mapping spec that we are consuming.
2800
- */
2801
- SourceMapConsumer.prototype._version = 3;
2802
-
2803
- // `__generatedMappings` and `__originalMappings` are arrays that hold the
2804
- // parsed mapping coordinates from the source map's "mappings" attribute. They
2805
- // are lazily instantiated, accessed via the `_generatedMappings` and
2806
- // `_originalMappings` getters respectively, and we only parse the mappings
2807
- // and create these arrays once queried for a source location. We jump through
2808
- // these hoops because there can be many thousands of mappings, and parsing
2809
- // them is expensive, so we only want to do it if we must.
2810
- //
2811
- // Each object in the arrays is of the form:
2812
- //
2813
- // {
2814
- // generatedLine: The line number in the generated code,
2815
- // generatedColumn: The column number in the generated code,
2816
- // source: The path to the original source file that generated this
2817
- // chunk of code,
2818
- // originalLine: The line number in the original source that
2819
- // corresponds to this chunk of generated code,
2820
- // originalColumn: The column number in the original source that
2821
- // corresponds to this chunk of generated code,
2822
- // name: The name of the original symbol which generated this chunk of
2823
- // code.
2824
- // }
2825
- //
2826
- // All properties except for `generatedLine` and `generatedColumn` can be
2827
- // `null`.
2828
- //
2829
- // `_generatedMappings` is ordered by the generated positions.
2830
- //
2831
- // `_originalMappings` is ordered by the original positions.
2832
-
2833
- SourceMapConsumer.prototype.__generatedMappings = null;
2834
- Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
2835
- configurable: true,
2836
- enumerable: true,
2837
- get: function () {
2838
- if (!this.__generatedMappings) {
2839
- this._parseMappings(this._mappings, this.sourceRoot);
2840
- }
2841
-
2842
- return this.__generatedMappings;
2843
- }
2844
- });
2845
-
2846
- SourceMapConsumer.prototype.__originalMappings = null;
2847
- Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
2848
- configurable: true,
2849
- enumerable: true,
2850
- get: function () {
2851
- if (!this.__originalMappings) {
2852
- this._parseMappings(this._mappings, this.sourceRoot);
2853
- }
2854
-
2855
- return this.__originalMappings;
2856
- }
2857
- });
2858
-
2859
- SourceMapConsumer.prototype._charIsMappingSeparator =
2860
- function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
2861
- var c = aStr.charAt(index);
2862
- return c === ";" || c === ",";
2863
- };
2864
-
2865
- /**
2866
- * Parse the mappings in a string in to a data structure which we can easily
2867
- * query (the ordered arrays in the `this.__generatedMappings` and
2868
- * `this.__originalMappings` properties).
2869
- */
2870
- SourceMapConsumer.prototype._parseMappings =
2871
- function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
2872
- throw new Error("Subclasses must implement _parseMappings");
2873
- };
2874
-
2875
- SourceMapConsumer.GENERATED_ORDER = 1;
2876
- SourceMapConsumer.ORIGINAL_ORDER = 2;
2877
-
2878
- SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
2879
- SourceMapConsumer.LEAST_UPPER_BOUND = 2;
2880
-
2881
- /**
2882
- * Iterate over each mapping between an original source/line/column and a
2883
- * generated line/column in this source map.
2884
- *
2885
- * @param Function aCallback
2886
- * The function that is called with each mapping.
2887
- * @param Object aContext
2888
- * Optional. If specified, this object will be the value of `this` every
2889
- * time that `aCallback` is called.
2890
- * @param aOrder
2891
- * Either `SourceMapConsumer.GENERATED_ORDER` or
2892
- * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
2893
- * iterate over the mappings sorted by the generated file's line/column
2894
- * order or the original's source/line/column order, respectively. Defaults to
2895
- * `SourceMapConsumer.GENERATED_ORDER`.
2896
- */
2897
- SourceMapConsumer.prototype.eachMapping =
2898
- function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
2899
- var context = aContext || null;
2900
- var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
2901
-
2902
- var mappings;
2903
- switch (order) {
2904
- case SourceMapConsumer.GENERATED_ORDER:
2905
- mappings = this._generatedMappings;
2906
- break;
2907
- case SourceMapConsumer.ORIGINAL_ORDER:
2908
- mappings = this._originalMappings;
2909
- break;
2910
- default:
2911
- throw new Error("Unknown order of iteration.");
2912
- }
2913
-
2914
- var sourceRoot = this.sourceRoot;
2915
- mappings.map(function (mapping) {
2916
- var source = mapping.source === null ? null : this._sources.at(mapping.source);
2917
- source = util$1.computeSourceURL(sourceRoot, source, this._sourceMapURL);
2918
- return {
2919
- source: source,
2920
- generatedLine: mapping.generatedLine,
2921
- generatedColumn: mapping.generatedColumn,
2922
- originalLine: mapping.originalLine,
2923
- originalColumn: mapping.originalColumn,
2924
- name: mapping.name === null ? null : this._names.at(mapping.name)
2925
- };
2926
- }, this).forEach(aCallback, context);
2927
- };
2928
-
2929
- /**
2930
- * Returns all generated line and column information for the original source,
2931
- * line, and column provided. If no column is provided, returns all mappings
2932
- * corresponding to a either the line we are searching for or the next
2933
- * closest line that has any mappings. Otherwise, returns all mappings
2934
- * corresponding to the given line and either the column we are searching for
2935
- * or the next closest column that has any offsets.
2936
- *
2937
- * The only argument is an object with the following properties:
2938
- *
2939
- * - source: The filename of the original source.
2940
- * - line: The line number in the original source. The line number is 1-based.
2941
- * - column: Optional. the column number in the original source.
2942
- * The column number is 0-based.
2943
- *
2944
- * and an array of objects is returned, each with the following properties:
2945
- *
2946
- * - line: The line number in the generated source, or null. The
2947
- * line number is 1-based.
2948
- * - column: The column number in the generated source, or null.
2949
- * The column number is 0-based.
2950
- */
2951
- SourceMapConsumer.prototype.allGeneratedPositionsFor =
2952
- function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
2953
- var line = util$1.getArg(aArgs, 'line');
2954
-
2955
- // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
2956
- // returns the index of the closest mapping less than the needle. By
2957
- // setting needle.originalColumn to 0, we thus find the last mapping for
2958
- // the given line, provided such a mapping exists.
2959
- var needle = {
2960
- source: util$1.getArg(aArgs, 'source'),
2961
- originalLine: line,
2962
- originalColumn: util$1.getArg(aArgs, 'column', 0)
2963
- };
2964
-
2965
- needle.source = this._findSourceIndex(needle.source);
2966
- if (needle.source < 0) {
2967
- return [];
2968
- }
2969
-
2970
- var mappings = [];
2971
-
2972
- var index = this._findMapping(needle,
2973
- this._originalMappings,
2974
- "originalLine",
2975
- "originalColumn",
2976
- util$1.compareByOriginalPositions,
2977
- binarySearch.LEAST_UPPER_BOUND);
2978
- if (index >= 0) {
2979
- var mapping = this._originalMappings[index];
2980
-
2981
- if (aArgs.column === undefined) {
2982
- var originalLine = mapping.originalLine;
2983
-
2984
- // Iterate until either we run out of mappings, or we run into
2985
- // a mapping for a different line than the one we found. Since
2986
- // mappings are sorted, this is guaranteed to find all mappings for
2987
- // the line we found.
2988
- while (mapping && mapping.originalLine === originalLine) {
2989
- mappings.push({
2990
- line: util$1.getArg(mapping, 'generatedLine', null),
2991
- column: util$1.getArg(mapping, 'generatedColumn', null),
2992
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
2993
- });
2994
-
2995
- mapping = this._originalMappings[++index];
2996
- }
2997
- } else {
2998
- var originalColumn = mapping.originalColumn;
2999
-
3000
- // Iterate until either we run out of mappings, or we run into
3001
- // a mapping for a different line than the one we were searching for.
3002
- // Since mappings are sorted, this is guaranteed to find all mappings for
3003
- // the line we are searching for.
3004
- while (mapping &&
3005
- mapping.originalLine === line &&
3006
- mapping.originalColumn == originalColumn) {
3007
- mappings.push({
3008
- line: util$1.getArg(mapping, 'generatedLine', null),
3009
- column: util$1.getArg(mapping, 'generatedColumn', null),
3010
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
3011
- });
3012
-
3013
- mapping = this._originalMappings[++index];
3014
- }
3015
- }
3016
- }
3017
-
3018
- return mappings;
3019
- };
3020
-
3021
- sourceMapConsumer.SourceMapConsumer = SourceMapConsumer;
3022
-
3023
- /**
3024
- * A BasicSourceMapConsumer instance represents a parsed source map which we can
3025
- * query for information about the original file positions by giving it a file
3026
- * position in the generated source.
3027
- *
3028
- * The first parameter is the raw source map (either as a JSON string, or
3029
- * already parsed to an object). According to the spec, source maps have the
3030
- * following attributes:
3031
- *
3032
- * - version: Which version of the source map spec this map is following.
3033
- * - sources: An array of URLs to the original source files.
3034
- * - names: An array of identifiers which can be referrenced by individual mappings.
3035
- * - sourceRoot: Optional. The URL root from which all sources are relative.
3036
- * - sourcesContent: Optional. An array of contents of the original source files.
3037
- * - mappings: A string of base64 VLQs which contain the actual mappings.
3038
- * - file: Optional. The generated file this source map is associated with.
3039
- *
3040
- * Here is an example source map, taken from the source map spec[0]:
3041
- *
3042
- * {
3043
- * version : 3,
3044
- * file: "out.js",
3045
- * sourceRoot : "",
3046
- * sources: ["foo.js", "bar.js"],
3047
- * names: ["src", "maps", "are", "fun"],
3048
- * mappings: "AA,AB;;ABCDE;"
3049
- * }
3050
- *
3051
- * The second parameter, if given, is a string whose value is the URL
3052
- * at which the source map was found. This URL is used to compute the
3053
- * sources array.
3054
- *
3055
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
3056
- */
3057
- function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
3058
- var sourceMap = aSourceMap;
3059
- if (typeof aSourceMap === 'string') {
3060
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
3061
- }
3062
-
3063
- var version = util$1.getArg(sourceMap, 'version');
3064
- var sources = util$1.getArg(sourceMap, 'sources');
3065
- // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
3066
- // requires the array) to play nice here.
3067
- var names = util$1.getArg(sourceMap, 'names', []);
3068
- var sourceRoot = util$1.getArg(sourceMap, 'sourceRoot', null);
3069
- var sourcesContent = util$1.getArg(sourceMap, 'sourcesContent', null);
3070
- var mappings = util$1.getArg(sourceMap, 'mappings');
3071
- var file = util$1.getArg(sourceMap, 'file', null);
3072
-
3073
- // Once again, Sass deviates from the spec and supplies the version as a
3074
- // string rather than a number, so we use loose equality checking here.
3075
- if (version != this._version) {
3076
- throw new Error('Unsupported version: ' + version);
3077
- }
3078
-
3079
- if (sourceRoot) {
3080
- sourceRoot = util$1.normalize(sourceRoot);
3081
- }
3082
-
3083
- sources = sources
3084
- .map(String)
3085
- // Some source maps produce relative source paths like "./foo.js" instead of
3086
- // "foo.js". Normalize these first so that future comparisons will succeed.
3087
- // See bugzil.la/1090768.
3088
- .map(util$1.normalize)
3089
- // Always ensure that absolute sources are internally stored relative to
3090
- // the source root, if the source root is absolute. Not doing this would
3091
- // be particularly problematic when the source root is a prefix of the
3092
- // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
3093
- .map(function (source) {
3094
- return sourceRoot && util$1.isAbsolute(sourceRoot) && util$1.isAbsolute(source)
3095
- ? util$1.relative(sourceRoot, source)
3096
- : source;
3097
- });
3098
-
3099
- // Pass `true` below to allow duplicate names and sources. While source maps
3100
- // are intended to be compressed and deduplicated, the TypeScript compiler
3101
- // sometimes generates source maps with duplicates in them. See Github issue
3102
- // #72 and bugzil.la/889492.
3103
- this._names = ArraySet.fromArray(names.map(String), true);
3104
- this._sources = ArraySet.fromArray(sources, true);
3105
-
3106
- this._absoluteSources = this._sources.toArray().map(function (s) {
3107
- return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
3108
- });
3109
-
3110
- this.sourceRoot = sourceRoot;
3111
- this.sourcesContent = sourcesContent;
3112
- this._mappings = mappings;
3113
- this._sourceMapURL = aSourceMapURL;
3114
- this.file = file;
3115
- }
3116
-
3117
- BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
3118
- BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
3119
-
3120
- /**
3121
- * Utility function to find the index of a source. Returns -1 if not
3122
- * found.
3123
- */
3124
- BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
3125
- var relativeSource = aSource;
3126
- if (this.sourceRoot != null) {
3127
- relativeSource = util$1.relative(this.sourceRoot, relativeSource);
3128
- }
3129
-
3130
- if (this._sources.has(relativeSource)) {
3131
- return this._sources.indexOf(relativeSource);
3132
- }
3133
-
3134
- // Maybe aSource is an absolute URL as returned by |sources|. In
3135
- // this case we can't simply undo the transform.
3136
- var i;
3137
- for (i = 0; i < this._absoluteSources.length; ++i) {
3138
- if (this._absoluteSources[i] == aSource) {
3139
- return i;
3140
- }
3141
- }
3142
-
3143
- return -1;
3144
- };
3145
-
3146
- /**
3147
- * Create a BasicSourceMapConsumer from a SourceMapGenerator.
3148
- *
3149
- * @param SourceMapGenerator aSourceMap
3150
- * The source map that will be consumed.
3151
- * @param String aSourceMapURL
3152
- * The URL at which the source map can be found (optional)
3153
- * @returns BasicSourceMapConsumer
3154
- */
3155
- BasicSourceMapConsumer.fromSourceMap =
3156
- function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
3157
- var smc = Object.create(BasicSourceMapConsumer.prototype);
3158
-
3159
- var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
3160
- var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
3161
- smc.sourceRoot = aSourceMap._sourceRoot;
3162
- smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
3163
- smc.sourceRoot);
3164
- smc.file = aSourceMap._file;
3165
- smc._sourceMapURL = aSourceMapURL;
3166
- smc._absoluteSources = smc._sources.toArray().map(function (s) {
3167
- return util$1.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
3168
- });
3169
-
3170
- // Because we are modifying the entries (by converting string sources and
3171
- // names to indices into the sources and names ArraySets), we have to make
3172
- // a copy of the entry or else bad things happen. Shared mutable state
3173
- // strikes again! See github issue #191.
3174
-
3175
- var generatedMappings = aSourceMap._mappings.toArray().slice();
3176
- var destGeneratedMappings = smc.__generatedMappings = [];
3177
- var destOriginalMappings = smc.__originalMappings = [];
3178
-
3179
- for (var i = 0, length = generatedMappings.length; i < length; i++) {
3180
- var srcMapping = generatedMappings[i];
3181
- var destMapping = new Mapping;
3182
- destMapping.generatedLine = srcMapping.generatedLine;
3183
- destMapping.generatedColumn = srcMapping.generatedColumn;
3184
-
3185
- if (srcMapping.source) {
3186
- destMapping.source = sources.indexOf(srcMapping.source);
3187
- destMapping.originalLine = srcMapping.originalLine;
3188
- destMapping.originalColumn = srcMapping.originalColumn;
3189
-
3190
- if (srcMapping.name) {
3191
- destMapping.name = names.indexOf(srcMapping.name);
3192
- }
3193
-
3194
- destOriginalMappings.push(destMapping);
3195
- }
3196
-
3197
- destGeneratedMappings.push(destMapping);
3198
- }
3199
-
3200
- quickSort(smc.__originalMappings, util$1.compareByOriginalPositions);
3201
-
3202
- return smc;
3203
- };
3204
-
3205
- /**
3206
- * The version of the source mapping spec that we are consuming.
3207
- */
3208
- BasicSourceMapConsumer.prototype._version = 3;
3209
-
3210
- /**
3211
- * The list of original sources.
3212
- */
3213
- Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
3214
- get: function () {
3215
- return this._absoluteSources.slice();
3216
- }
3217
- });
3218
-
3219
- /**
3220
- * Provide the JIT with a nice shape / hidden class.
3221
- */
3222
- function Mapping() {
3223
- this.generatedLine = 0;
3224
- this.generatedColumn = 0;
3225
- this.source = null;
3226
- this.originalLine = null;
3227
- this.originalColumn = null;
3228
- this.name = null;
3229
- }
3230
-
3231
- /**
3232
- * Parse the mappings in a string in to a data structure which we can easily
3233
- * query (the ordered arrays in the `this.__generatedMappings` and
3234
- * `this.__originalMappings` properties).
3235
- */
3236
- BasicSourceMapConsumer.prototype._parseMappings =
3237
- function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
3238
- var generatedLine = 1;
3239
- var previousGeneratedColumn = 0;
3240
- var previousOriginalLine = 0;
3241
- var previousOriginalColumn = 0;
3242
- var previousSource = 0;
3243
- var previousName = 0;
3244
- var length = aStr.length;
3245
- var index = 0;
3246
- var cachedSegments = {};
3247
- var temp = {};
3248
- var originalMappings = [];
3249
- var generatedMappings = [];
3250
- var mapping, str, segment, end, value;
3251
-
3252
- while (index < length) {
3253
- if (aStr.charAt(index) === ';') {
3254
- generatedLine++;
3255
- index++;
3256
- previousGeneratedColumn = 0;
3257
- }
3258
- else if (aStr.charAt(index) === ',') {
3259
- index++;
3260
- }
3261
- else {
3262
- mapping = new Mapping();
3263
- mapping.generatedLine = generatedLine;
3264
-
3265
- // Because each offset is encoded relative to the previous one,
3266
- // many segments often have the same encoding. We can exploit this
3267
- // fact by caching the parsed variable length fields of each segment,
3268
- // allowing us to avoid a second parse if we encounter the same
3269
- // segment again.
3270
- for (end = index; end < length; end++) {
3271
- if (this._charIsMappingSeparator(aStr, end)) {
3272
- break;
3273
- }
3274
- }
3275
- str = aStr.slice(index, end);
3276
-
3277
- segment = cachedSegments[str];
3278
- if (segment) {
3279
- index += str.length;
3280
- } else {
3281
- segment = [];
3282
- while (index < end) {
3283
- base64VLQ.decode(aStr, index, temp);
3284
- value = temp.value;
3285
- index = temp.rest;
3286
- segment.push(value);
3287
- }
3288
-
3289
- if (segment.length === 2) {
3290
- throw new Error('Found a source, but no line and column');
3291
- }
3292
-
3293
- if (segment.length === 3) {
3294
- throw new Error('Found a source and line, but no column');
3295
- }
3296
-
3297
- cachedSegments[str] = segment;
3298
- }
3299
-
3300
- // Generated column.
3301
- mapping.generatedColumn = previousGeneratedColumn + segment[0];
3302
- previousGeneratedColumn = mapping.generatedColumn;
3303
-
3304
- if (segment.length > 1) {
3305
- // Original source.
3306
- mapping.source = previousSource + segment[1];
3307
- previousSource += segment[1];
3308
-
3309
- // Original line.
3310
- mapping.originalLine = previousOriginalLine + segment[2];
3311
- previousOriginalLine = mapping.originalLine;
3312
- // Lines are stored 0-based
3313
- mapping.originalLine += 1;
3314
-
3315
- // Original column.
3316
- mapping.originalColumn = previousOriginalColumn + segment[3];
3317
- previousOriginalColumn = mapping.originalColumn;
3318
-
3319
- if (segment.length > 4) {
3320
- // Original name.
3321
- mapping.name = previousName + segment[4];
3322
- previousName += segment[4];
3323
- }
3324
- }
3325
-
3326
- generatedMappings.push(mapping);
3327
- if (typeof mapping.originalLine === 'number') {
3328
- originalMappings.push(mapping);
3329
- }
3330
- }
3331
- }
3332
-
3333
- quickSort(generatedMappings, util$1.compareByGeneratedPositionsDeflated);
3334
- this.__generatedMappings = generatedMappings;
3335
-
3336
- quickSort(originalMappings, util$1.compareByOriginalPositions);
3337
- this.__originalMappings = originalMappings;
3338
- };
3339
-
3340
- /**
3341
- * Find the mapping that best matches the hypothetical "needle" mapping that
3342
- * we are searching for in the given "haystack" of mappings.
3343
- */
3344
- BasicSourceMapConsumer.prototype._findMapping =
3345
- function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
3346
- aColumnName, aComparator, aBias) {
3347
- // To return the position we are searching for, we must first find the
3348
- // mapping for the given position and then return the opposite position it
3349
- // points to. Because the mappings are sorted, we can use binary search to
3350
- // find the best mapping.
3351
-
3352
- if (aNeedle[aLineName] <= 0) {
3353
- throw new TypeError('Line must be greater than or equal to 1, got '
3354
- + aNeedle[aLineName]);
3355
- }
3356
- if (aNeedle[aColumnName] < 0) {
3357
- throw new TypeError('Column must be greater than or equal to 0, got '
3358
- + aNeedle[aColumnName]);
3359
- }
3360
-
3361
- return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
3362
- };
3363
-
3364
- /**
3365
- * Compute the last column for each generated mapping. The last column is
3366
- * inclusive.
3367
- */
3368
- BasicSourceMapConsumer.prototype.computeColumnSpans =
3369
- function SourceMapConsumer_computeColumnSpans() {
3370
- for (var index = 0; index < this._generatedMappings.length; ++index) {
3371
- var mapping = this._generatedMappings[index];
3372
-
3373
- // Mappings do not contain a field for the last generated columnt. We
3374
- // can come up with an optimistic estimate, however, by assuming that
3375
- // mappings are contiguous (i.e. given two consecutive mappings, the
3376
- // first mapping ends where the second one starts).
3377
- if (index + 1 < this._generatedMappings.length) {
3378
- var nextMapping = this._generatedMappings[index + 1];
3379
-
3380
- if (mapping.generatedLine === nextMapping.generatedLine) {
3381
- mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
3382
- continue;
3383
- }
3384
- }
3385
-
3386
- // The last mapping for each line spans the entire line.
3387
- mapping.lastGeneratedColumn = Infinity;
3388
- }
3389
- };
3390
-
3391
- /**
3392
- * Returns the original source, line, and column information for the generated
3393
- * source's line and column positions provided. The only argument is an object
3394
- * with the following properties:
3395
- *
3396
- * - line: The line number in the generated source. The line number
3397
- * is 1-based.
3398
- * - column: The column number in the generated source. The column
3399
- * number is 0-based.
3400
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
3401
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
3402
- * closest element that is smaller than or greater than the one we are
3403
- * searching for, respectively, if the exact element cannot be found.
3404
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
3405
- *
3406
- * and an object is returned with the following properties:
3407
- *
3408
- * - source: The original source file, or null.
3409
- * - line: The line number in the original source, or null. The
3410
- * line number is 1-based.
3411
- * - column: The column number in the original source, or null. The
3412
- * column number is 0-based.
3413
- * - name: The original identifier, or null.
3414
- */
3415
- BasicSourceMapConsumer.prototype.originalPositionFor =
3416
- function SourceMapConsumer_originalPositionFor(aArgs) {
3417
- var needle = {
3418
- generatedLine: util$1.getArg(aArgs, 'line'),
3419
- generatedColumn: util$1.getArg(aArgs, 'column')
3420
- };
3421
-
3422
- var index = this._findMapping(
3423
- needle,
3424
- this._generatedMappings,
3425
- "generatedLine",
3426
- "generatedColumn",
3427
- util$1.compareByGeneratedPositionsDeflated,
3428
- util$1.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
3429
- );
3430
-
3431
- if (index >= 0) {
3432
- var mapping = this._generatedMappings[index];
3433
-
3434
- if (mapping.generatedLine === needle.generatedLine) {
3435
- var source = util$1.getArg(mapping, 'source', null);
3436
- if (source !== null) {
3437
- source = this._sources.at(source);
3438
- source = util$1.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
3439
- }
3440
- var name = util$1.getArg(mapping, 'name', null);
3441
- if (name !== null) {
3442
- name = this._names.at(name);
3443
- }
3444
- return {
3445
- source: source,
3446
- line: util$1.getArg(mapping, 'originalLine', null),
3447
- column: util$1.getArg(mapping, 'originalColumn', null),
3448
- name: name
3449
- };
3450
- }
3451
- }
3452
-
3453
- return {
3454
- source: null,
3455
- line: null,
3456
- column: null,
3457
- name: null
3458
- };
3459
- };
3460
-
3461
- /**
3462
- * Return true if we have the source content for every source in the source
3463
- * map, false otherwise.
3464
- */
3465
- BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
3466
- function BasicSourceMapConsumer_hasContentsOfAllSources() {
3467
- if (!this.sourcesContent) {
3468
- return false;
3469
- }
3470
- return this.sourcesContent.length >= this._sources.size() &&
3471
- !this.sourcesContent.some(function (sc) { return sc == null; });
3472
- };
3473
-
3474
- /**
3475
- * Returns the original source content. The only argument is the url of the
3476
- * original source file. Returns null if no original source content is
3477
- * available.
3478
- */
3479
- BasicSourceMapConsumer.prototype.sourceContentFor =
3480
- function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
3481
- if (!this.sourcesContent) {
3482
- return null;
3483
- }
3484
-
3485
- var index = this._findSourceIndex(aSource);
3486
- if (index >= 0) {
3487
- return this.sourcesContent[index];
3488
- }
3489
-
3490
- var relativeSource = aSource;
3491
- if (this.sourceRoot != null) {
3492
- relativeSource = util$1.relative(this.sourceRoot, relativeSource);
3493
- }
3494
-
3495
- var url;
3496
- if (this.sourceRoot != null
3497
- && (url = util$1.urlParse(this.sourceRoot))) {
3498
- // XXX: file:// URIs and absolute paths lead to unexpected behavior for
3499
- // many users. We can help them out when they expect file:// URIs to
3500
- // behave like it would if they were running a local HTTP server. See
3501
- // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
3502
- var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
3503
- if (url.scheme == "file"
3504
- && this._sources.has(fileUriAbsPath)) {
3505
- return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
3506
- }
3507
-
3508
- if ((!url.path || url.path == "/")
3509
- && this._sources.has("/" + relativeSource)) {
3510
- return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
3511
- }
3512
- }
3513
-
3514
- // This function is used recursively from
3515
- // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
3516
- // don't want to throw if we can't find the source - we just want to
3517
- // return null, so we provide a flag to exit gracefully.
3518
- if (nullOnMissing) {
3519
- return null;
3520
- }
3521
- else {
3522
- throw new Error('"' + relativeSource + '" is not in the SourceMap.');
3523
- }
3524
- };
3525
-
3526
- /**
3527
- * Returns the generated line and column information for the original source,
3528
- * line, and column positions provided. The only argument is an object with
3529
- * the following properties:
3530
- *
3531
- * - source: The filename of the original source.
3532
- * - line: The line number in the original source. The line number
3533
- * is 1-based.
3534
- * - column: The column number in the original source. The column
3535
- * number is 0-based.
3536
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
3537
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
3538
- * closest element that is smaller than or greater than the one we are
3539
- * searching for, respectively, if the exact element cannot be found.
3540
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
3541
- *
3542
- * and an object is returned with the following properties:
3543
- *
3544
- * - line: The line number in the generated source, or null. The
3545
- * line number is 1-based.
3546
- * - column: The column number in the generated source, or null.
3547
- * The column number is 0-based.
3548
- */
3549
- BasicSourceMapConsumer.prototype.generatedPositionFor =
3550
- function SourceMapConsumer_generatedPositionFor(aArgs) {
3551
- var source = util$1.getArg(aArgs, 'source');
3552
- source = this._findSourceIndex(source);
3553
- if (source < 0) {
3554
- return {
3555
- line: null,
3556
- column: null,
3557
- lastColumn: null
3558
- };
3559
- }
3560
-
3561
- var needle = {
3562
- source: source,
3563
- originalLine: util$1.getArg(aArgs, 'line'),
3564
- originalColumn: util$1.getArg(aArgs, 'column')
3565
- };
3566
-
3567
- var index = this._findMapping(
3568
- needle,
3569
- this._originalMappings,
3570
- "originalLine",
3571
- "originalColumn",
3572
- util$1.compareByOriginalPositions,
3573
- util$1.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
3574
- );
3575
-
3576
- if (index >= 0) {
3577
- var mapping = this._originalMappings[index];
3578
-
3579
- if (mapping.source === needle.source) {
3580
- return {
3581
- line: util$1.getArg(mapping, 'generatedLine', null),
3582
- column: util$1.getArg(mapping, 'generatedColumn', null),
3583
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
3584
- };
3585
- }
3586
- }
3587
-
3588
- return {
3589
- line: null,
3590
- column: null,
3591
- lastColumn: null
3592
- };
3593
- };
3594
-
3595
- sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
3596
-
3597
- /**
3598
- * An IndexedSourceMapConsumer instance represents a parsed source map which
3599
- * we can query for information. It differs from BasicSourceMapConsumer in
3600
- * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
3601
- * input.
3602
- *
3603
- * The first parameter is a raw source map (either as a JSON string, or already
3604
- * parsed to an object). According to the spec for indexed source maps, they
3605
- * have the following attributes:
3606
- *
3607
- * - version: Which version of the source map spec this map is following.
3608
- * - file: Optional. The generated file this source map is associated with.
3609
- * - sections: A list of section definitions.
3610
- *
3611
- * Each value under the "sections" field has two fields:
3612
- * - offset: The offset into the original specified at which this section
3613
- * begins to apply, defined as an object with a "line" and "column"
3614
- * field.
3615
- * - map: A source map definition. This source map could also be indexed,
3616
- * but doesn't have to be.
3617
- *
3618
- * Instead of the "map" field, it's also possible to have a "url" field
3619
- * specifying a URL to retrieve a source map from, but that's currently
3620
- * unsupported.
3621
- *
3622
- * Here's an example source map, taken from the source map spec[0], but
3623
- * modified to omit a section which uses the "url" field.
3624
- *
3625
- * {
3626
- * version : 3,
3627
- * file: "app.js",
3628
- * sections: [{
3629
- * offset: {line:100, column:10},
3630
- * map: {
3631
- * version : 3,
3632
- * file: "section.js",
3633
- * sources: ["foo.js", "bar.js"],
3634
- * names: ["src", "maps", "are", "fun"],
3635
- * mappings: "AAAA,E;;ABCDE;"
3636
- * }
3637
- * }],
3638
- * }
3639
- *
3640
- * The second parameter, if given, is a string whose value is the URL
3641
- * at which the source map was found. This URL is used to compute the
3642
- * sources array.
3643
- *
3644
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
3645
- */
3646
- function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
3647
- var sourceMap = aSourceMap;
3648
- if (typeof aSourceMap === 'string') {
3649
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
3650
- }
3651
-
3652
- var version = util$1.getArg(sourceMap, 'version');
3653
- var sections = util$1.getArg(sourceMap, 'sections');
3654
-
3655
- if (version != this._version) {
3656
- throw new Error('Unsupported version: ' + version);
3657
- }
3658
-
3659
- this._sources = new ArraySet();
3660
- this._names = new ArraySet();
3661
-
3662
- var lastOffset = {
3663
- line: -1,
3664
- column: 0
3665
- };
3666
- this._sections = sections.map(function (s) {
3667
- if (s.url) {
3668
- // The url field will require support for asynchronicity.
3669
- // See https://github.com/mozilla/source-map/issues/16
3670
- throw new Error('Support for url field in sections not implemented.');
3671
- }
3672
- var offset = util$1.getArg(s, 'offset');
3673
- var offsetLine = util$1.getArg(offset, 'line');
3674
- var offsetColumn = util$1.getArg(offset, 'column');
3675
-
3676
- if (offsetLine < lastOffset.line ||
3677
- (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
3678
- throw new Error('Section offsets must be ordered and non-overlapping.');
3679
- }
3680
- lastOffset = offset;
3681
-
3682
- return {
3683
- generatedOffset: {
3684
- // The offset fields are 0-based, but we use 1-based indices when
3685
- // encoding/decoding from VLQ.
3686
- generatedLine: offsetLine + 1,
3687
- generatedColumn: offsetColumn + 1
3688
- },
3689
- consumer: new SourceMapConsumer(util$1.getArg(s, 'map'), aSourceMapURL)
3690
- }
3691
- });
3692
- }
3693
-
3694
- IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
3695
- IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
3696
-
3697
- /**
3698
- * The version of the source mapping spec that we are consuming.
3699
- */
3700
- IndexedSourceMapConsumer.prototype._version = 3;
3701
-
3702
- /**
3703
- * The list of original sources.
3704
- */
3705
- Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
3706
- get: function () {
3707
- var sources = [];
3708
- for (var i = 0; i < this._sections.length; i++) {
3709
- for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
3710
- sources.push(this._sections[i].consumer.sources[j]);
3711
- }
3712
- }
3713
- return sources;
3714
- }
3715
- });
3716
-
3717
- /**
3718
- * Returns the original source, line, and column information for the generated
3719
- * source's line and column positions provided. The only argument is an object
3720
- * with the following properties:
3721
- *
3722
- * - line: The line number in the generated source. The line number
3723
- * is 1-based.
3724
- * - column: The column number in the generated source. The column
3725
- * number is 0-based.
3726
- *
3727
- * and an object is returned with the following properties:
3728
- *
3729
- * - source: The original source file, or null.
3730
- * - line: The line number in the original source, or null. The
3731
- * line number is 1-based.
3732
- * - column: The column number in the original source, or null. The
3733
- * column number is 0-based.
3734
- * - name: The original identifier, or null.
3735
- */
3736
- IndexedSourceMapConsumer.prototype.originalPositionFor =
3737
- function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
3738
- var needle = {
3739
- generatedLine: util$1.getArg(aArgs, 'line'),
3740
- generatedColumn: util$1.getArg(aArgs, 'column')
3741
- };
3742
-
3743
- // Find the section containing the generated position we're trying to map
3744
- // to an original position.
3745
- var sectionIndex = binarySearch.search(needle, this._sections,
3746
- function(needle, section) {
3747
- var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
3748
- if (cmp) {
3749
- return cmp;
3750
- }
3751
-
3752
- return (needle.generatedColumn -
3753
- section.generatedOffset.generatedColumn);
3754
- });
3755
- var section = this._sections[sectionIndex];
3756
-
3757
- if (!section) {
3758
- return {
3759
- source: null,
3760
- line: null,
3761
- column: null,
3762
- name: null
3763
- };
3764
- }
3765
-
3766
- return section.consumer.originalPositionFor({
3767
- line: needle.generatedLine -
3768
- (section.generatedOffset.generatedLine - 1),
3769
- column: needle.generatedColumn -
3770
- (section.generatedOffset.generatedLine === needle.generatedLine
3771
- ? section.generatedOffset.generatedColumn - 1
3772
- : 0),
3773
- bias: aArgs.bias
3774
- });
3775
- };
3776
-
3777
- /**
3778
- * Return true if we have the source content for every source in the source
3779
- * map, false otherwise.
3780
- */
3781
- IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
3782
- function IndexedSourceMapConsumer_hasContentsOfAllSources() {
3783
- return this._sections.every(function (s) {
3784
- return s.consumer.hasContentsOfAllSources();
3785
- });
3786
- };
3787
-
3788
- /**
3789
- * Returns the original source content. The only argument is the url of the
3790
- * original source file. Returns null if no original source content is
3791
- * available.
3792
- */
3793
- IndexedSourceMapConsumer.prototype.sourceContentFor =
3794
- function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
3795
- for (var i = 0; i < this._sections.length; i++) {
3796
- var section = this._sections[i];
3797
-
3798
- var content = section.consumer.sourceContentFor(aSource, true);
3799
- if (content) {
3800
- return content;
3801
- }
3802
- }
3803
- if (nullOnMissing) {
3804
- return null;
3805
- }
3806
- else {
3807
- throw new Error('"' + aSource + '" is not in the SourceMap.');
3808
- }
3809
- };
3810
-
3811
- /**
3812
- * Returns the generated line and column information for the original source,
3813
- * line, and column positions provided. The only argument is an object with
3814
- * the following properties:
3815
- *
3816
- * - source: The filename of the original source.
3817
- * - line: The line number in the original source. The line number
3818
- * is 1-based.
3819
- * - column: The column number in the original source. The column
3820
- * number is 0-based.
3821
- *
3822
- * and an object is returned with the following properties:
3823
- *
3824
- * - line: The line number in the generated source, or null. The
3825
- * line number is 1-based.
3826
- * - column: The column number in the generated source, or null.
3827
- * The column number is 0-based.
3828
- */
3829
- IndexedSourceMapConsumer.prototype.generatedPositionFor =
3830
- function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
3831
- for (var i = 0; i < this._sections.length; i++) {
3832
- var section = this._sections[i];
3833
-
3834
- // Only consider this section if the requested source is in the list of
3835
- // sources of the consumer.
3836
- if (section.consumer._findSourceIndex(util$1.getArg(aArgs, 'source')) === -1) {
3837
- continue;
3838
- }
3839
- var generatedPosition = section.consumer.generatedPositionFor(aArgs);
3840
- if (generatedPosition) {
3841
- var ret = {
3842
- line: generatedPosition.line +
3843
- (section.generatedOffset.generatedLine - 1),
3844
- column: generatedPosition.column +
3845
- (section.generatedOffset.generatedLine === generatedPosition.line
3846
- ? section.generatedOffset.generatedColumn - 1
3847
- : 0)
3848
- };
3849
- return ret;
3850
- }
3851
- }
3852
-
3853
- return {
3854
- line: null,
3855
- column: null
3856
- };
3857
- };
3858
-
3859
- /**
3860
- * Parse the mappings in a string in to a data structure which we can easily
3861
- * query (the ordered arrays in the `this.__generatedMappings` and
3862
- * `this.__originalMappings` properties).
3863
- */
3864
- IndexedSourceMapConsumer.prototype._parseMappings =
3865
- function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
3866
- this.__generatedMappings = [];
3867
- this.__originalMappings = [];
3868
- for (var i = 0; i < this._sections.length; i++) {
3869
- var section = this._sections[i];
3870
- var sectionMappings = section.consumer._generatedMappings;
3871
- for (var j = 0; j < sectionMappings.length; j++) {
3872
- var mapping = sectionMappings[j];
3873
-
3874
- var source = section.consumer._sources.at(mapping.source);
3875
- source = util$1.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
3876
- this._sources.add(source);
3877
- source = this._sources.indexOf(source);
3878
-
3879
- var name = null;
3880
- if (mapping.name) {
3881
- name = section.consumer._names.at(mapping.name);
3882
- this._names.add(name);
3883
- name = this._names.indexOf(name);
3884
- }
3885
-
3886
- // The mappings coming from the consumer for the section have
3887
- // generated positions relative to the start of the section, so we
3888
- // need to offset them to be relative to the start of the concatenated
3889
- // generated file.
3890
- var adjustedMapping = {
3891
- source: source,
3892
- generatedLine: mapping.generatedLine +
3893
- (section.generatedOffset.generatedLine - 1),
3894
- generatedColumn: mapping.generatedColumn +
3895
- (section.generatedOffset.generatedLine === mapping.generatedLine
3896
- ? section.generatedOffset.generatedColumn - 1
3897
- : 0),
3898
- originalLine: mapping.originalLine,
3899
- originalColumn: mapping.originalColumn,
3900
- name: name
3901
- };
3902
-
3903
- this.__generatedMappings.push(adjustedMapping);
3904
- if (typeof adjustedMapping.originalLine === 'number') {
3905
- this.__originalMappings.push(adjustedMapping);
3906
- }
3907
- }
3908
- }
3909
-
3910
- quickSort(this.__generatedMappings, util$1.compareByGeneratedPositionsDeflated);
3911
- quickSort(this.__originalMappings, util$1.compareByOriginalPositions);
3912
- };
3913
-
3914
- sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
3915
-
3916
- var sourceNode = {};
3917
-
3918
- /* -*- Mode: js; js-indent-level: 2; -*- */
3919
-
3920
- /*
3921
- * Copyright 2011 Mozilla Foundation and contributors
3922
- * Licensed under the New BSD license. See LICENSE or:
3923
- * http://opensource.org/licenses/BSD-3-Clause
3924
- */
3925
-
3926
- var SourceMapGenerator$1 = sourceMapGenerator.SourceMapGenerator;
3927
- var util = util$5;
3928
-
3929
- // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
3930
- // operating systems these days (capturing the result).
3931
- var REGEX_NEWLINE = /(\r?\n)/;
3932
-
3933
- // Newline character code for charCodeAt() comparisons
3934
- var NEWLINE_CODE = 10;
3935
-
3936
- // Private symbol for identifying `SourceNode`s when multiple versions of
3937
- // the source-map library are loaded. This MUST NOT CHANGE across
3938
- // versions!
3939
- var isSourceNode = "$$$isSourceNode$$$";
3940
-
3941
- /**
3942
- * SourceNodes provide a way to abstract over interpolating/concatenating
3943
- * snippets of generated JavaScript source code while maintaining the line and
3944
- * column information associated with the original source code.
3945
- *
3946
- * @param aLine The original line number.
3947
- * @param aColumn The original column number.
3948
- * @param aSource The original source's filename.
3949
- * @param aChunks Optional. An array of strings which are snippets of
3950
- * generated JS, or other SourceNodes.
3951
- * @param aName The original identifier.
3952
- */
3953
- function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
3954
- this.children = [];
3955
- this.sourceContents = {};
3956
- this.line = aLine == null ? null : aLine;
3957
- this.column = aColumn == null ? null : aColumn;
3958
- this.source = aSource == null ? null : aSource;
3959
- this.name = aName == null ? null : aName;
3960
- this[isSourceNode] = true;
3961
- if (aChunks != null) this.add(aChunks);
3962
- }
3963
-
3964
- /**
3965
- * Creates a SourceNode from generated code and a SourceMapConsumer.
3966
- *
3967
- * @param aGeneratedCode The generated code
3968
- * @param aSourceMapConsumer The SourceMap for the generated code
3969
- * @param aRelativePath Optional. The path that relative sources in the
3970
- * SourceMapConsumer should be relative to.
3971
- */
3972
- SourceNode.fromStringWithSourceMap =
3973
- function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
3974
- // The SourceNode we want to fill with the generated code
3975
- // and the SourceMap
3976
- var node = new SourceNode();
3977
-
3978
- // All even indices of this array are one line of the generated code,
3979
- // while all odd indices are the newlines between two adjacent lines
3980
- // (since `REGEX_NEWLINE` captures its match).
3981
- // Processed fragments are accessed by calling `shiftNextLine`.
3982
- var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
3983
- var remainingLinesIndex = 0;
3984
- var shiftNextLine = function() {
3985
- var lineContents = getNextLine();
3986
- // The last line of a file might not have a newline.
3987
- var newLine = getNextLine() || "";
3988
- return lineContents + newLine;
3989
-
3990
- function getNextLine() {
3991
- return remainingLinesIndex < remainingLines.length ?
3992
- remainingLines[remainingLinesIndex++] : undefined;
3993
- }
3994
- };
3995
-
3996
- // We need to remember the position of "remainingLines"
3997
- var lastGeneratedLine = 1, lastGeneratedColumn = 0;
3998
-
3999
- // The generate SourceNodes we need a code range.
4000
- // To extract it current and last mapping is used.
4001
- // Here we store the last mapping.
4002
- var lastMapping = null;
4003
-
4004
- aSourceMapConsumer.eachMapping(function (mapping) {
4005
- if (lastMapping !== null) {
4006
- // We add the code from "lastMapping" to "mapping":
4007
- // First check if there is a new line in between.
4008
- if (lastGeneratedLine < mapping.generatedLine) {
4009
- // Associate first line with "lastMapping"
4010
- addMappingWithCode(lastMapping, shiftNextLine());
4011
- lastGeneratedLine++;
4012
- lastGeneratedColumn = 0;
4013
- // The remaining code is added without mapping
4014
- } else {
4015
- // There is no new line in between.
4016
- // Associate the code between "lastGeneratedColumn" and
4017
- // "mapping.generatedColumn" with "lastMapping"
4018
- var nextLine = remainingLines[remainingLinesIndex] || '';
4019
- var code = nextLine.substr(0, mapping.generatedColumn -
4020
- lastGeneratedColumn);
4021
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
4022
- lastGeneratedColumn);
4023
- lastGeneratedColumn = mapping.generatedColumn;
4024
- addMappingWithCode(lastMapping, code);
4025
- // No more remaining code, continue
4026
- lastMapping = mapping;
4027
- return;
4028
- }
4029
- }
4030
- // We add the generated code until the first mapping
4031
- // to the SourceNode without any mapping.
4032
- // Each line is added as separate string.
4033
- while (lastGeneratedLine < mapping.generatedLine) {
4034
- node.add(shiftNextLine());
4035
- lastGeneratedLine++;
4036
- }
4037
- if (lastGeneratedColumn < mapping.generatedColumn) {
4038
- var nextLine = remainingLines[remainingLinesIndex] || '';
4039
- node.add(nextLine.substr(0, mapping.generatedColumn));
4040
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
4041
- lastGeneratedColumn = mapping.generatedColumn;
4042
- }
4043
- lastMapping = mapping;
4044
- }, this);
4045
- // We have processed all mappings.
4046
- if (remainingLinesIndex < remainingLines.length) {
4047
- if (lastMapping) {
4048
- // Associate the remaining code in the current line with "lastMapping"
4049
- addMappingWithCode(lastMapping, shiftNextLine());
4050
- }
4051
- // and add the remaining lines without any mapping
4052
- node.add(remainingLines.splice(remainingLinesIndex).join(""));
4053
- }
4054
-
4055
- // Copy sourcesContent into SourceNode
4056
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
4057
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
4058
- if (content != null) {
4059
- if (aRelativePath != null) {
4060
- sourceFile = util.join(aRelativePath, sourceFile);
4061
- }
4062
- node.setSourceContent(sourceFile, content);
4063
- }
4064
- });
4065
-
4066
- return node;
4067
-
4068
- function addMappingWithCode(mapping, code) {
4069
- if (mapping === null || mapping.source === undefined) {
4070
- node.add(code);
4071
- } else {
4072
- var source = aRelativePath
4073
- ? util.join(aRelativePath, mapping.source)
4074
- : mapping.source;
4075
- node.add(new SourceNode(mapping.originalLine,
4076
- mapping.originalColumn,
4077
- source,
4078
- code,
4079
- mapping.name));
4080
- }
4081
- }
4082
- };
4083
-
4084
- /**
4085
- * Add a chunk of generated JS to this source node.
4086
- *
4087
- * @param aChunk A string snippet of generated JS code, another instance of
4088
- * SourceNode, or an array where each member is one of those things.
4089
- */
4090
- SourceNode.prototype.add = function SourceNode_add(aChunk) {
4091
- if (Array.isArray(aChunk)) {
4092
- aChunk.forEach(function (chunk) {
4093
- this.add(chunk);
4094
- }, this);
4095
- }
4096
- else if (aChunk[isSourceNode] || typeof aChunk === "string") {
4097
- if (aChunk) {
4098
- this.children.push(aChunk);
4099
- }
4100
- }
4101
- else {
4102
- throw new TypeError(
4103
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
4104
- );
4105
- }
4106
- return this;
4107
- };
4108
-
4109
- /**
4110
- * Add a chunk of generated JS to the beginning of this source node.
4111
- *
4112
- * @param aChunk A string snippet of generated JS code, another instance of
4113
- * SourceNode, or an array where each member is one of those things.
4114
- */
4115
- SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
4116
- if (Array.isArray(aChunk)) {
4117
- for (var i = aChunk.length-1; i >= 0; i--) {
4118
- this.prepend(aChunk[i]);
4119
- }
4120
- }
4121
- else if (aChunk[isSourceNode] || typeof aChunk === "string") {
4122
- this.children.unshift(aChunk);
4123
- }
4124
- else {
4125
- throw new TypeError(
4126
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
4127
- );
4128
- }
4129
- return this;
4130
- };
4131
-
4132
- /**
4133
- * Walk over the tree of JS snippets in this node and its children. The
4134
- * walking function is called once for each snippet of JS and is passed that
4135
- * snippet and the its original associated source's line/column location.
4136
- *
4137
- * @param aFn The traversal function.
4138
- */
4139
- SourceNode.prototype.walk = function SourceNode_walk(aFn) {
4140
- var chunk;
4141
- for (var i = 0, len = this.children.length; i < len; i++) {
4142
- chunk = this.children[i];
4143
- if (chunk[isSourceNode]) {
4144
- chunk.walk(aFn);
4145
- }
4146
- else {
4147
- if (chunk !== '') {
4148
- aFn(chunk, { source: this.source,
4149
- line: this.line,
4150
- column: this.column,
4151
- name: this.name });
4152
- }
4153
- }
4154
- }
4155
- };
4156
-
4157
- /**
4158
- * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
4159
- * each of `this.children`.
4160
- *
4161
- * @param aSep The separator.
4162
- */
4163
- SourceNode.prototype.join = function SourceNode_join(aSep) {
4164
- var newChildren;
4165
- var i;
4166
- var len = this.children.length;
4167
- if (len > 0) {
4168
- newChildren = [];
4169
- for (i = 0; i < len-1; i++) {
4170
- newChildren.push(this.children[i]);
4171
- newChildren.push(aSep);
4172
- }
4173
- newChildren.push(this.children[i]);
4174
- this.children = newChildren;
4175
- }
4176
- return this;
4177
- };
4178
-
4179
- /**
4180
- * Call String.prototype.replace on the very right-most source snippet. Useful
4181
- * for trimming whitespace from the end of a source node, etc.
4182
- *
4183
- * @param aPattern The pattern to replace.
4184
- * @param aReplacement The thing to replace the pattern with.
4185
- */
4186
- SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
4187
- var lastChild = this.children[this.children.length - 1];
4188
- if (lastChild[isSourceNode]) {
4189
- lastChild.replaceRight(aPattern, aReplacement);
4190
- }
4191
- else if (typeof lastChild === 'string') {
4192
- this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
4193
- }
4194
- else {
4195
- this.children.push(''.replace(aPattern, aReplacement));
4196
- }
4197
- return this;
4198
- };
4199
-
4200
- /**
4201
- * Set the source content for a source file. This will be added to the SourceMapGenerator
4202
- * in the sourcesContent field.
4203
- *
4204
- * @param aSourceFile The filename of the source file
4205
- * @param aSourceContent The content of the source file
4206
- */
4207
- SourceNode.prototype.setSourceContent =
4208
- function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
4209
- this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
4210
- };
4211
-
4212
- /**
4213
- * Walk over the tree of SourceNodes. The walking function is called for each
4214
- * source file content and is passed the filename and source content.
4215
- *
4216
- * @param aFn The traversal function.
4217
- */
4218
- SourceNode.prototype.walkSourceContents =
4219
- function SourceNode_walkSourceContents(aFn) {
4220
- for (var i = 0, len = this.children.length; i < len; i++) {
4221
- if (this.children[i][isSourceNode]) {
4222
- this.children[i].walkSourceContents(aFn);
4223
- }
4224
- }
4225
-
4226
- var sources = Object.keys(this.sourceContents);
4227
- for (var i = 0, len = sources.length; i < len; i++) {
4228
- aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
4229
- }
4230
- };
4231
-
4232
- /**
4233
- * Return the string representation of this source node. Walks over the tree
4234
- * and concatenates all the various snippets together to one string.
4235
- */
4236
- SourceNode.prototype.toString = function SourceNode_toString() {
4237
- var str = "";
4238
- this.walk(function (chunk) {
4239
- str += chunk;
4240
- });
4241
- return str;
4242
- };
4243
-
4244
- /**
4245
- * Returns the string representation of this source node along with a source
4246
- * map.
4247
- */
4248
- SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
4249
- var generated = {
4250
- code: "",
4251
- line: 1,
4252
- column: 0
4253
- };
4254
- var map = new SourceMapGenerator$1(aArgs);
4255
- var sourceMappingActive = false;
4256
- var lastOriginalSource = null;
4257
- var lastOriginalLine = null;
4258
- var lastOriginalColumn = null;
4259
- var lastOriginalName = null;
4260
- this.walk(function (chunk, original) {
4261
- generated.code += chunk;
4262
- if (original.source !== null
4263
- && original.line !== null
4264
- && original.column !== null) {
4265
- if(lastOriginalSource !== original.source
4266
- || lastOriginalLine !== original.line
4267
- || lastOriginalColumn !== original.column
4268
- || lastOriginalName !== original.name) {
4269
- map.addMapping({
4270
- source: original.source,
4271
- original: {
4272
- line: original.line,
4273
- column: original.column
4274
- },
4275
- generated: {
4276
- line: generated.line,
4277
- column: generated.column
4278
- },
4279
- name: original.name
4280
- });
4281
- }
4282
- lastOriginalSource = original.source;
4283
- lastOriginalLine = original.line;
4284
- lastOriginalColumn = original.column;
4285
- lastOriginalName = original.name;
4286
- sourceMappingActive = true;
4287
- } else if (sourceMappingActive) {
4288
- map.addMapping({
4289
- generated: {
4290
- line: generated.line,
4291
- column: generated.column
4292
- }
4293
- });
4294
- lastOriginalSource = null;
4295
- sourceMappingActive = false;
4296
- }
4297
- for (var idx = 0, length = chunk.length; idx < length; idx++) {
4298
- if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
4299
- generated.line++;
4300
- generated.column = 0;
4301
- // Mappings end at eol
4302
- if (idx + 1 === length) {
4303
- lastOriginalSource = null;
4304
- sourceMappingActive = false;
4305
- } else if (sourceMappingActive) {
4306
- map.addMapping({
4307
- source: original.source,
4308
- original: {
4309
- line: original.line,
4310
- column: original.column
4311
- },
4312
- generated: {
4313
- line: generated.line,
4314
- column: generated.column
4315
- },
4316
- name: original.name
4317
- });
4318
- }
4319
- } else {
4320
- generated.column++;
4321
- }
4322
- }
4323
- });
4324
- this.walkSourceContents(function (sourceFile, sourceContent) {
4325
- map.setSourceContent(sourceFile, sourceContent);
4326
- });
4327
-
4328
- return { code: generated.code, map: map };
4329
- };
4330
-
4331
- sourceNode.SourceNode = SourceNode;
4332
-
4333
- /*
4334
- * Copyright 2009-2011 Mozilla Foundation and contributors
4335
- * Licensed under the New BSD license. See LICENSE.txt or:
4336
- * http://opensource.org/licenses/BSD-3-Clause
4337
- */
4338
-
4339
- var SourceMapGenerator = sourceMap.SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
4340
- sourceMap.SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
4341
- sourceMap.SourceNode = sourceNode.SourceNode;
4342
-
4343
1179
  function createCodeGenerator(ast, options) {
4344
1180
  const { sourceMap, filename, breakLineCode, needIndent: _needIndent } = options;
4345
1181
  const _context = {
@@ -4357,12 +1193,6 @@ function createCodeGenerator(ast, options) {
4357
1193
  const context = () => _context;
4358
1194
  function push(code, node) {
4359
1195
  _context.code += code;
4360
- if (_context.map) {
4361
- if (node && node.loc && node.loc !== LocationStub) {
4362
- addMapping(node.loc.start, getMappingName(node));
4363
- }
4364
- advancePositionWithSource(_context, code);
4365
- }
4366
1196
  }
4367
1197
  function _newline(n, withBreakLine = true) {
4368
1198
  const _breakLineCode = withBreakLine ? breakLineCode : '';
@@ -4381,24 +1211,6 @@ function createCodeGenerator(ast, options) {
4381
1211
  }
4382
1212
  const helper = (key) => `_${key}`;
4383
1213
  const needIndent = () => _context.needIndent;
4384
- function addMapping(loc, name) {
4385
- _context.map.addMapping({
4386
- name,
4387
- source: _context.filename,
4388
- original: {
4389
- line: loc.line,
4390
- column: loc.column - 1
4391
- },
4392
- generated: {
4393
- line: _context.line,
4394
- column: _context.column - 1
4395
- }
4396
- });
4397
- }
4398
- if (sourceMap) {
4399
- _context.map = new SourceMapGenerator();
4400
- _context.map.setSourceContent(filename, _context.source);
4401
- }
4402
1214
  return {
4403
1215
  context,
4404
1216
  push,
@@ -4537,42 +1349,7 @@ const generate = (ast, options = {} // eslint-disable-line
4537
1349
  code,
4538
1350
  map: map ? map.toJSON() : undefined // eslint-disable-line @typescript-eslint/no-explicit-any
4539
1351
  };
4540
- };
4541
- function getMappingName(node) {
4542
- switch (node.type) {
4543
- case 3 /* Text */:
4544
- return node.value;
4545
- case 5 /* List */:
4546
- return node.index.toString();
4547
- case 4 /* Named */:
4548
- return node.key;
4549
- case 9 /* Literal */:
4550
- return node.value;
4551
- case 8 /* LinkedModifier */:
4552
- return node.value;
4553
- case 7 /* LinkedKey */:
4554
- return node.value;
4555
- default:
4556
- return undefined;
4557
- }
4558
- }
4559
- function advancePositionWithSource(pos, source, numberOfCharacters = source.length) {
4560
- let linesCount = 0;
4561
- let lastNewLinePos = -1;
4562
- for (let i = 0; i < numberOfCharacters; i++) {
4563
- if (source.charCodeAt(i) === 10 /* newline char code */) {
4564
- linesCount++;
4565
- lastNewLinePos = i;
4566
- }
4567
- }
4568
- pos.offset += numberOfCharacters;
4569
- pos.line += linesCount;
4570
- pos.column =
4571
- lastNewLinePos === -1
4572
- ? pos.column + numberOfCharacters
4573
- : numberOfCharacters - lastNewLinePos;
4574
- return pos;
4575
- }
1352
+ };
4576
1353
 
4577
1354
  function baseCompile(source, options = {}) {
4578
1355
  const assignedOptions = assign({}, options);