You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3350 lines
104 KiB

4 years ago
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("fs"), require("path"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["fs", "path"], factory);
  6. else if(typeof exports === 'object')
  7. exports["sourceMap"] = factory(require("fs"), require("path"));
  8. else
  9. root["sourceMap"] = factory(root["fs"], root["path"]);
  10. })(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_10__, __WEBPACK_EXTERNAL_MODULE_11__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, {
  50. /******/ configurable: false,
  51. /******/ enumerable: true,
  52. /******/ get: getter
  53. /******/ });
  54. /******/ }
  55. /******/ };
  56. /******/
  57. /******/ // getDefaultExport function for compatibility with non-harmony modules
  58. /******/ __webpack_require__.n = function(module) {
  59. /******/ var getter = module && module.__esModule ?
  60. /******/ function getDefault() { return module['default']; } :
  61. /******/ function getModuleExports() { return module; };
  62. /******/ __webpack_require__.d(getter, 'a', getter);
  63. /******/ return getter;
  64. /******/ };
  65. /******/
  66. /******/ // Object.prototype.hasOwnProperty.call
  67. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  68. /******/
  69. /******/ // __webpack_public_path__
  70. /******/ __webpack_require__.p = "";
  71. /******/
  72. /******/ // Load entry module and return exports
  73. /******/ return __webpack_require__(__webpack_require__.s = 5);
  74. /******/ })
  75. /************************************************************************/
  76. /******/ ([
  77. /* 0 */
  78. /***/ (function(module, exports) {
  79. /* -*- Mode: js; js-indent-level: 2; -*- */
  80. /*
  81. * Copyright 2011 Mozilla Foundation and contributors
  82. * Licensed under the New BSD license. See LICENSE or:
  83. * http://opensource.org/licenses/BSD-3-Clause
  84. */
  85. /**
  86. * This is a helper function for getting values from parameter/options
  87. * objects.
  88. *
  89. * @param args The object we are extracting values from
  90. * @param name The name of the property we are getting.
  91. * @param defaultValue An optional value to return if the property is missing
  92. * from the object. If this is not specified and the property is missing, an
  93. * error will be thrown.
  94. */
  95. function getArg(aArgs, aName, aDefaultValue) {
  96. if (aName in aArgs) {
  97. return aArgs[aName];
  98. } else if (arguments.length === 3) {
  99. return aDefaultValue;
  100. }
  101. throw new Error('"' + aName + '" is a required argument.');
  102. }
  103. exports.getArg = getArg;
  104. const urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
  105. const dataUrlRegexp = /^data:.+\,.+$/;
  106. function urlParse(aUrl) {
  107. const match = aUrl.match(urlRegexp);
  108. if (!match) {
  109. return null;
  110. }
  111. return {
  112. scheme: match[1],
  113. auth: match[2],
  114. host: match[3],
  115. port: match[4],
  116. path: match[5]
  117. };
  118. }
  119. exports.urlParse = urlParse;
  120. function urlGenerate(aParsedUrl) {
  121. let url = "";
  122. if (aParsedUrl.scheme) {
  123. url += aParsedUrl.scheme + ":";
  124. }
  125. url += "//";
  126. if (aParsedUrl.auth) {
  127. url += aParsedUrl.auth + "@";
  128. }
  129. if (aParsedUrl.host) {
  130. url += aParsedUrl.host;
  131. }
  132. if (aParsedUrl.port) {
  133. url += ":" + aParsedUrl.port;
  134. }
  135. if (aParsedUrl.path) {
  136. url += aParsedUrl.path;
  137. }
  138. return url;
  139. }
  140. exports.urlGenerate = urlGenerate;
  141. const MAX_CACHED_INPUTS = 32;
  142. /**
  143. * Takes some function `f(input) -> result` and returns a memoized version of
  144. * `f`.
  145. *
  146. * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
  147. * memoization is a dumb-simple, linear least-recently-used cache.
  148. */
  149. function lruMemoize(f) {
  150. const cache = [];
  151. return function(input) {
  152. for (let i = 0; i < cache.length; i++) {
  153. if (cache[i].input === input) {
  154. const temp = cache[0];
  155. cache[0] = cache[i];
  156. cache[i] = temp;
  157. return cache[0].result;
  158. }
  159. }
  160. const result = f(input);
  161. cache.unshift({
  162. input,
  163. result,
  164. });
  165. if (cache.length > MAX_CACHED_INPUTS) {
  166. cache.pop();
  167. }
  168. return result;
  169. };
  170. }
  171. /**
  172. * Normalizes a path, or the path portion of a URL:
  173. *
  174. * - Replaces consecutive slashes with one slash.
  175. * - Removes unnecessary '.' parts.
  176. * - Removes unnecessary '<dir>/..' parts.
  177. *
  178. * Based on code in the Node.js 'path' core module.
  179. *
  180. * @param aPath The path or url to normalize.
  181. */
  182. const normalize = lruMemoize(function normalize(aPath) {
  183. let path = aPath;
  184. const url = urlParse(aPath);
  185. if (url) {
  186. if (!url.path) {
  187. return aPath;
  188. }
  189. path = url.path;
  190. }
  191. const isAbsolute = exports.isAbsolute(path);
  192. // Split the path into parts between `/` characters. This is much faster than
  193. // using `.split(/\/+/g)`.
  194. const parts = [];
  195. let start = 0;
  196. let i = 0;
  197. while (true) {
  198. start = i;
  199. i = path.indexOf("/", start);
  200. if (i === -1) {
  201. parts.push(path.slice(start));
  202. break;
  203. } else {
  204. parts.push(path.slice(start, i));
  205. while (i < path.length && path[i] === "/") {
  206. i++;
  207. }
  208. }
  209. }
  210. let up = 0;
  211. for (i = parts.length - 1; i >= 0; i--) {
  212. const part = parts[i];
  213. if (part === ".") {
  214. parts.splice(i, 1);
  215. } else if (part === "..") {
  216. up++;
  217. } else if (up > 0) {
  218. if (part === "") {
  219. // The first part is blank if the path is absolute. Trying to go
  220. // above the root is a no-op. Therefore we can remove all '..' parts
  221. // directly after the root.
  222. parts.splice(i + 1, up);
  223. up = 0;
  224. } else {
  225. parts.splice(i, 2);
  226. up--;
  227. }
  228. }
  229. }
  230. path = parts.join("/");
  231. if (path === "") {
  232. path = isAbsolute ? "/" : ".";
  233. }
  234. if (url) {
  235. url.path = path;
  236. return urlGenerate(url);
  237. }
  238. return path;
  239. });
  240. exports.normalize = normalize;
  241. /**
  242. * Joins two paths/URLs.
  243. *
  244. * @param aRoot The root path or URL.
  245. * @param aPath The path or URL to be joined with the root.
  246. *
  247. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  248. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  249. * first.
  250. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  251. * is updated with the result and aRoot is returned. Otherwise the result
  252. * is returned.
  253. * - If aPath is absolute, the result is aPath.
  254. * - Otherwise the two paths are joined with a slash.
  255. * - Joining for example 'http://' and 'www.example.com' is also supported.
  256. */
  257. function join(aRoot, aPath) {
  258. if (aRoot === "") {
  259. aRoot = ".";
  260. }
  261. if (aPath === "") {
  262. aPath = ".";
  263. }
  264. const aPathUrl = urlParse(aPath);
  265. const aRootUrl = urlParse(aRoot);
  266. if (aRootUrl) {
  267. aRoot = aRootUrl.path || "/";
  268. }
  269. // `join(foo, '//www.example.org')`
  270. if (aPathUrl && !aPathUrl.scheme) {
  271. if (aRootUrl) {
  272. aPathUrl.scheme = aRootUrl.scheme;
  273. }
  274. return urlGenerate(aPathUrl);
  275. }
  276. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  277. return aPath;
  278. }
  279. // `join('http://', 'www.example.com')`
  280. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  281. aRootUrl.host = aPath;
  282. return urlGenerate(aRootUrl);
  283. }
  284. const joined = aPath.charAt(0) === "/"
  285. ? aPath
  286. : normalize(aRoot.replace(/\/+$/, "") + "/" + aPath);
  287. if (aRootUrl) {
  288. aRootUrl.path = joined;
  289. return urlGenerate(aRootUrl);
  290. }
  291. return joined;
  292. }
  293. exports.join = join;
  294. exports.isAbsolute = function(aPath) {
  295. return aPath.charAt(0) === "/" || urlRegexp.test(aPath);
  296. };
  297. /**
  298. * Make a path relative to a URL or another path.
  299. *
  300. * @param aRoot The root path or URL.
  301. * @param aPath The path or URL to be made relative to aRoot.
  302. */
  303. function relative(aRoot, aPath) {
  304. if (aRoot === "") {
  305. aRoot = ".";
  306. }
  307. aRoot = aRoot.replace(/\/$/, "");
  308. // It is possible for the path to be above the root. In this case, simply
  309. // checking whether the root is a prefix of the path won't work. Instead, we
  310. // need to remove components from the root one by one, until either we find
  311. // a prefix that fits, or we run out of components to remove.
  312. let level = 0;
  313. while (aPath.indexOf(aRoot + "/") !== 0) {
  314. const index = aRoot.lastIndexOf("/");
  315. if (index < 0) {
  316. return aPath;
  317. }
  318. // If the only part of the root that is left is the scheme (i.e. http://,
  319. // file:///, etc.), one or more slashes (/), or simply nothing at all, we
  320. // have exhausted all components, so the path is not relative to the root.
  321. aRoot = aRoot.slice(0, index);
  322. if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
  323. return aPath;
  324. }
  325. ++level;
  326. }
  327. // Make sure we add a "../" for each component we removed from the root.
  328. return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
  329. }
  330. exports.relative = relative;
  331. const supportsNullProto = (function() {
  332. const obj = Object.create(null);
  333. return !("__proto__" in obj);
  334. }());
  335. function identity(s) {
  336. return s;
  337. }
  338. /**
  339. * Because behavior goes wacky when you set `__proto__` on objects, we
  340. * have to prefix all the strings in our set with an arbitrary character.
  341. *
  342. * See https://github.com/mozilla/source-map/pull/31 and
  343. * https://github.com/mozilla/source-map/issues/30
  344. *
  345. * @param String aStr
  346. */
  347. function toSetString(aStr) {
  348. if (isProtoString(aStr)) {
  349. return "$" + aStr;
  350. }
  351. return aStr;
  352. }
  353. exports.toSetString = supportsNullProto ? identity : toSetString;
  354. function fromSetString(aStr) {
  355. if (isProtoString(aStr)) {
  356. return aStr.slice(1);
  357. }
  358. return aStr;
  359. }
  360. exports.fromSetString = supportsNullProto ? identity : fromSetString;
  361. function isProtoString(s) {
  362. if (!s) {
  363. return false;
  364. }
  365. const length = s.length;
  366. if (length < 9 /* "__proto__".length */) {
  367. return false;
  368. }
  369. /* eslint-disable no-multi-spaces */
  370. if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
  371. s.charCodeAt(length - 2) !== 95 /* '_' */ ||
  372. s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
  373. s.charCodeAt(length - 4) !== 116 /* 't' */ ||
  374. s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
  375. s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
  376. s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
  377. s.charCodeAt(length - 8) !== 95 /* '_' */ ||
  378. s.charCodeAt(length - 9) !== 95 /* '_' */) {
  379. return false;
  380. }
  381. /* eslint-enable no-multi-spaces */
  382. for (let i = length - 10; i >= 0; i--) {
  383. if (s.charCodeAt(i) !== 36 /* '$' */) {
  384. return false;
  385. }
  386. }
  387. return true;
  388. }
  389. /**
  390. * Comparator between two mappings where the original positions are compared.
  391. *
  392. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  393. * mappings with the same original source/line/column, but different generated
  394. * line and column the same. Useful when searching for a mapping with a
  395. * stubbed out mapping.
  396. */
  397. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  398. let cmp = strcmp(mappingA.source, mappingB.source);
  399. if (cmp !== 0) {
  400. return cmp;
  401. }
  402. cmp = mappingA.originalLine - mappingB.originalLine;
  403. if (cmp !== 0) {
  404. return cmp;
  405. }
  406. cmp = mappingA.originalColumn - mappingB.originalColumn;
  407. if (cmp !== 0 || onlyCompareOriginal) {
  408. return cmp;
  409. }
  410. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  411. if (cmp !== 0) {
  412. return cmp;
  413. }
  414. cmp = mappingA.generatedLine - mappingB.generatedLine;
  415. if (cmp !== 0) {
  416. return cmp;
  417. }
  418. return strcmp(mappingA.name, mappingB.name);
  419. }
  420. exports.compareByOriginalPositions = compareByOriginalPositions;
  421. /**
  422. * Comparator between two mappings with deflated source and name indices where
  423. * the generated positions are compared.
  424. *
  425. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  426. * mappings with the same generated line and column, but different
  427. * source/name/original line and column the same. Useful when searching for a
  428. * mapping with a stubbed out mapping.
  429. */
  430. function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
  431. let cmp = mappingA.generatedLine - mappingB.generatedLine;
  432. if (cmp !== 0) {
  433. return cmp;
  434. }
  435. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  436. if (cmp !== 0 || onlyCompareGenerated) {
  437. return cmp;
  438. }
  439. cmp = strcmp(mappingA.source, mappingB.source);
  440. if (cmp !== 0) {
  441. return cmp;
  442. }
  443. cmp = mappingA.originalLine - mappingB.originalLine;
  444. if (cmp !== 0) {
  445. return cmp;
  446. }
  447. cmp = mappingA.originalColumn - mappingB.originalColumn;
  448. if (cmp !== 0) {
  449. return cmp;
  450. }
  451. return strcmp(mappingA.name, mappingB.name);
  452. }
  453. exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
  454. function strcmp(aStr1, aStr2) {
  455. if (aStr1 === aStr2) {
  456. return 0;
  457. }
  458. if (aStr1 === null) {
  459. return 1; // aStr2 !== null
  460. }
  461. if (aStr2 === null) {
  462. return -1; // aStr1 !== null
  463. }
  464. if (aStr1 > aStr2) {
  465. return 1;
  466. }
  467. return -1;
  468. }
  469. /**
  470. * Comparator between two mappings with inflated source and name strings where
  471. * the generated positions are compared.
  472. */
  473. function compareByGeneratedPositionsInflated(mappingA, mappingB) {
  474. let cmp = mappingA.generatedLine - mappingB.generatedLine;
  475. if (cmp !== 0) {
  476. return cmp;
  477. }
  478. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  479. if (cmp !== 0) {
  480. return cmp;
  481. }
  482. cmp = strcmp(mappingA.source, mappingB.source);
  483. if (cmp !== 0) {
  484. return cmp;
  485. }
  486. cmp = mappingA.originalLine - mappingB.originalLine;
  487. if (cmp !== 0) {
  488. return cmp;
  489. }
  490. cmp = mappingA.originalColumn - mappingB.originalColumn;
  491. if (cmp !== 0) {
  492. return cmp;
  493. }
  494. return strcmp(mappingA.name, mappingB.name);
  495. }
  496. exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
  497. /**
  498. * Strip any JSON XSSI avoidance prefix from the string (as documented
  499. * in the source maps specification), and then parse the string as
  500. * JSON.
  501. */
  502. function parseSourceMapInput(str) {
  503. return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ""));
  504. }
  505. exports.parseSourceMapInput = parseSourceMapInput;
  506. /**
  507. * Compute the URL of a source given the the source root, the source's
  508. * URL, and the source map's URL.
  509. */
  510. function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
  511. sourceURL = sourceURL || "";
  512. if (sourceRoot) {
  513. // This follows what Chrome does.
  514. if (sourceRoot[sourceRoot.length - 1] !== "/" && sourceURL[0] !== "/") {
  515. sourceRoot += "/";
  516. }
  517. // The spec says:
  518. // Line 4: An optional source root, useful for relocating source
  519. // files on a server or removing repeated values in the
  520. // “sources” entry. This value is prepended to the individual
  521. // entries in the “source” field.
  522. sourceURL = sourceRoot + sourceURL;
  523. }
  524. // Historically, SourceMapConsumer did not take the sourceMapURL as
  525. // a parameter. This mode is still somewhat supported, which is why
  526. // this code block is conditional. However, it's preferable to pass
  527. // the source map URL to SourceMapConsumer, so that this function
  528. // can implement the source URL resolution algorithm as outlined in
  529. // the spec. This block is basically the equivalent of:
  530. // new URL(sourceURL, sourceMapURL).toString()
  531. // ... except it avoids using URL, which wasn't available in the
  532. // older releases of node still supported by this library.
  533. //
  534. // The spec says:
  535. // If the sources are not absolute URLs after prepending of the
  536. // “sourceRoot”, the sources are resolved relative to the
  537. // SourceMap (like resolving script src in a html document).
  538. if (sourceMapURL) {
  539. const parsed = urlParse(sourceMapURL);
  540. if (!parsed) {
  541. throw new Error("sourceMapURL could not be parsed");
  542. }
  543. if (parsed.path) {
  544. // Strip the last path component, but keep the "/".
  545. const index = parsed.path.lastIndexOf("/");
  546. if (index >= 0) {
  547. parsed.path = parsed.path.substring(0, index + 1);
  548. }
  549. }
  550. sourceURL = join(urlGenerate(parsed), sourceURL);
  551. }
  552. return normalize(sourceURL);
  553. }
  554. exports.computeSourceURL = computeSourceURL;
  555. /***/ }),
  556. /* 1 */
  557. /***/ (function(module, exports, __webpack_require__) {
  558. /* -*- Mode: js; js-indent-level: 2; -*- */
  559. /*
  560. * Copyright 2011 Mozilla Foundation and contributors
  561. * Licensed under the New BSD license. See LICENSE or:
  562. * http://opensource.org/licenses/BSD-3-Clause
  563. */
  564. const base64VLQ = __webpack_require__(2);
  565. const util = __webpack_require__(0);
  566. const ArraySet = __webpack_require__(3).ArraySet;
  567. const MappingList = __webpack_require__(7).MappingList;
  568. /**
  569. * An instance of the SourceMapGenerator represents a source map which is
  570. * being built incrementally. You may pass an object with the following
  571. * properties:
  572. *
  573. * - file: The filename of the generated source.
  574. * - sourceRoot: A root for all relative URLs in this source map.
  575. */
  576. class SourceMapGenerator {
  577. constructor(aArgs) {
  578. if (!aArgs) {
  579. aArgs = {};
  580. }
  581. this._file = util.getArg(aArgs, "file", null);
  582. this._sourceRoot = util.getArg(aArgs, "sourceRoot", null);
  583. this._skipValidation = util.getArg(aArgs, "skipValidation", false);
  584. this._sources = new ArraySet();
  585. this._names = new ArraySet();
  586. this._mappings = new MappingList();
  587. this._sourcesContents = null;
  588. }
  589. /**
  590. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  591. *
  592. * @param aSourceMapConsumer The SourceMap.
  593. */
  594. static fromSourceMap(aSourceMapConsumer) {
  595. const sourceRoot = aSourceMapConsumer.sourceRoot;
  596. const generator = new SourceMapGenerator({
  597. file: aSourceMapConsumer.file,
  598. sourceRoot
  599. });
  600. aSourceMapConsumer.eachMapping(function(mapping) {
  601. const newMapping = {
  602. generated: {
  603. line: mapping.generatedLine,
  604. column: mapping.generatedColumn
  605. }
  606. };
  607. if (mapping.source != null) {
  608. newMapping.source = mapping.source;
  609. if (sourceRoot != null) {
  610. newMapping.source = util.relative(sourceRoot, newMapping.source);
  611. }
  612. newMapping.original = {
  613. line: mapping.originalLine,
  614. column: mapping.originalColumn
  615. };
  616. if (mapping.name != null) {
  617. newMapping.name = mapping.name;
  618. }
  619. }
  620. generator.addMapping(newMapping);
  621. });
  622. aSourceMapConsumer.sources.forEach(function(sourceFile) {
  623. let sourceRelative = sourceFile;
  624. if (sourceRoot !== null) {
  625. sourceRelative = util.relative(sourceRoot, sourceFile);
  626. }
  627. if (!generator._sources.has(sourceRelative)) {
  628. generator._sources.add(sourceRelative);
  629. }
  630. const content = aSourceMapConsumer.sourceContentFor(sourceFile);
  631. if (content != null) {
  632. generator.setSourceContent(sourceFile, content);
  633. }
  634. });
  635. return generator;
  636. }
  637. /**
  638. * Add a single mapping from original source line and column to the generated
  639. * source's line and column for this source map being created. The mapping
  640. * object should have the following properties:
  641. *
  642. * - generated: An object with the generated line and column positions.
  643. * - original: An object with the original line and column positions.
  644. * - source: The original source file (relative to the sourceRoot).
  645. * - name: An optional original token name for this mapping.
  646. */
  647. addMapping(aArgs) {
  648. const generated = util.getArg(aArgs, "generated");
  649. const original = util.getArg(aArgs, "original", null);
  650. let source = util.getArg(aArgs, "source", null);
  651. let name = util.getArg(aArgs, "name", null);
  652. if (!this._skipValidation) {
  653. this._validateMapping(generated, original, source, name);
  654. }
  655. if (source != null) {
  656. source = String(source);
  657. if (!this._sources.has(source)) {
  658. this._sources.add(source);
  659. }
  660. }
  661. if (name != null) {
  662. name = String(name);
  663. if (!this._names.has(name)) {
  664. this._names.add(name);
  665. }
  666. }
  667. this._mappings.add({
  668. generatedLine: generated.line,
  669. generatedColumn: generated.column,
  670. originalLine: original != null && original.line,
  671. originalColumn: original != null && original.column,
  672. source,
  673. name
  674. });
  675. }
  676. /**
  677. * Set the source content for a source file.
  678. */
  679. setSourceContent(aSourceFile, aSourceContent) {
  680. let source = aSourceFile;
  681. if (this._sourceRoot != null) {
  682. source = util.relative(this._sourceRoot, source);
  683. }
  684. if (aSourceContent != null) {
  685. // Add the source content to the _sourcesContents map.
  686. // Create a new _sourcesContents map if the property is null.
  687. if (!this._sourcesContents) {
  688. this._sourcesContents = Object.create(null);
  689. }
  690. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  691. } else if (this._sourcesContents) {
  692. // Remove the source file from the _sourcesContents map.
  693. // If the _sourcesContents map is empty, set the property to null.
  694. delete this._sourcesContents[util.toSetString(source)];
  695. if (Object.keys(this._sourcesContents).length === 0) {
  696. this._sourcesContents = null;
  697. }
  698. }
  699. }
  700. /**
  701. * Applies the mappings of a sub-source-map for a specific source file to the
  702. * source map being generated. Each mapping to the supplied source file is
  703. * rewritten using the supplied source map. Note: The resolution for the
  704. * resulting mappings is the minimium of this map and the supplied map.
  705. *
  706. * @param aSourceMapConsumer The source map to be applied.
  707. * @param aSourceFile Optional. The filename of the source file.
  708. * If omitted, SourceMapConsumer's file property will be used.
  709. * @param aSourceMapPath Optional. The dirname of the path to the source map
  710. * to be applied. If relative, it is relative to the SourceMapConsumer.
  711. * This parameter is needed when the two source maps aren't in the same
  712. * directory, and the source map to be applied contains relative source
  713. * paths. If so, those relative source paths need to be rewritten
  714. * relative to the SourceMapGenerator.
  715. */
  716. applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  717. let sourceFile = aSourceFile;
  718. // If aSourceFile is omitted, we will use the file property of the SourceMap
  719. if (aSourceFile == null) {
  720. if (aSourceMapConsumer.file == null) {
  721. throw new Error(
  722. "SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, " +
  723. 'or the source map\'s "file" property. Both were omitted.'
  724. );
  725. }
  726. sourceFile = aSourceMapConsumer.file;
  727. }
  728. const sourceRoot = this._sourceRoot;
  729. // Make "sourceFile" relative if an absolute Url is passed.
  730. if (sourceRoot != null) {
  731. sourceFile = util.relative(sourceRoot, sourceFile);
  732. }
  733. // Applying the SourceMap can add and remove items from the sources and
  734. // the names array.
  735. const newSources = this._mappings.toArray().length > 0
  736. ? new ArraySet()
  737. : this._sources;
  738. const newNames = new ArraySet();
  739. // Find mappings for the "sourceFile"
  740. this._mappings.unsortedForEach(function(mapping) {
  741. if (mapping.source === sourceFile && mapping.originalLine != null) {
  742. // Check if it can be mapped by the source map, then update the mapping.
  743. const original = aSourceMapConsumer.originalPositionFor({
  744. line: mapping.originalLine,
  745. column: mapping.originalColumn
  746. });
  747. if (original.source != null) {
  748. // Copy mapping
  749. mapping.source = original.source;
  750. if (aSourceMapPath != null) {
  751. mapping.source = util.join(aSourceMapPath, mapping.source);
  752. }
  753. if (sourceRoot != null) {
  754. mapping.source = util.relative(sourceRoot, mapping.source);
  755. }
  756. mapping.originalLine = original.line;
  757. mapping.originalColumn = original.column;
  758. if (original.name != null) {
  759. mapping.name = original.name;
  760. }
  761. }
  762. }
  763. const source = mapping.source;
  764. if (source != null && !newSources.has(source)) {
  765. newSources.add(source);
  766. }
  767. const name = mapping.name;
  768. if (name != null && !newNames.has(name)) {
  769. newNames.add(name);
  770. }
  771. }, this);
  772. this._sources = newSources;
  773. this._names = newNames;
  774. // Copy sourcesContents of applied map.
  775. aSourceMapConsumer.sources.forEach(function(srcFile) {
  776. const content = aSourceMapConsumer.sourceContentFor(srcFile);
  777. if (content != null) {
  778. if (aSourceMapPath != null) {
  779. srcFile = util.join(aSourceMapPath, srcFile);
  780. }
  781. if (sourceRoot != null) {
  782. srcFile = util.relative(sourceRoot, srcFile);
  783. }
  784. this.setSourceContent(srcFile, content);
  785. }
  786. }, this);
  787. }
  788. /**
  789. * A mapping can have one of the three levels of data:
  790. *
  791. * 1. Just the generated position.
  792. * 2. The Generated position, original position, and original source.
  793. * 3. Generated and original position, original source, as well as a name
  794. * token.
  795. *
  796. * To maintain consistency, we validate that any new mapping being added falls
  797. * in to one of these categories.
  798. */
  799. _validateMapping(aGenerated, aOriginal, aSource, aName) {
  800. // When aOriginal is truthy but has empty values for .line and .column,
  801. // it is most likely a programmer error. In this case we throw a very
  802. // specific error message to try to guide them the right way.
  803. // For example: https://github.com/Polymer/polymer-bundler/pull/519
  804. if (aOriginal && typeof aOriginal.line !== "number" && typeof aOriginal.column !== "number") {
  805. throw new Error(
  806. "original.line and original.column are not numbers -- you probably meant to omit " +
  807. "the original mapping entirely and only map the generated position. If so, pass " +
  808. "null for the original mapping instead of an object with empty or null values."
  809. );
  810. }
  811. if (aGenerated && "line" in aGenerated && "column" in aGenerated
  812. && aGenerated.line > 0 && aGenerated.column >= 0
  813. && !aOriginal && !aSource && !aName) {
  814. // Case 1.
  815. } else if (aGenerated && "line" in aGenerated && "column" in aGenerated
  816. && aOriginal && "line" in aOriginal && "column" in aOriginal
  817. && aGenerated.line > 0 && aGenerated.column >= 0
  818. && aOriginal.line > 0 && aOriginal.column >= 0
  819. && aSource) {
  820. // Cases 2 and 3.
  821. } else {
  822. throw new Error("Invalid mapping: " + JSON.stringify({
  823. generated: aGenerated,
  824. source: aSource,
  825. original: aOriginal,
  826. name: aName
  827. }));
  828. }
  829. }
  830. /**
  831. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  832. * specified by the source map format.
  833. */
  834. _serializeMappings() {
  835. let previousGeneratedColumn = 0;
  836. let previousGeneratedLine = 1;
  837. let previousOriginalColumn = 0;
  838. let previousOriginalLine = 0;
  839. let previousName = 0;
  840. let previousSource = 0;
  841. let result = "";
  842. let next;
  843. let mapping;
  844. let nameIdx;
  845. let sourceIdx;
  846. const mappings = this._mappings.toArray();
  847. for (let i = 0, len = mappings.length; i < len; i++) {
  848. mapping = mappings[i];
  849. next = "";
  850. if (mapping.generatedLine !== previousGeneratedLine) {
  851. previousGeneratedColumn = 0;
  852. while (mapping.generatedLine !== previousGeneratedLine) {
  853. next += ";";
  854. previousGeneratedLine++;
  855. }
  856. } else if (i > 0) {
  857. if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
  858. continue;
  859. }
  860. next += ",";
  861. }
  862. next += base64VLQ.encode(mapping.generatedColumn
  863. - previousGeneratedColumn);
  864. previousGeneratedColumn = mapping.generatedColumn;
  865. if (mapping.source != null) {
  866. sourceIdx = this._sources.indexOf(mapping.source);
  867. next += base64VLQ.encode(sourceIdx - previousSource);
  868. previousSource = sourceIdx;
  869. // lines are stored 0-based in SourceMap spec version 3
  870. next += base64VLQ.encode(mapping.originalLine - 1
  871. - previousOriginalLine);
  872. previousOriginalLine = mapping.originalLine - 1;
  873. next += base64VLQ.encode(mapping.originalColumn
  874. - previousOriginalColumn);
  875. previousOriginalColumn = mapping.originalColumn;
  876. if (mapping.name != null) {
  877. nameIdx = this._names.indexOf(mapping.name);
  878. next += base64VLQ.encode(nameIdx - previousName);
  879. previousName = nameIdx;
  880. }
  881. }
  882. result += next;
  883. }
  884. return result;
  885. }
  886. _generateSourcesContent(aSources, aSourceRoot) {
  887. return aSources.map(function(source) {
  888. if (!this._sourcesContents) {
  889. return null;
  890. }
  891. if (aSourceRoot != null) {
  892. source = util.relative(aSourceRoot, source);
  893. }
  894. const key = util.toSetString(source);
  895. return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
  896. ? this._sourcesContents[key]
  897. : null;
  898. }, this);
  899. }
  900. /**
  901. * Externalize the source map.
  902. */
  903. toJSON() {
  904. const map = {
  905. version: this._version,
  906. sources: this._sources.toArray(),
  907. names: this._names.toArray(),
  908. mappings: this._serializeMappings()
  909. };
  910. if (this._file != null) {
  911. map.file = this._file;
  912. }
  913. if (this._sourceRoot != null) {
  914. map.sourceRoot = this._sourceRoot;
  915. }
  916. if (this._sourcesContents) {
  917. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  918. }
  919. return map;
  920. }
  921. /**
  922. * Render the source map being generated to a string.
  923. */
  924. toString() {
  925. return JSON.stringify(this.toJSON());
  926. }
  927. }
  928. SourceMapGenerator.prototype._version = 3;
  929. exports.SourceMapGenerator = SourceMapGenerator;
  930. /***/ }),
  931. /* 2 */
  932. /***/ (function(module, exports, __webpack_require__) {
  933. /* -*- Mode: js; js-indent-level: 2; -*- */
  934. /*
  935. * Copyright 2011 Mozilla Foundation and contributors
  936. * Licensed under the New BSD license. See LICENSE or:
  937. * http://opensource.org/licenses/BSD-3-Clause
  938. *
  939. * Based on the Base 64 VLQ implementation in Closure Compiler:
  940. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  941. *
  942. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  943. * Redistribution and use in source and binary forms, with or without
  944. * modification, are permitted provided that the following conditions are
  945. * met:
  946. *
  947. * * Redistributions of source code must retain the above copyright
  948. * notice, this list of conditions and the following disclaimer.
  949. * * Redistributions in binary form must reproduce the above
  950. * copyright notice, this list of conditions and the following
  951. * disclaimer in the documentation and/or other materials provided
  952. * with the distribution.
  953. * * Neither the name of Google Inc. nor the names of its
  954. * contributors may be used to endorse or promote products derived
  955. * from this software without specific prior written permission.
  956. *
  957. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  958. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  959. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  960. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  961. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  962. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  963. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  964. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  965. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  966. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  967. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  968. */
  969. const base64 = __webpack_require__(6);
  970. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  971. // length quantities we use in the source map spec, the first bit is the sign,
  972. // the next four bits are the actual value, and the 6th bit is the
  973. // continuation bit. The continuation bit tells us whether there are more
  974. // digits in this value following this digit.
  975. //
  976. // Continuation
  977. // | Sign
  978. // | |
  979. // V V
  980. // 101011
  981. const VLQ_BASE_SHIFT = 5;
  982. // binary: 100000
  983. const VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  984. // binary: 011111
  985. const VLQ_BASE_MASK = VLQ_BASE - 1;
  986. // binary: 100000
  987. const VLQ_CONTINUATION_BIT = VLQ_BASE;
  988. /**
  989. * Converts from a two-complement value to a value where the sign bit is
  990. * placed in the least significant bit. For example, as decimals:
  991. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  992. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  993. */
  994. function toVLQSigned(aValue) {
  995. return aValue < 0
  996. ? ((-aValue) << 1) + 1
  997. : (aValue << 1) + 0;
  998. }
  999. /**
  1000. * Converts to a two-complement value from a value where the sign bit is
  1001. * placed in the least significant bit. For example, as decimals:
  1002. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  1003. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  1004. */
  1005. // eslint-disable-next-line no-unused-vars
  1006. function fromVLQSigned(aValue) {
  1007. const isNegative = (aValue & 1) === 1;
  1008. const shifted = aValue >> 1;
  1009. return isNegative
  1010. ? -shifted
  1011. : shifted;
  1012. }
  1013. /**
  1014. * Returns the base 64 VLQ encoded value.
  1015. */
  1016. exports.encode = function base64VLQ_encode(aValue) {
  1017. let encoded = "";
  1018. let digit;
  1019. let vlq = toVLQSigned(aValue);
  1020. do {
  1021. digit = vlq & VLQ_BASE_MASK;
  1022. vlq >>>= VLQ_BASE_SHIFT;
  1023. if (vlq > 0) {
  1024. // There are still more digits in this value, so we must make sure the
  1025. // continuation bit is marked.
  1026. digit |= VLQ_CONTINUATION_BIT;
  1027. }
  1028. encoded += base64.encode(digit);
  1029. } while (vlq > 0);
  1030. return encoded;
  1031. };
  1032. /***/ }),
  1033. /* 3 */
  1034. /***/ (function(module, exports) {
  1035. /* -*- Mode: js; js-indent-level: 2; -*- */
  1036. /*
  1037. * Copyright 2011 Mozilla Foundation and contributors
  1038. * Licensed under the New BSD license. See LICENSE or:
  1039. * http://opensource.org/licenses/BSD-3-Clause
  1040. */
  1041. /**
  1042. * A data structure which is a combination of an array and a set. Adding a new
  1043. * member is O(1), testing for membership is O(1), and finding the index of an
  1044. * element is O(1). Removing elements from the set is not supported. Only
  1045. * strings are supported for membership.
  1046. */
  1047. class ArraySet {
  1048. constructor() {
  1049. this._array = [];
  1050. this._set = new Map();
  1051. }
  1052. /**
  1053. * Static method for creating ArraySet instances from an existing array.
  1054. */
  1055. static fromArray(aArray, aAllowDuplicates) {
  1056. const set = new ArraySet();
  1057. for (let i = 0, len = aArray.length; i < len; i++) {
  1058. set.add(aArray[i], aAllowDuplicates);
  1059. }
  1060. return set;
  1061. }
  1062. /**
  1063. * Return how many unique items are in this ArraySet. If duplicates have been
  1064. * added, than those do not count towards the size.
  1065. *
  1066. * @returns Number
  1067. */
  1068. size() {
  1069. return this._set.size;
  1070. }
  1071. /**
  1072. * Add the given string to this set.
  1073. *
  1074. * @param String aStr
  1075. */
  1076. add(aStr, aAllowDuplicates) {
  1077. const isDuplicate = this.has(aStr);
  1078. const idx = this._array.length;
  1079. if (!isDuplicate || aAllowDuplicates) {
  1080. this._array.push(aStr);
  1081. }
  1082. if (!isDuplicate) {
  1083. this._set.set(aStr, idx);
  1084. }
  1085. }
  1086. /**
  1087. * Is the given string a member of this set?
  1088. *
  1089. * @param String aStr
  1090. */
  1091. has(aStr) {
  1092. return this._set.has(aStr);
  1093. }
  1094. /**
  1095. * What is the index of the given string in the array?
  1096. *
  1097. * @param String aStr
  1098. */
  1099. indexOf(aStr) {
  1100. const idx = this._set.get(aStr);
  1101. if (idx >= 0) {
  1102. return idx;
  1103. }
  1104. throw new Error('"' + aStr + '" is not in the set.');
  1105. }
  1106. /**
  1107. * What is the element at the given index?
  1108. *
  1109. * @param Number aIdx
  1110. */
  1111. at(aIdx) {
  1112. if (aIdx >= 0 && aIdx < this._array.length) {
  1113. return this._array[aIdx];
  1114. }
  1115. throw new Error("No element indexed by " + aIdx);
  1116. }
  1117. /**
  1118. * Returns the array representation of this set (which has the proper indices
  1119. * indicated by indexOf). Note that this is a copy of the internal array used
  1120. * for storing the members so that no one can mess with internal state.
  1121. */
  1122. toArray() {
  1123. return this._array.slice();
  1124. }
  1125. }
  1126. exports.ArraySet = ArraySet;
  1127. /***/ }),
  1128. /* 4 */
  1129. /***/ (function(module, exports, __webpack_require__) {
  1130. /* WEBPACK VAR INJECTION */(function(__dirname) {if (typeof fetch === "function") {
  1131. // Web version of reading a wasm file into an array buffer.
  1132. let mappingsWasmUrl = null;
  1133. module.exports = function readWasm() {
  1134. if (typeof mappingsWasmUrl !== "string") {
  1135. throw new Error("You must provide the URL of lib/mappings.wasm by calling " +
  1136. "SourceMapConsumer.initialize({ 'lib/mappings.wasm': ... }) " +
  1137. "before using SourceMapConsumer");
  1138. }
  1139. return fetch(mappingsWasmUrl)
  1140. .then(response => response.arrayBuffer());
  1141. };
  1142. module.exports.initialize = url => mappingsWasmUrl = url;
  1143. } else {
  1144. // Node version of reading a wasm file into an array buffer.
  1145. const fs = __webpack_require__(10);
  1146. const path = __webpack_require__(11);
  1147. module.exports = function readWasm() {
  1148. return new Promise((resolve, reject) => {
  1149. const wasmPath = path.join(__dirname, "mappings.wasm");
  1150. fs.readFile(wasmPath, null, (error, data) => {
  1151. if (error) {
  1152. reject(error);
  1153. return;
  1154. }
  1155. resolve(data.buffer);
  1156. });
  1157. });
  1158. };
  1159. module.exports.initialize = _ => {
  1160. console.debug("SourceMapConsumer.initialize is a no-op when running in node.js");
  1161. };
  1162. }
  1163. /* WEBPACK VAR INJECTION */}.call(exports, "/"))
  1164. /***/ }),
  1165. /* 5 */
  1166. /***/ (function(module, exports, __webpack_require__) {
  1167. /*
  1168. * Copyright 2009-2011 Mozilla Foundation and contributors
  1169. * Licensed under the New BSD license. See LICENSE.txt or:
  1170. * http://opensource.org/licenses/BSD-3-Clause
  1171. */
  1172. exports.SourceMapGenerator = __webpack_require__(1).SourceMapGenerator;
  1173. exports.SourceMapConsumer = __webpack_require__(8).SourceMapConsumer;
  1174. exports.SourceNode = __webpack_require__(13).SourceNode;
  1175. /***/ }),
  1176. /* 6 */
  1177. /***/ (function(module, exports) {
  1178. /* -*- Mode: js; js-indent-level: 2; -*- */
  1179. /*
  1180. * Copyright 2011 Mozilla Foundation and contributors
  1181. * Licensed under the New BSD license. See LICENSE or:
  1182. * http://opensource.org/licenses/BSD-3-Clause
  1183. */
  1184. const intToCharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
  1185. /**
  1186. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  1187. */
  1188. exports.encode = function(number) {
  1189. if (0 <= number && number < intToCharMap.length) {
  1190. return intToCharMap[number];
  1191. }
  1192. throw new TypeError("Must be between 0 and 63: " + number);
  1193. };
  1194. /***/ }),
  1195. /* 7 */
  1196. /***/ (function(module, exports, __webpack_require__) {
  1197. /* -*- Mode: js; js-indent-level: 2; -*- */
  1198. /*
  1199. * Copyright 2014 Mozilla Foundation and contributors
  1200. * Licensed under the New BSD license. See LICENSE or:
  1201. * http://opensource.org/licenses/BSD-3-Clause
  1202. */
  1203. const util = __webpack_require__(0);
  1204. /**
  1205. * Determine whether mappingB is after mappingA with respect to generated
  1206. * position.
  1207. */
  1208. function generatedPositionAfter(mappingA, mappingB) {
  1209. // Optimized for most common case
  1210. const lineA = mappingA.generatedLine;
  1211. const lineB = mappingB.generatedLine;
  1212. const columnA = mappingA.generatedColumn;
  1213. const columnB = mappingB.generatedColumn;
  1214. return lineB > lineA || lineB == lineA && columnB >= columnA ||
  1215. util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
  1216. }
  1217. /**
  1218. * A data structure to provide a sorted view of accumulated mappings in a
  1219. * performance conscious manner. It trades a negligible overhead in general
  1220. * case for a large speedup in case of mappings being added in order.
  1221. */
  1222. class MappingList {
  1223. constructor() {
  1224. this._array = [];
  1225. this._sorted = true;
  1226. // Serves as infimum
  1227. this._last = {generatedLine: -1, generatedColumn: 0};
  1228. }
  1229. /**
  1230. * Iterate through internal items. This method takes the same arguments that
  1231. * `Array.prototype.forEach` takes.
  1232. *
  1233. * NOTE: The order of the mappings is NOT guaranteed.
  1234. */
  1235. unsortedForEach(aCallback, aThisArg) {
  1236. this._array.forEach(aCallback, aThisArg);
  1237. }
  1238. /**
  1239. * Add the given source mapping.
  1240. *
  1241. * @param Object aMapping
  1242. */
  1243. add(aMapping) {
  1244. if (generatedPositionAfter(this._last, aMapping)) {
  1245. this._last = aMapping;
  1246. this._array.push(aMapping);
  1247. } else {
  1248. this._sorted = false;
  1249. this._array.push(aMapping);
  1250. }
  1251. }
  1252. /**
  1253. * Returns the flat, sorted array of mappings. The mappings are sorted by
  1254. * generated position.
  1255. *
  1256. * WARNING: This method returns internal data without copying, for
  1257. * performance. The return value must NOT be mutated, and should be treated as
  1258. * an immutable borrow. If you want to take ownership, you must make your own
  1259. * copy.
  1260. */
  1261. toArray() {
  1262. if (!this._sorted) {
  1263. this._array.sort(util.compareByGeneratedPositionsInflated);
  1264. this._sorted = true;
  1265. }
  1266. return this._array;
  1267. }
  1268. }
  1269. exports.MappingList = MappingList;
  1270. /***/ }),
  1271. /* 8 */
  1272. /***/ (function(module, exports, __webpack_require__) {
  1273. /* -*- Mode: js; js-indent-level: 2; -*- */
  1274. /*
  1275. * Copyright 2011 Mozilla Foundation and contributors
  1276. * Licensed under the New BSD license. See LICENSE or:
  1277. * http://opensource.org/licenses/BSD-3-Clause
  1278. */
  1279. const util = __webpack_require__(0);
  1280. const binarySearch = __webpack_require__(9);
  1281. const ArraySet = __webpack_require__(3).ArraySet;
  1282. const base64VLQ = __webpack_require__(2); // eslint-disable-line no-unused-vars
  1283. const readWasm = __webpack_require__(4);
  1284. const wasm = __webpack_require__(12);
  1285. const INTERNAL = Symbol("smcInternal");
  1286. class SourceMapConsumer {
  1287. constructor(aSourceMap, aSourceMapURL) {
  1288. // If the constructor was called by super(), just return Promise<this>.
  1289. // Yes, this is a hack to retain the pre-existing API of the base-class
  1290. // constructor also being an async factory function.
  1291. if (aSourceMap == INTERNAL) {
  1292. return Promise.resolve(this);
  1293. }
  1294. return _factory(aSourceMap, aSourceMapURL);
  1295. }
  1296. static initialize(opts) {
  1297. readWasm.initialize(opts["lib/mappings.wasm"]);
  1298. }
  1299. static fromSourceMap(aSourceMap, aSourceMapURL) {
  1300. return _factoryBSM(aSourceMap, aSourceMapURL);
  1301. }
  1302. /**
  1303. * Construct a new `SourceMapConsumer` from `rawSourceMap` and `sourceMapUrl`
  1304. * (see the `SourceMapConsumer` constructor for details. Then, invoke the `async
  1305. * function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait
  1306. * for `f` to complete, call `destroy` on the consumer, and return `f`'s return
  1307. * value.
  1308. *
  1309. * You must not use the consumer after `f` completes!
  1310. *
  1311. * By using `with`, you do not have to remember to manually call `destroy` on
  1312. * the consumer, since it will be called automatically once `f` completes.
  1313. *
  1314. * ```js
  1315. * const xSquared = await SourceMapConsumer.with(
  1316. * myRawSourceMap,
  1317. * null,
  1318. * async function (consumer) {
  1319. * // Use `consumer` inside here and don't worry about remembering
  1320. * // to call `destroy`.
  1321. *
  1322. * const x = await whatever(consumer);
  1323. * return x * x;
  1324. * }
  1325. * );
  1326. *
  1327. * // You may not use that `consumer` anymore out here; it has
  1328. * // been destroyed. But you can use `xSquared`.
  1329. * console.log(xSquared);
  1330. * ```
  1331. */
  1332. static with(rawSourceMap, sourceMapUrl, f) {
  1333. // Note: The `acorn` version that `webpack` currently depends on doesn't
  1334. // support `async` functions, and the nodes that we support don't all have
  1335. // `.finally`. Therefore, this is written a bit more convolutedly than it
  1336. // should really be.
  1337. let consumer = null;
  1338. const promise = new SourceMapConsumer(rawSourceMap, sourceMapUrl);
  1339. return promise
  1340. .then(c => {
  1341. consumer = c;
  1342. return f(c);
  1343. })
  1344. .then(x => {
  1345. if (consumer) {
  1346. consumer.destroy();
  1347. }
  1348. return x;
  1349. }, e => {
  1350. if (consumer) {
  1351. consumer.destroy();
  1352. }
  1353. throw e;
  1354. });
  1355. }
  1356. /**
  1357. * Parse the mappings in a string in to a data structure which we can easily
  1358. * query (the ordered arrays in the `this.__generatedMappings` and
  1359. * `this.__originalMappings` properties).
  1360. */
  1361. _parseMappings(aStr, aSourceRoot) {
  1362. throw new Error("Subclasses must implement _parseMappings");
  1363. }
  1364. /**
  1365. * Iterate over each mapping between an original source/line/column and a
  1366. * generated line/column in this source map.
  1367. *
  1368. * @param Function aCallback
  1369. * The function that is called with each mapping.
  1370. * @param Object aContext
  1371. * Optional. If specified, this object will be the value of `this` every
  1372. * time that `aCallback` is called.
  1373. * @param aOrder
  1374. * Either `SourceMapConsumer.GENERATED_ORDER` or
  1375. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  1376. * iterate over the mappings sorted by the generated file's line/column
  1377. * order or the original's source/line/column order, respectively. Defaults to
  1378. * `SourceMapConsumer.GENERATED_ORDER`.
  1379. */
  1380. eachMapping(aCallback, aContext, aOrder) {
  1381. throw new Error("Subclasses must implement eachMapping");
  1382. }
  1383. /**
  1384. * Returns all generated line and column information for the original source,
  1385. * line, and column provided. If no column is provided, returns all mappings
  1386. * corresponding to a either the line we are searching for or the next
  1387. * closest line that has any mappings. Otherwise, returns all mappings
  1388. * corresponding to the given line and either the column we are searching for
  1389. * or the next closest column that has any offsets.
  1390. *
  1391. * The only argument is an object with the following properties:
  1392. *
  1393. * - source: The filename of the original source.
  1394. * - line: The line number in the original source. The line number is 1-based.
  1395. * - column: Optional. the column number in the original source.
  1396. * The column number is 0-based.
  1397. *
  1398. * and an array of objects is returned, each with the following properties:
  1399. *
  1400. * - line: The line number in the generated source, or null. The
  1401. * line number is 1-based.
  1402. * - column: The column number in the generated source, or null.
  1403. * The column number is 0-based.
  1404. */
  1405. allGeneratedPositionsFor(aArgs) {
  1406. throw new Error("Subclasses must implement allGeneratedPositionsFor");
  1407. }
  1408. destroy() {
  1409. throw new Error("Subclasses must implement destroy");
  1410. }
  1411. }
  1412. /**
  1413. * The version of the source mapping spec that we are consuming.
  1414. */
  1415. SourceMapConsumer.prototype._version = 3;
  1416. SourceMapConsumer.GENERATED_ORDER = 1;
  1417. SourceMapConsumer.ORIGINAL_ORDER = 2;
  1418. SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
  1419. SourceMapConsumer.LEAST_UPPER_BOUND = 2;
  1420. exports.SourceMapConsumer = SourceMapConsumer;
  1421. /**
  1422. * A BasicSourceMapConsumer instance represents a parsed source map which we can
  1423. * query for information about the original file positions by giving it a file
  1424. * position in the generated source.
  1425. *
  1426. * The first parameter is the raw source map (either as a JSON string, or
  1427. * already parsed to an object). According to the spec, source maps have the
  1428. * following attributes:
  1429. *
  1430. * - version: Which version of the source map spec this map is following.
  1431. * - sources: An array of URLs to the original source files.
  1432. * - names: An array of identifiers which can be referenced by individual mappings.
  1433. * - sourceRoot: Optional. The URL root from which all sources are relative.
  1434. * - sourcesContent: Optional. An array of contents of the original source files.
  1435. * - mappings: A string of base64 VLQs which contain the actual mappings.
  1436. * - file: Optional. The generated file this source map is associated with.
  1437. *
  1438. * Here is an example source map, taken from the source map spec[0]:
  1439. *
  1440. * {
  1441. * version : 3,
  1442. * file: "out.js",
  1443. * sourceRoot : "",
  1444. * sources: ["foo.js", "bar.js"],
  1445. * names: ["src", "maps", "are", "fun"],
  1446. * mappings: "AA,AB;;ABCDE;"
  1447. * }
  1448. *
  1449. * The second parameter, if given, is a string whose value is the URL
  1450. * at which the source map was found. This URL is used to compute the
  1451. * sources array.
  1452. *
  1453. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  1454. */
  1455. class BasicSourceMapConsumer extends SourceMapConsumer {
  1456. constructor(aSourceMap, aSourceMapURL) {
  1457. return super(INTERNAL).then(that => {
  1458. let sourceMap = aSourceMap;
  1459. if (typeof aSourceMap === "string") {
  1460. sourceMap = util.parseSourceMapInput(aSourceMap);
  1461. }
  1462. const version = util.getArg(sourceMap, "version");
  1463. let sources = util.getArg(sourceMap, "sources");
  1464. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  1465. // requires the array) to play nice here.
  1466. const names = util.getArg(sourceMap, "names", []);
  1467. let sourceRoot = util.getArg(sourceMap, "sourceRoot", null);
  1468. const sourcesContent = util.getArg(sourceMap, "sourcesContent", null);
  1469. const mappings = util.getArg(sourceMap, "mappings");
  1470. const file = util.getArg(sourceMap, "file", null);
  1471. // Once again, Sass deviates from the spec and supplies the version as a
  1472. // string rather than a number, so we use loose equality checking here.
  1473. if (version != that._version) {
  1474. throw new Error("Unsupported version: " + version);
  1475. }
  1476. if (sourceRoot) {
  1477. sourceRoot = util.normalize(sourceRoot);
  1478. }
  1479. sources = sources
  1480. .map(String)
  1481. // Some source maps produce relative source paths like "./foo.js" instead of
  1482. // "foo.js". Normalize these first so that future comparisons will succeed.
  1483. // See bugzil.la/1090768.
  1484. .map(util.normalize)
  1485. // Always ensure that absolute sources are internally stored relative to
  1486. // the source root, if the source root is absolute. Not doing this would
  1487. // be particularly problematic when the source root is a prefix of the
  1488. // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
  1489. .map(function(source) {
  1490. return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
  1491. ? util.relative(sourceRoot, source)
  1492. : source;
  1493. });
  1494. // Pass `true` below to allow duplicate names and sources. While source maps
  1495. // are intended to be compressed and deduplicated, the TypeScript compiler
  1496. // sometimes generates source maps with duplicates in them. See Github issue
  1497. // #72 and bugzil.la/889492.
  1498. that._names = ArraySet.fromArray(names.map(String), true);
  1499. that._sources = ArraySet.fromArray(sources, true);
  1500. that._absoluteSources = that._sources.toArray().map(function(s) {
  1501. return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
  1502. });
  1503. that.sourceRoot = sourceRoot;
  1504. that.sourcesContent = sourcesContent;
  1505. that._mappings = mappings;
  1506. that._sourceMapURL = aSourceMapURL;
  1507. that.file = file;
  1508. that._computedColumnSpans = false;
  1509. that._mappingsPtr = 0;
  1510. that._wasm = null;
  1511. return wasm().then(w => {
  1512. that._wasm = w;
  1513. return that;
  1514. });
  1515. });
  1516. }
  1517. /**
  1518. * Utility function to find the index of a source. Returns -1 if not
  1519. * found.
  1520. */
  1521. _findSourceIndex(aSource) {
  1522. let relativeSource = aSource;
  1523. if (this.sourceRoot != null) {
  1524. relativeSource = util.relative(this.sourceRoot, relativeSource);
  1525. }
  1526. if (this._sources.has(relativeSource)) {
  1527. return this._sources.indexOf(relativeSource);
  1528. }
  1529. // Maybe aSource is an absolute URL as returned by |sources|. In
  1530. // this case we can't simply undo the transform.
  1531. for (let i = 0; i < this._absoluteSources.length; ++i) {
  1532. if (this._absoluteSources[i] == aSource) {
  1533. return i;
  1534. }
  1535. }
  1536. return -1;
  1537. }
  1538. /**
  1539. * Create a BasicSourceMapConsumer from a SourceMapGenerator.
  1540. *
  1541. * @param SourceMapGenerator aSourceMap
  1542. * The source map that will be consumed.
  1543. * @param String aSourceMapURL
  1544. * The URL at which the source map can be found (optional)
  1545. * @returns BasicSourceMapConsumer
  1546. */
  1547. static fromSourceMap(aSourceMap, aSourceMapURL) {
  1548. return new BasicSourceMapConsumer(aSourceMap.toString());
  1549. }
  1550. get sources() {
  1551. return this._absoluteSources.slice();
  1552. }
  1553. _getMappingsPtr() {
  1554. if (this._mappingsPtr === 0) {
  1555. this._parseMappings(this._mappings, this.sourceRoot);
  1556. }
  1557. return this._mappingsPtr;
  1558. }
  1559. /**
  1560. * Parse the mappings in a string in to a data structure which we can easily
  1561. * query (the ordered arrays in the `this.__generatedMappings` and
  1562. * `this.__originalMappings` properties).
  1563. */
  1564. _parseMappings(aStr, aSourceRoot) {
  1565. const size = aStr.length;
  1566. const mappingsBufPtr = this._wasm.exports.allocate_mappings(size);
  1567. const mappingsBuf = new Uint8Array(this._wasm.exports.memory.buffer, mappingsBufPtr, size);
  1568. for (let i = 0; i < size; i++) {
  1569. mappingsBuf[i] = aStr.charCodeAt(i);
  1570. }
  1571. const mappingsPtr = this._wasm.exports.parse_mappings(mappingsBufPtr);
  1572. if (!mappingsPtr) {
  1573. const error = this._wasm.exports.get_last_error();
  1574. let msg = `Error parsing mappings (code ${error}): `;
  1575. // XXX: keep these error codes in sync with `fitzgen/source-map-mappings`.
  1576. switch (error) {
  1577. case 1:
  1578. msg += "the mappings contained a negative line, column, source index, or name index";
  1579. break;
  1580. case 2:
  1581. msg += "the mappings contained a number larger than 2**32";
  1582. break;
  1583. case 3:
  1584. msg += "reached EOF while in the middle of parsing a VLQ";
  1585. break;
  1586. case 4:
  1587. msg += "invalid base 64 character while parsing a VLQ";
  1588. break;
  1589. default:
  1590. msg += "unknown error code";
  1591. break;
  1592. }
  1593. throw new Error(msg);
  1594. }
  1595. this._mappingsPtr = mappingsPtr;
  1596. }
  1597. eachMapping(aCallback, aContext, aOrder) {
  1598. const context = aContext || null;
  1599. const order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  1600. const sourceRoot = this.sourceRoot;
  1601. this._wasm.withMappingCallback(
  1602. mapping => {
  1603. if (mapping.source !== null) {
  1604. mapping.source = this._sources.at(mapping.source);
  1605. mapping.source = util.computeSourceURL(sourceRoot, mapping.source, this._sourceMapURL);
  1606. if (mapping.name !== null) {
  1607. mapping.name = this._names.at(mapping.name);
  1608. }
  1609. }
  1610. aCallback.call(context, mapping);
  1611. },
  1612. () => {
  1613. switch (order) {
  1614. case SourceMapConsumer.GENERATED_ORDER:
  1615. this._wasm.exports.by_generated_location(this._getMappingsPtr());
  1616. break;
  1617. case SourceMapConsumer.ORIGINAL_ORDER:
  1618. this._wasm.exports.by_original_location(this._getMappingsPtr());
  1619. break;
  1620. default:
  1621. throw new Error("Unknown order of iteration.");
  1622. }
  1623. }
  1624. );
  1625. }
  1626. allGeneratedPositionsFor(aArgs) {
  1627. let source = util.getArg(aArgs, "source");
  1628. const originalLine = util.getArg(aArgs, "line");
  1629. const originalColumn = aArgs.column || 0;
  1630. source = this._findSourceIndex(source);
  1631. if (source < 0) {
  1632. return [];
  1633. }
  1634. if (originalLine < 1) {
  1635. throw new Error("Line numbers must be >= 1");
  1636. }
  1637. if (originalColumn < 0) {
  1638. throw new Error("Column numbers must be >= 0");
  1639. }
  1640. const mappings = [];
  1641. this._wasm.withMappingCallback(
  1642. m => {
  1643. let lastColumn = m.lastGeneratedColumn;
  1644. if (this._computedColumnSpans && lastColumn === null) {
  1645. lastColumn = Infinity;
  1646. }
  1647. mappings.push({
  1648. line: m.generatedLine,
  1649. column: m.generatedColumn,
  1650. lastColumn,
  1651. });
  1652. }, () => {
  1653. this._wasm.exports.all_generated_locations_for(
  1654. this._getMappingsPtr(),
  1655. source,
  1656. originalLine - 1,
  1657. "column" in aArgs,
  1658. originalColumn
  1659. );
  1660. }
  1661. );
  1662. return mappings;
  1663. }
  1664. destroy() {
  1665. if (this._mappingsPtr !== 0) {
  1666. this._wasm.exports.free_mappings(this._mappingsPtr);
  1667. this._mappingsPtr = 0;
  1668. }
  1669. }
  1670. /**
  1671. * Compute the last column for each generated mapping. The last column is
  1672. * inclusive.
  1673. */
  1674. computeColumnSpans() {
  1675. if (this._computedColumnSpans) {
  1676. return;
  1677. }
  1678. this._wasm.exports.compute_column_spans(this._getMappingsPtr());
  1679. this._computedColumnSpans = true;
  1680. }
  1681. /**
  1682. * Returns the original source, line, and column information for the generated
  1683. * source's line and column positions provided. The only argument is an object
  1684. * with the following properties:
  1685. *
  1686. * - line: The line number in the generated source. The line number
  1687. * is 1-based.
  1688. * - column: The column number in the generated source. The column
  1689. * number is 0-based.
  1690. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  1691. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  1692. * closest element that is smaller than or greater than the one we are
  1693. * searching for, respectively, if the exact element cannot be found.
  1694. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  1695. *
  1696. * and an object is returned with the following properties:
  1697. *
  1698. * - source: The original source file, or null.
  1699. * - line: The line number in the original source, or null. The
  1700. * line number is 1-based.
  1701. * - column: The column number in the original source, or null. The
  1702. * column number is 0-based.
  1703. * - name: The original identifier, or null.
  1704. */
  1705. originalPositionFor(aArgs) {
  1706. const needle = {
  1707. generatedLine: util.getArg(aArgs, "line"),
  1708. generatedColumn: util.getArg(aArgs, "column")
  1709. };
  1710. if (needle.generatedLine < 1) {
  1711. throw new Error("Line numbers must be >= 1");
  1712. }
  1713. if (needle.generatedColumn < 0) {
  1714. throw new Error("Column numbers must be >= 0");
  1715. }
  1716. let bias = util.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND);
  1717. if (bias == null) {
  1718. bias = SourceMapConsumer.GREATEST_LOWER_BOUND;
  1719. }
  1720. let mapping;
  1721. this._wasm.withMappingCallback(m => mapping = m, () => {
  1722. this._wasm.exports.original_location_for(
  1723. this._getMappingsPtr(),
  1724. needle.generatedLine - 1,
  1725. needle.generatedColumn,
  1726. bias
  1727. );
  1728. });
  1729. if (mapping) {
  1730. if (mapping.generatedLine === needle.generatedLine) {
  1731. let source = util.getArg(mapping, "source", null);
  1732. if (source !== null) {
  1733. source = this._sources.at(source);
  1734. source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
  1735. }
  1736. let name = util.getArg(mapping, "name", null);
  1737. if (name !== null) {
  1738. name = this._names.at(name);
  1739. }
  1740. return {
  1741. source,
  1742. line: util.getArg(mapping, "originalLine", null),
  1743. column: util.getArg(mapping, "originalColumn", null),
  1744. name
  1745. };
  1746. }
  1747. }
  1748. return {
  1749. source: null,
  1750. line: null,
  1751. column: null,
  1752. name: null
  1753. };
  1754. }
  1755. /**
  1756. * Return true if we have the source content for every source in the source
  1757. * map, false otherwise.
  1758. */
  1759. hasContentsOfAllSources() {
  1760. if (!this.sourcesContent) {
  1761. return false;
  1762. }
  1763. return this.sourcesContent.length >= this._sources.size() &&
  1764. !this.sourcesContent.some(function(sc) { return sc == null; });
  1765. }
  1766. /**
  1767. * Returns the original source content. The only argument is the url of the
  1768. * original source file. Returns null if no original source content is
  1769. * available.
  1770. */
  1771. sourceContentFor(aSource, nullOnMissing) {
  1772. if (!this.sourcesContent) {
  1773. return null;
  1774. }
  1775. const index = this._findSourceIndex(aSource);
  1776. if (index >= 0) {
  1777. return this.sourcesContent[index];
  1778. }
  1779. let relativeSource = aSource;
  1780. if (this.sourceRoot != null) {
  1781. relativeSource = util.relative(this.sourceRoot, relativeSource);
  1782. }
  1783. let url;
  1784. if (this.sourceRoot != null
  1785. && (url = util.urlParse(this.sourceRoot))) {
  1786. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  1787. // many users. We can help them out when they expect file:// URIs to
  1788. // behave like it would if they were running a local HTTP server. See
  1789. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  1790. const fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
  1791. if (url.scheme == "file"
  1792. && this._sources.has(fileUriAbsPath)) {
  1793. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)];
  1794. }
  1795. if ((!url.path || url.path == "/")
  1796. && this._sources.has("/" + relativeSource)) {
  1797. return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
  1798. }
  1799. }
  1800. // This function is used recursively from
  1801. // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
  1802. // don't want to throw if we can't find the source - we just want to
  1803. // return null, so we provide a flag to exit gracefully.
  1804. if (nullOnMissing) {
  1805. return null;
  1806. }
  1807. throw new Error('"' + relativeSource + '" is not in the SourceMap.');
  1808. }
  1809. /**
  1810. * Returns the generated line and column information for the original source,
  1811. * line, and column positions provided. The only argument is an object with
  1812. * the following properties:
  1813. *
  1814. * - source: The filename of the original source.
  1815. * - line: The line number in the original source. The line number
  1816. * is 1-based.
  1817. * - column: The column number in the original source. The column
  1818. * number is 0-based.
  1819. * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
  1820. * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
  1821. * closest element that is smaller than or greater than the one we are
  1822. * searching for, respectively, if the exact element cannot be found.
  1823. * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
  1824. *
  1825. * and an object is returned with the following properties:
  1826. *
  1827. * - line: The line number in the generated source, or null. The
  1828. * line number is 1-based.
  1829. * - column: The column number in the generated source, or null.
  1830. * The column number is 0-based.
  1831. */
  1832. generatedPositionFor(aArgs) {
  1833. let source = util.getArg(aArgs, "source");
  1834. source = this._findSourceIndex(source);
  1835. if (source < 0) {
  1836. return {
  1837. line: null,
  1838. column: null,
  1839. lastColumn: null
  1840. };
  1841. }
  1842. const needle = {
  1843. source,
  1844. originalLine: util.getArg(aArgs, "line"),
  1845. originalColumn: util.getArg(aArgs, "column")
  1846. };
  1847. if (needle.originalLine < 1) {
  1848. throw new Error("Line numbers must be >= 1");
  1849. }
  1850. if (needle.originalColumn < 0) {
  1851. throw new Error("Column numbers must be >= 0");
  1852. }
  1853. let bias = util.getArg(aArgs, "bias", SourceMapConsumer.GREATEST_LOWER_BOUND);
  1854. if (bias == null) {
  1855. bias = SourceMapConsumer.GREATEST_LOWER_BOUND;
  1856. }
  1857. let mapping;
  1858. this._wasm.withMappingCallback(m => mapping = m, () => {
  1859. this._wasm.exports.generated_location_for(
  1860. this._getMappingsPtr(),
  1861. needle.source,
  1862. needle.originalLine - 1,
  1863. needle.originalColumn,
  1864. bias
  1865. );
  1866. });
  1867. if (mapping) {
  1868. if (mapping.source === needle.source) {
  1869. let lastColumn = mapping.lastGeneratedColumn;
  1870. if (this._computedColumnSpans && lastColumn === null) {
  1871. lastColumn = Infinity;
  1872. }
  1873. return {
  1874. line: util.getArg(mapping, "generatedLine", null),
  1875. column: util.getArg(mapping, "generatedColumn", null),
  1876. lastColumn,
  1877. };
  1878. }
  1879. }
  1880. return {
  1881. line: null,
  1882. column: null,
  1883. lastColumn: null
  1884. };
  1885. }
  1886. }
  1887. BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
  1888. exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
  1889. /**
  1890. * An IndexedSourceMapConsumer instance represents a parsed source map which
  1891. * we can query for information. It differs from BasicSourceMapConsumer in
  1892. * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
  1893. * input.
  1894. *
  1895. * The first parameter is a raw source map (either as a JSON string, or already
  1896. * parsed to an object). According to the spec for indexed source maps, they
  1897. * have the following attributes:
  1898. *
  1899. * - version: Which version of the source map spec this map is following.
  1900. * - file: Optional. The generated file this source map is associated with.
  1901. * - sections: A list of section definitions.
  1902. *
  1903. * Each value under the "sections" field has two fields:
  1904. * - offset: The offset into the original specified at which this section
  1905. * begins to apply, defined as an object with a "line" and "column"
  1906. * field.
  1907. * - map: A source map definition. This source map could also be indexed,
  1908. * but doesn't have to be.
  1909. *
  1910. * Instead of the "map" field, it's also possible to have a "url" field
  1911. * specifying a URL to retrieve a source map from, but that's currently
  1912. * unsupported.
  1913. *
  1914. * Here's an example source map, taken from the source map spec[0], but
  1915. * modified to omit a section which uses the "url" field.
  1916. *
  1917. * {
  1918. * version : 3,
  1919. * file: "app.js",
  1920. * sections: [{
  1921. * offset: {line:100, column:10},
  1922. * map: {
  1923. * version : 3,
  1924. * file: "section.js",
  1925. * sources: ["foo.js", "bar.js"],
  1926. * names: ["src", "maps", "are", "fun"],
  1927. * mappings: "AAAA,E;;ABCDE;"
  1928. * }
  1929. * }],
  1930. * }
  1931. *
  1932. * The second parameter, if given, is a string whose value is the URL
  1933. * at which the source map was found. This URL is used to compute the
  1934. * sources array.
  1935. *
  1936. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
  1937. */
  1938. class IndexedSourceMapConsumer extends SourceMapConsumer {
  1939. constructor(aSourceMap, aSourceMapURL) {
  1940. return super(INTERNAL).then(that => {
  1941. let sourceMap = aSourceMap;
  1942. if (typeof aSourceMap === "string") {
  1943. sourceMap = util.parseSourceMapInput(aSourceMap);
  1944. }
  1945. const version = util.getArg(sourceMap, "version");
  1946. const sections = util.getArg(sourceMap, "sections");
  1947. if (version != that._version) {
  1948. throw new Error("Unsupported version: " + version);
  1949. }
  1950. that._sources = new ArraySet();
  1951. that._names = new ArraySet();
  1952. that.__generatedMappings = null;
  1953. that.__originalMappings = null;
  1954. that.__generatedMappingsUnsorted = null;
  1955. that.__originalMappingsUnsorted = null;
  1956. let lastOffset = {
  1957. line: -1,
  1958. column: 0
  1959. };
  1960. return Promise.all(sections.map(s => {
  1961. if (s.url) {
  1962. // The url field will require support for asynchronicity.
  1963. // See https://github.com/mozilla/source-map/issues/16
  1964. throw new Error("Support for url field in sections not implemented.");
  1965. }
  1966. const offset = util.getArg(s, "offset");
  1967. const offsetLine = util.getArg(offset, "line");
  1968. const offsetColumn = util.getArg(offset, "column");
  1969. if (offsetLine < lastOffset.line ||
  1970. (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
  1971. throw new Error("Section offsets must be ordered and non-overlapping.");
  1972. }
  1973. lastOffset = offset;
  1974. const cons = new SourceMapConsumer(util.getArg(s, "map"), aSourceMapURL);
  1975. return cons.then(consumer => {
  1976. return {
  1977. generatedOffset: {
  1978. // The offset fields are 0-based, but we use 1-based indices when
  1979. // encoding/decoding from VLQ.
  1980. generatedLine: offsetLine + 1,
  1981. generatedColumn: offsetColumn + 1
  1982. },
  1983. consumer
  1984. };
  1985. });
  1986. })).then(s => {
  1987. that._sections = s;
  1988. return that;
  1989. });
  1990. });
  1991. }
  1992. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  1993. // parsed mapping coordinates from the source map's "mappings" attribute. They
  1994. // are lazily instantiated, accessed via the `_generatedMappings` and
  1995. // `_originalMappings` getters respectively, and we only parse the mappings
  1996. // and create these arrays once queried for a source location. We jump through
  1997. // these hoops because there can be many thousands of mappings, and parsing
  1998. // them is expensive, so we only want to do it if we must.
  1999. //
  2000. // Each object in the arrays is of the form:
  2001. //
  2002. // {
  2003. // generatedLine: The line number in the generated code,
  2004. // generatedColumn: The column number in the generated code,
  2005. // source: The path to the original source file that generated this
  2006. // chunk of code,
  2007. // originalLine: The line number in the original source that
  2008. // corresponds to this chunk of generated code,
  2009. // originalColumn: The column number in the original source that
  2010. // corresponds to this chunk of generated code,
  2011. // name: The name of the original symbol which generated this chunk of
  2012. // code.
  2013. // }
  2014. //
  2015. // All properties except for `generatedLine` and `generatedColumn` can be
  2016. // `null`.
  2017. //
  2018. // `_generatedMappings` is ordered by the generated positions.
  2019. //
  2020. // `_originalMappings` is ordered by the original positions.
  2021. get _generatedMappings() {
  2022. if (!this.__generatedMappings) {
  2023. this._sortGeneratedMappings();
  2024. }
  2025. return this.__generatedMappings;
  2026. }
  2027. get _originalMappings() {
  2028. if (!this.__originalMappings) {
  2029. this._sortOriginalMappings();
  2030. }
  2031. return this.__originalMappings;
  2032. }
  2033. get _generatedMappingsUnsorted() {
  2034. if (!this.__generatedMappingsUnsorted) {
  2035. this._parseMappings(this._mappings, this.sourceRoot);
  2036. }
  2037. return this.__generatedMappingsUnsorted;
  2038. }
  2039. get _originalMappingsUnsorted() {
  2040. if (!this.__originalMappingsUnsorted) {
  2041. this._parseMappings(this._mappings, this.sourceRoot);
  2042. }
  2043. return this.__originalMappingsUnsorted;
  2044. }
  2045. _sortGeneratedMappings() {
  2046. const mappings = this._generatedMappingsUnsorted;
  2047. mappings.sort(util.compareByGeneratedPositionsDeflated);
  2048. this.__generatedMappings = mappings;
  2049. }
  2050. _sortOriginalMappings() {
  2051. const mappings = this._originalMappingsUnsorted;
  2052. mappings.sort(util.compareByOriginalPositions);
  2053. this.__originalMappings = mappings;
  2054. }
  2055. /**
  2056. * The list of original sources.
  2057. */
  2058. get sources() {
  2059. const sources = [];
  2060. for (let i = 0; i < this._sections.length; i++) {
  2061. for (let j = 0; j < this._sections[i].consumer.sources.length; j++) {
  2062. sources.push(this._sections[i].consumer.sources[j]);
  2063. }
  2064. }
  2065. return sources;
  2066. }
  2067. /**
  2068. * Returns the original source, line, and column information for the generated
  2069. * source's line and column positions provided. The only argument is an object
  2070. * with the following properties:
  2071. *
  2072. * - line: The line number in the generated source. The line number
  2073. * is 1-based.
  2074. * - column: The column number in the generated source. The column
  2075. * number is 0-based.
  2076. *
  2077. * and an object is returned with the following properties:
  2078. *
  2079. * - source: The original source file, or null.
  2080. * - line: The line number in the original source, or null. The
  2081. * line number is 1-based.
  2082. * - column: The column number in the original source, or null. The
  2083. * column number is 0-based.
  2084. * - name: The original identifier, or null.
  2085. */
  2086. originalPositionFor(aArgs) {
  2087. const needle = {
  2088. generatedLine: util.getArg(aArgs, "line"),
  2089. generatedColumn: util.getArg(aArgs, "column")
  2090. };
  2091. // Find the section containing the generated position we're trying to map
  2092. // to an original position.
  2093. const sectionIndex = binarySearch.search(needle, this._sections,
  2094. function(aNeedle, section) {
  2095. const cmp = aNeedle.generatedLine - section.generatedOffset.generatedLine;
  2096. if (cmp) {
  2097. return cmp;
  2098. }
  2099. return (aNeedle.generatedColumn -
  2100. section.generatedOffset.generatedColumn);
  2101. });
  2102. const section = this._sections[sectionIndex];
  2103. if (!section) {
  2104. return {
  2105. source: null,
  2106. line: null,
  2107. column: null,
  2108. name: null
  2109. };
  2110. }
  2111. return section.consumer.originalPositionFor({
  2112. line: needle.generatedLine -
  2113. (section.generatedOffset.generatedLine - 1),
  2114. column: needle.generatedColumn -
  2115. (section.generatedOffset.generatedLine === needle.generatedLine
  2116. ? section.generatedOffset.generatedColumn - 1
  2117. : 0),
  2118. bias: aArgs.bias
  2119. });
  2120. }
  2121. /**
  2122. * Return true if we have the source content for every source in the source
  2123. * map, false otherwise.
  2124. */
  2125. hasContentsOfAllSources() {
  2126. return this._sections.every(function(s) {
  2127. return s.consumer.hasContentsOfAllSources();
  2128. });
  2129. }
  2130. /**
  2131. * Returns the original source content. The only argument is the url of the
  2132. * original source file. Returns null if no original source content is
  2133. * available.
  2134. */
  2135. sourceContentFor(aSource, nullOnMissing) {
  2136. for (let i = 0; i < this._sections.length; i++) {
  2137. const section = this._sections[i];
  2138. const content = section.consumer.sourceContentFor(aSource, true);
  2139. if (content) {
  2140. return content;
  2141. }
  2142. }
  2143. if (nullOnMissing) {
  2144. return null;
  2145. }
  2146. throw new Error('"' + aSource + '" is not in the SourceMap.');
  2147. }
  2148. /**
  2149. * Returns the generated line and column information for the original source,
  2150. * line, and column positions provided. The only argument is an object with
  2151. * the following properties:
  2152. *
  2153. * - source: The filename of the original source.
  2154. * - line: The line number in the original source. The line number
  2155. * is 1-based.
  2156. * - column: The column number in the original source. The column
  2157. * number is 0-based.
  2158. *
  2159. * and an object is returned with the following properties:
  2160. *
  2161. * - line: The line number in the generated source, or null. The
  2162. * line number is 1-based.
  2163. * - column: The column number in the generated source, or null.
  2164. * The column number is 0-based.
  2165. */
  2166. generatedPositionFor(aArgs) {
  2167. for (let i = 0; i < this._sections.length; i++) {
  2168. const section = this._sections[i];
  2169. // Only consider this section if the requested source is in the list of
  2170. // sources of the consumer.
  2171. if (section.consumer._findSourceIndex(util.getArg(aArgs, "source")) === -1) {
  2172. continue;
  2173. }
  2174. const generatedPosition = section.consumer.generatedPositionFor(aArgs);
  2175. if (generatedPosition) {
  2176. const ret = {
  2177. line: generatedPosition.line +
  2178. (section.generatedOffset.generatedLine - 1),
  2179. column: generatedPosition.column +
  2180. (section.generatedOffset.generatedLine === generatedPosition.line
  2181. ? section.generatedOffset.generatedColumn - 1
  2182. : 0)
  2183. };
  2184. return ret;
  2185. }
  2186. }
  2187. return {
  2188. line: null,
  2189. column: null
  2190. };
  2191. }
  2192. /**
  2193. * Parse the mappings in a string in to a data structure which we can easily
  2194. * query (the ordered arrays in the `this.__generatedMappings` and
  2195. * `this.__originalMappings` properties).
  2196. */
  2197. _parseMappings(aStr, aSourceRoot) {
  2198. const generatedMappings = this.__generatedMappingsUnsorted = [];
  2199. const originalMappings = this.__originalMappingsUnsorted = [];
  2200. for (let i = 0; i < this._sections.length; i++) {
  2201. const section = this._sections[i];
  2202. const sectionMappings = [];
  2203. section.consumer.eachMapping(m => sectionMappings.push(m));
  2204. for (let j = 0; j < sectionMappings.length; j++) {
  2205. const mapping = sectionMappings[j];
  2206. // TODO: test if null is correct here. The original code used
  2207. // `source`, which would actually have gotten used as null because
  2208. // var's get hoisted.
  2209. // See: https://github.com/mozilla/source-map/issues/333
  2210. let source = util.computeSourceURL(section.consumer.sourceRoot, null, this._sourceMapURL);
  2211. this._sources.add(source);
  2212. source = this._sources.indexOf(source);
  2213. let name = null;
  2214. if (mapping.name) {
  2215. this._names.add(mapping.name);
  2216. name = this._names.indexOf(mapping.name);
  2217. }
  2218. // The mappings coming from the consumer for the section have
  2219. // generated positions relative to the start of the section, so we
  2220. // need to offset them to be relative to the start of the concatenated
  2221. // generated file.
  2222. const adjustedMapping = {
  2223. source,
  2224. generatedLine: mapping.generatedLine +
  2225. (section.generatedOffset.generatedLine - 1),
  2226. generatedColumn: mapping.generatedColumn +
  2227. (section.generatedOffset.generatedLine === mapping.generatedLine
  2228. ? section.generatedOffset.generatedColumn - 1
  2229. : 0),
  2230. originalLine: mapping.originalLine,
  2231. originalColumn: mapping.originalColumn,
  2232. name
  2233. };
  2234. generatedMappings.push(adjustedMapping);
  2235. if (typeof adjustedMapping.originalLine === "number") {
  2236. originalMappings.push(adjustedMapping);
  2237. }
  2238. }
  2239. }
  2240. }
  2241. eachMapping(aCallback, aContext, aOrder) {
  2242. const context = aContext || null;
  2243. const order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  2244. let mappings;
  2245. switch (order) {
  2246. case SourceMapConsumer.GENERATED_ORDER:
  2247. mappings = this._generatedMappings;
  2248. break;
  2249. case SourceMapConsumer.ORIGINAL_ORDER:
  2250. mappings = this._originalMappings;
  2251. break;
  2252. default:
  2253. throw new Error("Unknown order of iteration.");
  2254. }
  2255. const sourceRoot = this.sourceRoot;
  2256. mappings.map(function(mapping) {
  2257. let source = null;
  2258. if (mapping.source !== null) {
  2259. source = this._sources.at(mapping.source);
  2260. source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
  2261. }
  2262. return {
  2263. source,
  2264. generatedLine: mapping.generatedLine,
  2265. generatedColumn: mapping.generatedColumn,
  2266. originalLine: mapping.originalLine,
  2267. originalColumn: mapping.originalColumn,
  2268. name: mapping.name === null ? null : this._names.at(mapping.name)
  2269. };
  2270. }, this).forEach(aCallback, context);
  2271. }
  2272. /**
  2273. * Find the mapping that best matches the hypothetical "needle" mapping that
  2274. * we are searching for in the given "haystack" of mappings.
  2275. */
  2276. _findMapping(aNeedle, aMappings, aLineName,
  2277. aColumnName, aComparator, aBias) {
  2278. // To return the position we are searching for, we must first find the
  2279. // mapping for the given position and then return the opposite position it
  2280. // points to. Because the mappings are sorted, we can use binary search to
  2281. // find the best mapping.
  2282. if (aNeedle[aLineName] <= 0) {
  2283. throw new TypeError("Line must be greater than or equal to 1, got "
  2284. + aNeedle[aLineName]);
  2285. }
  2286. if (aNeedle[aColumnName] < 0) {
  2287. throw new TypeError("Column must be greater than or equal to 0, got "
  2288. + aNeedle[aColumnName]);
  2289. }
  2290. return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
  2291. }
  2292. allGeneratedPositionsFor(aArgs) {
  2293. const line = util.getArg(aArgs, "line");
  2294. // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
  2295. // returns the index of the closest mapping less than the needle. By
  2296. // setting needle.originalColumn to 0, we thus find the last mapping for
  2297. // the given line, provided such a mapping exists.
  2298. const needle = {
  2299. source: util.getArg(aArgs, "source"),
  2300. originalLine: line,
  2301. originalColumn: util.getArg(aArgs, "column", 0)
  2302. };
  2303. needle.source = this._findSourceIndex(needle.source);
  2304. if (needle.source < 0) {
  2305. return [];
  2306. }
  2307. if (needle.originalLine < 1) {
  2308. throw new Error("Line numbers must be >= 1");
  2309. }
  2310. if (needle.originalColumn < 0) {
  2311. throw new Error("Column numbers must be >= 0");
  2312. }
  2313. const mappings = [];
  2314. let index = this._findMapping(needle,
  2315. this._originalMappings,
  2316. "originalLine",
  2317. "originalColumn",
  2318. util.compareByOriginalPositions,
  2319. binarySearch.LEAST_UPPER_BOUND);
  2320. if (index >= 0) {
  2321. let mapping = this._originalMappings[index];
  2322. if (aArgs.column === undefined) {
  2323. const originalLine = mapping.originalLine;
  2324. // Iterate until either we run out of mappings, or we run into
  2325. // a mapping for a different line than the one we found. Since
  2326. // mappings are sorted, this is guaranteed to find all mappings for
  2327. // the line we found.
  2328. while (mapping && mapping.originalLine === originalLine) {
  2329. let lastColumn = mapping.lastGeneratedColumn;
  2330. if (this._computedColumnSpans && lastColumn === null) {
  2331. lastColumn = Infinity;
  2332. }
  2333. mappings.push({
  2334. line: util.getArg(mapping, "generatedLine", null),
  2335. column: util.getArg(mapping, "generatedColumn", null),
  2336. lastColumn,
  2337. });
  2338. mapping = this._originalMappings[++index];
  2339. }
  2340. } else {
  2341. const originalColumn = mapping.originalColumn;
  2342. // Iterate until either we run out of mappings, or we run into
  2343. // a mapping for a different line than the one we were searching for.
  2344. // Since mappings are sorted, this is guaranteed to find all mappings for
  2345. // the line we are searching for.
  2346. while (mapping &&
  2347. mapping.originalLine === line &&
  2348. mapping.originalColumn == originalColumn) {
  2349. let lastColumn = mapping.lastGeneratedColumn;
  2350. if (this._computedColumnSpans && lastColumn === null) {
  2351. lastColumn = Infinity;
  2352. }
  2353. mappings.push({
  2354. line: util.getArg(mapping, "generatedLine", null),
  2355. column: util.getArg(mapping, "generatedColumn", null),
  2356. lastColumn,
  2357. });
  2358. mapping = this._originalMappings[++index];
  2359. }
  2360. }
  2361. }
  2362. return mappings;
  2363. }
  2364. destroy() {
  2365. for (let i = 0; i < this._sections.length; i++) {
  2366. this._sections[i].consumer.destroy();
  2367. }
  2368. }
  2369. }
  2370. exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
  2371. /*
  2372. * Cheat to get around inter-twingled classes. `factory()` can be at the end
  2373. * where it has access to non-hoisted classes, but it gets hoisted itself.
  2374. */
  2375. function _factory(aSourceMap, aSourceMapURL) {
  2376. let sourceMap = aSourceMap;
  2377. if (typeof aSourceMap === "string") {
  2378. sourceMap = util.parseSourceMapInput(aSourceMap);
  2379. }
  2380. const consumer = sourceMap.sections != null
  2381. ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
  2382. : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
  2383. return Promise.resolve(consumer);
  2384. }
  2385. function _factoryBSM(aSourceMap, aSourceMapURL) {
  2386. return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
  2387. }
  2388. /***/ }),
  2389. /* 9 */
  2390. /***/ (function(module, exports) {
  2391. /* -*- Mode: js; js-indent-level: 2; -*- */
  2392. /*
  2393. * Copyright 2011 Mozilla Foundation and contributors
  2394. * Licensed under the New BSD license. See LICENSE or:
  2395. * http://opensource.org/licenses/BSD-3-Clause
  2396. */
  2397. exports.GREATEST_LOWER_BOUND = 1;
  2398. exports.LEAST_UPPER_BOUND = 2;
  2399. /**
  2400. * Recursive implementation of binary search.
  2401. *
  2402. * @param aLow Indices here and lower do not contain the needle.
  2403. * @param aHigh Indices here and higher do not contain the needle.
  2404. * @param aNeedle The element being searched for.
  2405. * @param aHaystack The non-empty array being searched.
  2406. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  2407. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  2408. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  2409. * closest element that is smaller than or greater than the one we are
  2410. * searching for, respectively, if the exact element cannot be found.
  2411. */
  2412. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
  2413. // This function terminates when one of the following is true:
  2414. //
  2415. // 1. We find the exact element we are looking for.
  2416. //
  2417. // 2. We did not find the exact element, but we can return the index of
  2418. // the next-closest element.
  2419. //
  2420. // 3. We did not find the exact element, and there is no next-closest
  2421. // element than the one we are searching for, so we return -1.
  2422. const mid = Math.floor((aHigh - aLow) / 2) + aLow;
  2423. const cmp = aCompare(aNeedle, aHaystack[mid], true);
  2424. if (cmp === 0) {
  2425. // Found the element we are looking for.
  2426. return mid;
  2427. } else if (cmp > 0) {
  2428. // Our needle is greater than aHaystack[mid].
  2429. if (aHigh - mid > 1) {
  2430. // The element is in the upper half.
  2431. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
  2432. }
  2433. // The exact needle element was not found in this haystack. Determine if
  2434. // we are in termination case (3) or (2) and return the appropriate thing.
  2435. if (aBias == exports.LEAST_UPPER_BOUND) {
  2436. return aHigh < aHaystack.length ? aHigh : -1;
  2437. }
  2438. return mid;
  2439. }
  2440. // Our needle is less than aHaystack[mid].
  2441. if (mid - aLow > 1) {
  2442. // The element is in the lower half.
  2443. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
  2444. }
  2445. // we are in termination case (3) or (2) and return the appropriate thing.
  2446. if (aBias == exports.LEAST_UPPER_BOUND) {
  2447. return mid;
  2448. }
  2449. return aLow < 0 ? -1 : aLow;
  2450. }
  2451. /**
  2452. * This is an implementation of binary search which will always try and return
  2453. * the index of the closest element if there is no exact hit. This is because
  2454. * mappings between original and generated line/col pairs are single points,
  2455. * and there is an implicit region between each of them, so a miss just means
  2456. * that you aren't on the very start of a region.
  2457. *
  2458. * @param aNeedle The element you are looking for.
  2459. * @param aHaystack The array that is being searched.
  2460. * @param aCompare A function which takes the needle and an element in the
  2461. * array and returns -1, 0, or 1 depending on whether the needle is less
  2462. * than, equal to, or greater than the element, respectively.
  2463. * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
  2464. * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
  2465. * closest element that is smaller than or greater than the one we are
  2466. * searching for, respectively, if the exact element cannot be found.
  2467. * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
  2468. */
  2469. exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
  2470. if (aHaystack.length === 0) {
  2471. return -1;
  2472. }
  2473. let index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
  2474. aCompare, aBias || exports.GREATEST_LOWER_BOUND);
  2475. if (index < 0) {
  2476. return -1;
  2477. }
  2478. // We have found either the exact element, or the next-closest element than
  2479. // the one we are searching for. However, there may be more than one such
  2480. // element. Make sure we always return the smallest of these.
  2481. while (index - 1 >= 0) {
  2482. if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
  2483. break;
  2484. }
  2485. --index;
  2486. }
  2487. return index;
  2488. };
  2489. /***/ }),
  2490. /* 10 */
  2491. /***/ (function(module, exports) {
  2492. module.exports = __WEBPACK_EXTERNAL_MODULE_10__;
  2493. /***/ }),
  2494. /* 11 */
  2495. /***/ (function(module, exports) {
  2496. module.exports = __WEBPACK_EXTERNAL_MODULE_11__;
  2497. /***/ }),
  2498. /* 12 */
  2499. /***/ (function(module, exports, __webpack_require__) {
  2500. const readWasm = __webpack_require__(4);
  2501. /**
  2502. * Provide the JIT with a nice shape / hidden class.
  2503. */
  2504. function Mapping() {
  2505. this.generatedLine = 0;
  2506. this.generatedColumn = 0;
  2507. this.lastGeneratedColumn = null;
  2508. this.source = null;
  2509. this.originalLine = null;
  2510. this.originalColumn = null;
  2511. this.name = null;
  2512. }
  2513. let cachedWasm = null;
  2514. module.exports = function wasm() {
  2515. if (cachedWasm) {
  2516. return cachedWasm;
  2517. }
  2518. const callbackStack = [];
  2519. cachedWasm = readWasm().then(buffer => {
  2520. return WebAssembly.instantiate(buffer, {
  2521. env: {
  2522. mapping_callback(
  2523. generatedLine,
  2524. generatedColumn,
  2525. hasLastGeneratedColumn,
  2526. lastGeneratedColumn,
  2527. hasOriginal,
  2528. source,
  2529. originalLine,
  2530. originalColumn,
  2531. hasName,
  2532. name
  2533. ) {
  2534. const mapping = new Mapping();
  2535. // JS uses 1-based line numbers, wasm uses 0-based.
  2536. mapping.generatedLine = generatedLine + 1;
  2537. mapping.generatedColumn = generatedColumn;
  2538. if (hasLastGeneratedColumn) {
  2539. // JS uses inclusive last generated column, wasm uses exclusive.
  2540. mapping.lastGeneratedColumn = lastGeneratedColumn - 1;
  2541. }
  2542. if (hasOriginal) {
  2543. mapping.source = source;
  2544. // JS uses 1-based line numbers, wasm uses 0-based.
  2545. mapping.originalLine = originalLine + 1;
  2546. mapping.originalColumn = originalColumn;
  2547. if (hasName) {
  2548. mapping.name = name;
  2549. }
  2550. }
  2551. callbackStack[callbackStack.length - 1](mapping);
  2552. },
  2553. start_all_generated_locations_for() { console.time("all_generated_locations_for"); },
  2554. end_all_generated_locations_for() { console.timeEnd("all_generated_locations_for"); },
  2555. start_compute_column_spans() { console.time("compute_column_spans"); },
  2556. end_compute_column_spans() { console.timeEnd("compute_column_spans"); },
  2557. start_generated_location_for() { console.time("generated_location_for"); },
  2558. end_generated_location_for() { console.timeEnd("generated_location_for"); },
  2559. start_original_location_for() { console.time("original_location_for"); },
  2560. end_original_location_for() { console.timeEnd("original_location_for"); },
  2561. start_parse_mappings() { console.time("parse_mappings"); },
  2562. end_parse_mappings() { console.timeEnd("parse_mappings"); },
  2563. start_sort_by_generated_location() { console.time("sort_by_generated_location"); },
  2564. end_sort_by_generated_location() { console.timeEnd("sort_by_generated_location"); },
  2565. start_sort_by_original_location() { console.time("sort_by_original_location"); },
  2566. end_sort_by_original_location() { console.timeEnd("sort_by_original_location"); },
  2567. }
  2568. });
  2569. }).then(Wasm => {
  2570. return {
  2571. exports: Wasm.instance.exports,
  2572. withMappingCallback: (mappingCallback, f) => {
  2573. callbackStack.push(mappingCallback);
  2574. try {
  2575. f();
  2576. } finally {
  2577. callbackStack.pop();
  2578. }
  2579. }
  2580. };
  2581. }).then(null, e => {
  2582. cachedWasm = null;
  2583. throw e;
  2584. });
  2585. return cachedWasm;
  2586. };
  2587. /***/ }),
  2588. /* 13 */
  2589. /***/ (function(module, exports, __webpack_require__) {
  2590. /* -*- Mode: js; js-indent-level: 2; -*- */
  2591. /*
  2592. * Copyright 2011 Mozilla Foundation and contributors
  2593. * Licensed under the New BSD license. See LICENSE or:
  2594. * http://opensource.org/licenses/BSD-3-Clause
  2595. */
  2596. const SourceMapGenerator = __webpack_require__(1).SourceMapGenerator;
  2597. const util = __webpack_require__(0);
  2598. // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
  2599. // operating systems these days (capturing the result).
  2600. const REGEX_NEWLINE = /(\r?\n)/;
  2601. // Newline character code for charCodeAt() comparisons
  2602. const NEWLINE_CODE = 10;
  2603. // Private symbol for identifying `SourceNode`s when multiple versions of
  2604. // the source-map library are loaded. This MUST NOT CHANGE across
  2605. // versions!
  2606. const isSourceNode = "$$$isSourceNode$$$";
  2607. /**
  2608. * SourceNodes provide a way to abstract over interpolating/concatenating
  2609. * snippets of generated JavaScript source code while maintaining the line and
  2610. * column information associated with the original source code.
  2611. *
  2612. * @param aLine The original line number.
  2613. * @param aColumn The original column number.
  2614. * @param aSource The original source's filename.
  2615. * @param aChunks Optional. An array of strings which are snippets of
  2616. * generated JS, or other SourceNodes.
  2617. * @param aName The original identifier.
  2618. */
  2619. class SourceNode {
  2620. constructor(aLine, aColumn, aSource, aChunks, aName) {
  2621. this.children = [];
  2622. this.sourceContents = {};
  2623. this.line = aLine == null ? null : aLine;
  2624. this.column = aColumn == null ? null : aColumn;
  2625. this.source = aSource == null ? null : aSource;
  2626. this.name = aName == null ? null : aName;
  2627. this[isSourceNode] = true;
  2628. if (aChunks != null) this.add(aChunks);
  2629. }
  2630. /**
  2631. * Creates a SourceNode from generated code and a SourceMapConsumer.
  2632. *
  2633. * @param aGeneratedCode The generated code
  2634. * @param aSourceMapConsumer The SourceMap for the generated code
  2635. * @param aRelativePath Optional. The path that relative sources in the
  2636. * SourceMapConsumer should be relative to.
  2637. */
  2638. static fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
  2639. // The SourceNode we want to fill with the generated code
  2640. // and the SourceMap
  2641. const node = new SourceNode();
  2642. // All even indices of this array are one line of the generated code,
  2643. // while all odd indices are the newlines between two adjacent lines
  2644. // (since `REGEX_NEWLINE` captures its match).
  2645. // Processed fragments are accessed by calling `shiftNextLine`.
  2646. const remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
  2647. let remainingLinesIndex = 0;
  2648. const shiftNextLine = function() {
  2649. const lineContents = getNextLine();
  2650. // The last line of a file might not have a newline.
  2651. const newLine = getNextLine() || "";
  2652. return lineContents + newLine;
  2653. function getNextLine() {
  2654. return remainingLinesIndex < remainingLines.length ?
  2655. remainingLines[remainingLinesIndex++] : undefined;
  2656. }
  2657. };
  2658. // We need to remember the position of "remainingLines"
  2659. let lastGeneratedLine = 1, lastGeneratedColumn = 0;
  2660. // The generate SourceNodes we need a code range.
  2661. // To extract it current and last mapping is used.
  2662. // Here we store the last mapping.
  2663. let lastMapping = null;
  2664. let nextLine;
  2665. aSourceMapConsumer.eachMapping(function(mapping) {
  2666. if (lastMapping !== null) {
  2667. // We add the code from "lastMapping" to "mapping":
  2668. // First check if there is a new line in between.
  2669. if (lastGeneratedLine < mapping.generatedLine) {
  2670. // Associate first line with "lastMapping"
  2671. addMappingWithCode(lastMapping, shiftNextLine());
  2672. lastGeneratedLine++;
  2673. lastGeneratedColumn = 0;
  2674. // The remaining code is added without mapping
  2675. } else {
  2676. // There is no new line in between.
  2677. // Associate the code between "lastGeneratedColumn" and
  2678. // "mapping.generatedColumn" with "lastMapping"
  2679. nextLine = remainingLines[remainingLinesIndex] || "";
  2680. const code = nextLine.substr(0, mapping.generatedColumn -
  2681. lastGeneratedColumn);
  2682. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
  2683. lastGeneratedColumn);
  2684. lastGeneratedColumn = mapping.generatedColumn;
  2685. addMappingWithCode(lastMapping, code);
  2686. // No more remaining code, continue
  2687. lastMapping = mapping;
  2688. return;
  2689. }
  2690. }
  2691. // We add the generated code until the first mapping
  2692. // to the SourceNode without any mapping.
  2693. // Each line is added as separate string.
  2694. while (lastGeneratedLine < mapping.generatedLine) {
  2695. node.add(shiftNextLine());
  2696. lastGeneratedLine++;
  2697. }
  2698. if (lastGeneratedColumn < mapping.generatedColumn) {
  2699. nextLine = remainingLines[remainingLinesIndex] || "";
  2700. node.add(nextLine.substr(0, mapping.generatedColumn));
  2701. remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
  2702. lastGeneratedColumn = mapping.generatedColumn;
  2703. }
  2704. lastMapping = mapping;
  2705. }, this);
  2706. // We have processed all mappings.
  2707. if (remainingLinesIndex < remainingLines.length) {
  2708. if (lastMapping) {
  2709. // Associate the remaining code in the current line with "lastMapping"
  2710. addMappingWithCode(lastMapping, shiftNextLine());
  2711. }
  2712. // and add the remaining lines without any mapping
  2713. node.add(remainingLines.splice(remainingLinesIndex).join(""));
  2714. }
  2715. // Copy sourcesContent into SourceNode
  2716. aSourceMapConsumer.sources.forEach(function(sourceFile) {
  2717. const content = aSourceMapConsumer.sourceContentFor(sourceFile);
  2718. if (content != null) {
  2719. if (aRelativePath != null) {
  2720. sourceFile = util.join(aRelativePath, sourceFile);
  2721. }
  2722. node.setSourceContent(sourceFile, content);
  2723. }
  2724. });
  2725. return node;
  2726. function addMappingWithCode(mapping, code) {
  2727. if (mapping === null || mapping.source === undefined) {
  2728. node.add(code);
  2729. } else {
  2730. const source = aRelativePath
  2731. ? util.join(aRelativePath, mapping.source)
  2732. : mapping.source;
  2733. node.add(new SourceNode(mapping.originalLine,
  2734. mapping.originalColumn,
  2735. source,
  2736. code,
  2737. mapping.name));
  2738. }
  2739. }
  2740. }
  2741. /**
  2742. * Add a chunk of generated JS to this source node.
  2743. *
  2744. * @param aChunk A string snippet of generated JS code, another instance of
  2745. * SourceNode, or an array where each member is one of those things.
  2746. */
  2747. add(aChunk) {
  2748. if (Array.isArray(aChunk)) {
  2749. aChunk.forEach(function(chunk) {
  2750. this.add(chunk);
  2751. }, this);
  2752. } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  2753. if (aChunk) {
  2754. this.children.push(aChunk);
  2755. }
  2756. } else {
  2757. throw new TypeError(
  2758. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  2759. );
  2760. }
  2761. return this;
  2762. }
  2763. /**
  2764. * Add a chunk of generated JS to the beginning of this source node.
  2765. *
  2766. * @param aChunk A string snippet of generated JS code, another instance of
  2767. * SourceNode, or an array where each member is one of those things.
  2768. */
  2769. prepend(aChunk) {
  2770. if (Array.isArray(aChunk)) {
  2771. for (let i = aChunk.length - 1; i >= 0; i--) {
  2772. this.prepend(aChunk[i]);
  2773. }
  2774. } else if (aChunk[isSourceNode] || typeof aChunk === "string") {
  2775. this.children.unshift(aChunk);
  2776. } else {
  2777. throw new TypeError(
  2778. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  2779. );
  2780. }
  2781. return this;
  2782. }
  2783. /**
  2784. * Walk over the tree of JS snippets in this node and its children. The
  2785. * walking function is called once for each snippet of JS and is passed that
  2786. * snippet and the its original associated source's line/column location.
  2787. *
  2788. * @param aFn The traversal function.
  2789. */
  2790. walk(aFn) {
  2791. let chunk;
  2792. for (let i = 0, len = this.children.length; i < len; i++) {
  2793. chunk = this.children[i];
  2794. if (chunk[isSourceNode]) {
  2795. chunk.walk(aFn);
  2796. } else if (chunk !== "") {
  2797. aFn(chunk, { source: this.source,
  2798. line: this.line,
  2799. column: this.column,
  2800. name: this.name });
  2801. }
  2802. }
  2803. }
  2804. /**
  2805. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  2806. * each of `this.children`.
  2807. *
  2808. * @param aSep The separator.
  2809. */
  2810. join(aSep) {
  2811. let newChildren;
  2812. let i;
  2813. const len = this.children.length;
  2814. if (len > 0) {
  2815. newChildren = [];
  2816. for (i = 0; i < len - 1; i++) {
  2817. newChildren.push(this.children[i]);
  2818. newChildren.push(aSep);
  2819. }
  2820. newChildren.push(this.children[i]);
  2821. this.children = newChildren;
  2822. }
  2823. return this;
  2824. }
  2825. /**
  2826. * Call String.prototype.replace on the very right-most source snippet. Useful
  2827. * for trimming whitespace from the end of a source node, etc.
  2828. *
  2829. * @param aPattern The pattern to replace.
  2830. * @param aReplacement The thing to replace the pattern with.
  2831. */
  2832. replaceRight(aPattern, aReplacement) {
  2833. const lastChild = this.children[this.children.length - 1];
  2834. if (lastChild[isSourceNode]) {
  2835. lastChild.replaceRight(aPattern, aReplacement);
  2836. } else if (typeof lastChild === "string") {
  2837. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  2838. } else {
  2839. this.children.push("".replace(aPattern, aReplacement));
  2840. }
  2841. return this;
  2842. }
  2843. /**
  2844. * Set the source content for a source file. This will be added to the SourceMapGenerator
  2845. * in the sourcesContent field.
  2846. *
  2847. * @param aSourceFile The filename of the source file
  2848. * @param aSourceContent The content of the source file
  2849. */
  2850. setSourceContent(aSourceFile, aSourceContent) {
  2851. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  2852. }
  2853. /**
  2854. * Walk over the tree of SourceNodes. The walking function is called for each
  2855. * source file content and is passed the filename and source content.
  2856. *
  2857. * @param aFn The traversal function.
  2858. */
  2859. walkSourceContents(aFn) {
  2860. for (let i = 0, len = this.children.length; i < len; i++) {
  2861. if (this.children[i][isSourceNode]) {
  2862. this.children[i].walkSourceContents(aFn);
  2863. }
  2864. }
  2865. const sources = Object.keys(this.sourceContents);
  2866. for (let i = 0, len = sources.length; i < len; i++) {
  2867. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  2868. }
  2869. }
  2870. /**
  2871. * Return the string representation of this source node. Walks over the tree
  2872. * and concatenates all the various snippets together to one string.
  2873. */
  2874. toString() {
  2875. let str = "";
  2876. this.walk(function(chunk) {
  2877. str += chunk;
  2878. });
  2879. return str;
  2880. }
  2881. /**
  2882. * Returns the string representation of this source node along with a source
  2883. * map.
  2884. */
  2885. toStringWithSourceMap(aArgs) {
  2886. const generated = {
  2887. code: "",
  2888. line: 1,
  2889. column: 0
  2890. };
  2891. const map = new SourceMapGenerator(aArgs);
  2892. let sourceMappingActive = false;
  2893. let lastOriginalSource = null;
  2894. let lastOriginalLine = null;
  2895. let lastOriginalColumn = null;
  2896. let lastOriginalName = null;
  2897. this.walk(function(chunk, original) {
  2898. generated.code += chunk;
  2899. if (original.source !== null
  2900. && original.line !== null
  2901. && original.column !== null) {
  2902. if (lastOriginalSource !== original.source
  2903. || lastOriginalLine !== original.line
  2904. || lastOriginalColumn !== original.column
  2905. || lastOriginalName !== original.name) {
  2906. map.addMapping({
  2907. source: original.source,
  2908. original: {
  2909. line: original.line,
  2910. column: original.column
  2911. },
  2912. generated: {
  2913. line: generated.line,
  2914. column: generated.column
  2915. },
  2916. name: original.name
  2917. });
  2918. }
  2919. lastOriginalSource = original.source;
  2920. lastOriginalLine = original.line;
  2921. lastOriginalColumn = original.column;
  2922. lastOriginalName = original.name;
  2923. sourceMappingActive = true;
  2924. } else if (sourceMappingActive) {
  2925. map.addMapping({
  2926. generated: {
  2927. line: generated.line,
  2928. column: generated.column
  2929. }
  2930. });
  2931. lastOriginalSource = null;
  2932. sourceMappingActive = false;
  2933. }
  2934. for (let idx = 0, length = chunk.length; idx < length; idx++) {
  2935. if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
  2936. generated.line++;
  2937. generated.column = 0;
  2938. // Mappings end at eol
  2939. if (idx + 1 === length) {
  2940. lastOriginalSource = null;
  2941. sourceMappingActive = false;
  2942. } else if (sourceMappingActive) {
  2943. map.addMapping({
  2944. source: original.source,
  2945. original: {
  2946. line: original.line,
  2947. column: original.column
  2948. },
  2949. generated: {
  2950. line: generated.line,
  2951. column: generated.column
  2952. },
  2953. name: original.name
  2954. });
  2955. }
  2956. } else {
  2957. generated.column++;
  2958. }
  2959. }
  2960. });
  2961. this.walkSourceContents(function(sourceFile, sourceContent) {
  2962. map.setSourceContent(sourceFile, sourceContent);
  2963. });
  2964. return { code: generated.code, map };
  2965. }
  2966. }
  2967. exports.SourceNode = SourceNode;
  2968. /***/ })
  2969. /******/ ]);
  2970. });