PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/src/main/resources/META-INF/source-map.js

http://github.com/asual/lesscss-engine
JavaScript | 2064 lines | 1214 code | 199 blank | 651 comment | 255 complexity | a27bf14c23fa8d34a1fe1083a261daf6 MD5 | raw file
Possible License(s): Apache-2.0

Large files files are truncated, but you can click here to view the full file

  1. /* -*- Mode: js; js-indent-level: 2; -*- */
  2. /*
  3. * Copyright 2011 Mozilla Foundation and contributors
  4. * Licensed under the New BSD license. See LICENSE or:
  5. * http://opensource.org/licenses/BSD-3-Clause
  6. */
  7. /**
  8. * Define a module along with a payload.
  9. * @param {string} moduleName Name for the payload
  10. * @param {ignored} deps Ignored. For compatibility with CommonJS AMD Spec
  11. * @param {function} payload Function with (require, exports, module) params
  12. */
  13. function define(moduleName, deps, payload) {
  14. if (typeof moduleName != "string") {
  15. throw new TypeError('Expected string, got: ' + moduleName);
  16. }
  17. if (arguments.length == 2) {
  18. payload = deps;
  19. }
  20. if (moduleName in define.modules) {
  21. throw new Error("Module already defined: " + moduleName);
  22. }
  23. define.modules[moduleName] = payload;
  24. };
  25. /**
  26. * The global store of un-instantiated modules
  27. */
  28. define.modules = {};
  29. /**
  30. * We invoke require() in the context of a Domain so we can have multiple
  31. * sets of modules running separate from each other.
  32. * This contrasts with JSMs which are singletons, Domains allows us to
  33. * optionally load a CommonJS module twice with separate data each time.
  34. * Perhaps you want 2 command lines with a different set of commands in each,
  35. * for example.
  36. */
  37. function Domain() {
  38. this.modules = {};
  39. this._currentModule = null;
  40. }
  41. (function () {
  42. /**
  43. * Lookup module names and resolve them by calling the definition function if
  44. * needed.
  45. * There are 2 ways to call this, either with an array of dependencies and a
  46. * callback to call when the dependencies are found (which can happen
  47. * asynchronously in an in-page context) or with a single string an no callback
  48. * where the dependency is resolved synchronously and returned.
  49. * The API is designed to be compatible with the CommonJS AMD spec and
  50. * RequireJS.
  51. * @param {string[]|string} deps A name, or names for the payload
  52. * @param {function|undefined} callback Function to call when the dependencies
  53. * are resolved
  54. * @return {undefined|object} The module required or undefined for
  55. * array/callback method
  56. */
  57. Domain.prototype.require = function(deps, callback) {
  58. if (Array.isArray(deps)) {
  59. var params = deps.map(function(dep) {
  60. return this.lookup(dep);
  61. }, this);
  62. if (callback) {
  63. callback.apply(null, params);
  64. }
  65. return undefined;
  66. }
  67. else {
  68. return this.lookup(deps);
  69. }
  70. };
  71. function normalize(path) {
  72. var bits = path.split('/');
  73. var i = 1;
  74. while (i < bits.length) {
  75. if (bits[i] === '..') {
  76. bits.splice(i-1, 1);
  77. } else if (bits[i] === '.') {
  78. bits.splice(i, 1);
  79. } else {
  80. i++;
  81. }
  82. }
  83. return bits.join('/');
  84. }
  85. function join(a, b) {
  86. a = a.trim();
  87. b = b.trim();
  88. if (/^\//.test(b)) {
  89. return b;
  90. } else {
  91. return a.replace(/\/*$/, '/') + b;
  92. }
  93. }
  94. function dirname(path) {
  95. var bits = path.split('/');
  96. bits.pop();
  97. return bits.join('/');
  98. }
  99. /**
  100. * Lookup module names and resolve them by calling the definition function if
  101. * needed.
  102. * @param {string} moduleName A name for the payload to lookup
  103. * @return {object} The module specified by aModuleName or null if not found.
  104. */
  105. Domain.prototype.lookup = function(moduleName) {
  106. if (/^\./.test(moduleName)) {
  107. moduleName = normalize(join(dirname(this._currentModule), moduleName));
  108. }
  109. if (moduleName in this.modules) {
  110. var module = this.modules[moduleName];
  111. return module;
  112. }
  113. if (!(moduleName in define.modules)) {
  114. throw new Error("Module not defined: " + moduleName);
  115. }
  116. var module = define.modules[moduleName];
  117. if (typeof module == "function") {
  118. var exports = {};
  119. var previousModule = this._currentModule;
  120. this._currentModule = moduleName;
  121. module(this.require.bind(this), exports, { id: moduleName, uri: "" });
  122. this._currentModule = previousModule;
  123. module = exports;
  124. }
  125. // cache the resulting module object for next time
  126. this.modules[moduleName] = module;
  127. return module;
  128. };
  129. }());
  130. define.Domain = Domain;
  131. define.globalDomain = new Domain();
  132. var require = define.globalDomain.require.bind(define.globalDomain);
  133. /* -*- Mode: js; js-indent-level: 2; -*- */
  134. /*
  135. * Copyright 2011 Mozilla Foundation and contributors
  136. * Licensed under the New BSD license. See LICENSE or:
  137. * http://opensource.org/licenses/BSD-3-Clause
  138. */
  139. define('source-map/source-map-generator', ['require', 'exports', 'module' , 'source-map/base64-vlq', 'source-map/util', 'source-map/array-set'], function(require, exports, module) {
  140. var base64VLQ = require('./base64-vlq');
  141. var util = require('./util');
  142. var ArraySet = require('./array-set').ArraySet;
  143. /**
  144. * An instance of the SourceMapGenerator represents a source map which is
  145. * being built incrementally. You may pass an object with the following
  146. * properties:
  147. *
  148. * - file: The filename of the generated source.
  149. * - sourceRoot: A root for all relative URLs in this source map.
  150. */
  151. function SourceMapGenerator(aArgs) {
  152. if (!aArgs) {
  153. aArgs = {};
  154. }
  155. this._file = util.getArg(aArgs, 'file', null);
  156. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  157. this._sources = new ArraySet();
  158. this._names = new ArraySet();
  159. this._mappings = [];
  160. this._sourcesContents = null;
  161. }
  162. SourceMapGenerator.prototype._version = 3;
  163. /**
  164. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  165. *
  166. * @param aSourceMapConsumer The SourceMap.
  167. */
  168. SourceMapGenerator.fromSourceMap =
  169. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  170. var sourceRoot = aSourceMapConsumer.sourceRoot;
  171. var generator = new SourceMapGenerator({
  172. file: aSourceMapConsumer.file,
  173. sourceRoot: sourceRoot
  174. });
  175. aSourceMapConsumer.eachMapping(function (mapping) {
  176. var newMapping = {
  177. generated: {
  178. line: mapping.generatedLine,
  179. column: mapping.generatedColumn
  180. }
  181. };
  182. if (mapping.source) {
  183. newMapping.source = mapping.source;
  184. if (sourceRoot) {
  185. newMapping.source = util.relative(sourceRoot, newMapping.source);
  186. }
  187. newMapping.original = {
  188. line: mapping.originalLine,
  189. column: mapping.originalColumn
  190. };
  191. if (mapping.name) {
  192. newMapping.name = mapping.name;
  193. }
  194. }
  195. generator.addMapping(newMapping);
  196. });
  197. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  198. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  199. if (content) {
  200. generator.setSourceContent(sourceFile, content);
  201. }
  202. });
  203. return generator;
  204. };
  205. /**
  206. * Add a single mapping from original source line and column to the generated
  207. * source's line and column for this source map being created. The mapping
  208. * object should have the following properties:
  209. *
  210. * - generated: An object with the generated line and column positions.
  211. * - original: An object with the original line and column positions.
  212. * - source: The original source file (relative to the sourceRoot).
  213. * - name: An optional original token name for this mapping.
  214. */
  215. SourceMapGenerator.prototype.addMapping =
  216. function SourceMapGenerator_addMapping(aArgs) {
  217. var generated = util.getArg(aArgs, 'generated');
  218. var original = util.getArg(aArgs, 'original', null);
  219. var source = util.getArg(aArgs, 'source', null);
  220. var name = util.getArg(aArgs, 'name', null);
  221. this._validateMapping(generated, original, source, name);
  222. if (source && !this._sources.has(source)) {
  223. this._sources.add(source);
  224. }
  225. if (name && !this._names.has(name)) {
  226. this._names.add(name);
  227. }
  228. this._mappings.push({
  229. generatedLine: generated.line,
  230. generatedColumn: generated.column,
  231. originalLine: original != null && original.line,
  232. originalColumn: original != null && original.column,
  233. source: source,
  234. name: name
  235. });
  236. };
  237. /**
  238. * Set the source content for a source file.
  239. */
  240. SourceMapGenerator.prototype.setSourceContent =
  241. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  242. var source = aSourceFile;
  243. if (this._sourceRoot) {
  244. source = util.relative(this._sourceRoot, source);
  245. }
  246. if (aSourceContent !== null) {
  247. // Add the source content to the _sourcesContents map.
  248. // Create a new _sourcesContents map if the property is null.
  249. if (!this._sourcesContents) {
  250. this._sourcesContents = {};
  251. }
  252. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  253. } else {
  254. // Remove the source file from the _sourcesContents map.
  255. // If the _sourcesContents map is empty, set the property to null.
  256. delete this._sourcesContents[util.toSetString(source)];
  257. if (Object.keys(this._sourcesContents).length === 0) {
  258. this._sourcesContents = null;
  259. }
  260. }
  261. };
  262. /**
  263. * Applies the mappings of a sub-source-map for a specific source file to the
  264. * source map being generated. Each mapping to the supplied source file is
  265. * rewritten using the supplied source map. Note: The resolution for the
  266. * resulting mappings is the minimium of this map and the supplied map.
  267. *
  268. * @param aSourceMapConsumer The source map to be applied.
  269. * @param aSourceFile Optional. The filename of the source file.
  270. * If omitted, SourceMapConsumer's file property will be used.
  271. * @param aSourceMapPath Optional. The dirname of the path to the source map
  272. * to be applied. If relative, it is relative to the SourceMapConsumer.
  273. * This parameter is needed when the two source maps aren't in the same
  274. * directory, and the source map to be applied contains relative source
  275. * paths. If so, those relative source paths need to be rewritten
  276. * relative to the SourceMapGenerator.
  277. */
  278. SourceMapGenerator.prototype.applySourceMap =
  279. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
  280. // If aSourceFile is omitted, we will use the file property of the SourceMap
  281. if (!aSourceFile) {
  282. if (!aSourceMapConsumer.file) {
  283. throw new Error(
  284. 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
  285. 'or the source map\'s "file" property. Both were omitted.'
  286. );
  287. }
  288. aSourceFile = aSourceMapConsumer.file;
  289. }
  290. var sourceRoot = this._sourceRoot;
  291. // Make "aSourceFile" relative if an absolute Url is passed.
  292. if (sourceRoot) {
  293. aSourceFile = util.relative(sourceRoot, aSourceFile);
  294. }
  295. // Applying the SourceMap can add and remove items from the sources and
  296. // the names array.
  297. var newSources = new ArraySet();
  298. var newNames = new ArraySet();
  299. // Find mappings for the "aSourceFile"
  300. this._mappings.forEach(function (mapping) {
  301. if (mapping.source === aSourceFile && mapping.originalLine) {
  302. // Check if it can be mapped by the source map, then update the mapping.
  303. var original = aSourceMapConsumer.originalPositionFor({
  304. line: mapping.originalLine,
  305. column: mapping.originalColumn
  306. });
  307. if (original.source !== null) {
  308. // Copy mapping
  309. mapping.source = original.source;
  310. if (aSourceMapPath) {
  311. mapping.source = util.join(aSourceMapPath, mapping.source)
  312. }
  313. if (sourceRoot) {
  314. mapping.source = util.relative(sourceRoot, mapping.source);
  315. }
  316. mapping.originalLine = original.line;
  317. mapping.originalColumn = original.column;
  318. if (original.name !== null && mapping.name !== null) {
  319. // Only use the identifier name if it's an identifier
  320. // in both SourceMaps
  321. mapping.name = original.name;
  322. }
  323. }
  324. }
  325. var source = mapping.source;
  326. if (source && !newSources.has(source)) {
  327. newSources.add(source);
  328. }
  329. var name = mapping.name;
  330. if (name && !newNames.has(name)) {
  331. newNames.add(name);
  332. }
  333. }, this);
  334. this._sources = newSources;
  335. this._names = newNames;
  336. // Copy sourcesContents of applied map.
  337. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  338. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  339. if (content) {
  340. if (sourceRoot) {
  341. sourceFile = util.relative(sourceRoot, sourceFile);
  342. }
  343. this.setSourceContent(sourceFile, content);
  344. }
  345. }, this);
  346. };
  347. /**
  348. * A mapping can have one of the three levels of data:
  349. *
  350. * 1. Just the generated position.
  351. * 2. The Generated position, original position, and original source.
  352. * 3. Generated and original position, original source, as well as a name
  353. * token.
  354. *
  355. * To maintain consistency, we validate that any new mapping being added falls
  356. * in to one of these categories.
  357. */
  358. SourceMapGenerator.prototype._validateMapping =
  359. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  360. aName) {
  361. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  362. && aGenerated.line > 0 && aGenerated.column >= 0
  363. && !aOriginal && !aSource && !aName) {
  364. // Case 1.
  365. return;
  366. }
  367. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  368. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  369. && aGenerated.line > 0 && aGenerated.column >= 0
  370. && aOriginal.line > 0 && aOriginal.column >= 0
  371. && aSource) {
  372. // Cases 2 and 3.
  373. return;
  374. }
  375. else {
  376. throw new Error('Invalid mapping: ' + JSON.stringify({
  377. generated: aGenerated,
  378. source: aSource,
  379. original: aOriginal,
  380. name: aName
  381. }));
  382. }
  383. };
  384. /**
  385. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  386. * specified by the source map format.
  387. */
  388. SourceMapGenerator.prototype._serializeMappings =
  389. function SourceMapGenerator_serializeMappings() {
  390. var previousGeneratedColumn = 0;
  391. var previousGeneratedLine = 1;
  392. var previousOriginalColumn = 0;
  393. var previousOriginalLine = 0;
  394. var previousName = 0;
  395. var previousSource = 0;
  396. var result = '';
  397. var mapping;
  398. // The mappings must be guaranteed to be in sorted order before we start
  399. // serializing them or else the generated line numbers (which are defined
  400. // via the ';' separators) will be all messed up. Note: it might be more
  401. // performant to maintain the sorting as we insert them, rather than as we
  402. // serialize them, but the big O is the same either way.
  403. this._mappings.sort(util.compareByGeneratedPositions);
  404. for (var i = 0, len = this._mappings.length; i < len; i++) {
  405. mapping = this._mappings[i];
  406. if (mapping.generatedLine !== previousGeneratedLine) {
  407. previousGeneratedColumn = 0;
  408. while (mapping.generatedLine !== previousGeneratedLine) {
  409. result += ';';
  410. previousGeneratedLine++;
  411. }
  412. }
  413. else {
  414. if (i > 0) {
  415. if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
  416. continue;
  417. }
  418. result += ',';
  419. }
  420. }
  421. result += base64VLQ.encode(mapping.generatedColumn
  422. - previousGeneratedColumn);
  423. previousGeneratedColumn = mapping.generatedColumn;
  424. if (mapping.source) {
  425. result += base64VLQ.encode(this._sources.indexOf(mapping.source)
  426. - previousSource);
  427. previousSource = this._sources.indexOf(mapping.source);
  428. // lines are stored 0-based in SourceMap spec version 3
  429. result += base64VLQ.encode(mapping.originalLine - 1
  430. - previousOriginalLine);
  431. previousOriginalLine = mapping.originalLine - 1;
  432. result += base64VLQ.encode(mapping.originalColumn
  433. - previousOriginalColumn);
  434. previousOriginalColumn = mapping.originalColumn;
  435. if (mapping.name) {
  436. result += base64VLQ.encode(this._names.indexOf(mapping.name)
  437. - previousName);
  438. previousName = this._names.indexOf(mapping.name);
  439. }
  440. }
  441. }
  442. return result;
  443. };
  444. SourceMapGenerator.prototype._generateSourcesContent =
  445. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  446. return aSources.map(function (source) {
  447. if (!this._sourcesContents) {
  448. return null;
  449. }
  450. if (aSourceRoot) {
  451. source = util.relative(aSourceRoot, source);
  452. }
  453. var key = util.toSetString(source);
  454. return Object.prototype.hasOwnProperty.call(this._sourcesContents,
  455. key)
  456. ? this._sourcesContents[key]
  457. : null;
  458. }, this);
  459. };
  460. /**
  461. * Externalize the source map.
  462. */
  463. SourceMapGenerator.prototype.toJSON =
  464. function SourceMapGenerator_toJSON() {
  465. var map = {
  466. version: this._version,
  467. file: this._file,
  468. sources: this._sources.toArray(),
  469. names: this._names.toArray(),
  470. mappings: this._serializeMappings()
  471. };
  472. if (this._sourceRoot) {
  473. map.sourceRoot = this._sourceRoot;
  474. }
  475. if (this._sourcesContents) {
  476. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  477. }
  478. return map;
  479. };
  480. /**
  481. * Render the source map being generated to a string.
  482. */
  483. SourceMapGenerator.prototype.toString =
  484. function SourceMapGenerator_toString() {
  485. return JSON.stringify(this);
  486. };
  487. exports.SourceMapGenerator = SourceMapGenerator;
  488. });
  489. /* -*- Mode: js; js-indent-level: 2; -*- */
  490. /*
  491. * Copyright 2011 Mozilla Foundation and contributors
  492. * Licensed under the New BSD license. See LICENSE or:
  493. * http://opensource.org/licenses/BSD-3-Clause
  494. *
  495. * Based on the Base 64 VLQ implementation in Closure Compiler:
  496. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  497. *
  498. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  499. * Redistribution and use in source and binary forms, with or without
  500. * modification, are permitted provided that the following conditions are
  501. * met:
  502. *
  503. * * Redistributions of source code must retain the above copyright
  504. * notice, this list of conditions and the following disclaimer.
  505. * * Redistributions in binary form must reproduce the above
  506. * copyright notice, this list of conditions and the following
  507. * disclaimer in the documentation and/or other materials provided
  508. * with the distribution.
  509. * * Neither the name of Google Inc. nor the names of its
  510. * contributors may be used to endorse or promote products derived
  511. * from this software without specific prior written permission.
  512. *
  513. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  514. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  515. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  516. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  517. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  518. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  519. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  520. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  521. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  522. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  523. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  524. */
  525. define('source-map/base64-vlq', ['require', 'exports', 'module' , 'source-map/base64'], function(require, exports, module) {
  526. var base64 = require('./base64');
  527. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  528. // length quantities we use in the source map spec, the first bit is the sign,
  529. // the next four bits are the actual value, and the 6th bit is the
  530. // continuation bit. The continuation bit tells us whether there are more
  531. // digits in this value following this digit.
  532. //
  533. // Continuation
  534. // | Sign
  535. // | |
  536. // V V
  537. // 101011
  538. var VLQ_BASE_SHIFT = 5;
  539. // binary: 100000
  540. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  541. // binary: 011111
  542. var VLQ_BASE_MASK = VLQ_BASE - 1;
  543. // binary: 100000
  544. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  545. /**
  546. * Converts from a two-complement value to a value where the sign bit is
  547. * is placed in the least significant bit. For example, as decimals:
  548. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  549. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  550. */
  551. function toVLQSigned(aValue) {
  552. return aValue < 0
  553. ? ((-aValue) << 1) + 1
  554. : (aValue << 1) + 0;
  555. }
  556. /**
  557. * Converts to a two-complement value from a value where the sign bit is
  558. * is placed in the least significant bit. For example, as decimals:
  559. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  560. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  561. */
  562. function fromVLQSigned(aValue) {
  563. var isNegative = (aValue & 1) === 1;
  564. var shifted = aValue >> 1;
  565. return isNegative
  566. ? -shifted
  567. : shifted;
  568. }
  569. /**
  570. * Returns the base 64 VLQ encoded value.
  571. */
  572. exports.encode = function base64VLQ_encode(aValue) {
  573. var encoded = "";
  574. var digit;
  575. var vlq = toVLQSigned(aValue);
  576. do {
  577. digit = vlq & VLQ_BASE_MASK;
  578. vlq >>>= VLQ_BASE_SHIFT;
  579. if (vlq > 0) {
  580. // There are still more digits in this value, so we must make sure the
  581. // continuation bit is marked.
  582. digit |= VLQ_CONTINUATION_BIT;
  583. }
  584. encoded += base64.encode(digit);
  585. } while (vlq > 0);
  586. return encoded;
  587. };
  588. /**
  589. * Decodes the next base 64 VLQ value from the given string and returns the
  590. * value and the rest of the string.
  591. */
  592. exports.decode = function base64VLQ_decode(aStr) {
  593. var i = 0;
  594. var strLen = aStr.length;
  595. var result = 0;
  596. var shift = 0;
  597. var continuation, digit;
  598. do {
  599. if (i >= strLen) {
  600. throw new Error("Expected more digits in base 64 VLQ value.");
  601. }
  602. digit = base64.decode(aStr.charAt(i++));
  603. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  604. digit &= VLQ_BASE_MASK;
  605. result = result + (digit << shift);
  606. shift += VLQ_BASE_SHIFT;
  607. } while (continuation);
  608. return {
  609. value: fromVLQSigned(result),
  610. rest: aStr.slice(i)
  611. };
  612. };
  613. });
  614. /* -*- Mode: js; js-indent-level: 2; -*- */
  615. /*
  616. * Copyright 2011 Mozilla Foundation and contributors
  617. * Licensed under the New BSD license. See LICENSE or:
  618. * http://opensource.org/licenses/BSD-3-Clause
  619. */
  620. define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
  621. var charToIntMap = {};
  622. var intToCharMap = {};
  623. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  624. .split('')
  625. .forEach(function (ch, index) {
  626. charToIntMap[ch] = index;
  627. intToCharMap[index] = ch;
  628. });
  629. /**
  630. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  631. */
  632. exports.encode = function base64_encode(aNumber) {
  633. if (aNumber in intToCharMap) {
  634. return intToCharMap[aNumber];
  635. }
  636. throw new TypeError("Must be between 0 and 63: " + aNumber);
  637. };
  638. /**
  639. * Decode a single base 64 digit to an integer.
  640. */
  641. exports.decode = function base64_decode(aChar) {
  642. if (aChar in charToIntMap) {
  643. return charToIntMap[aChar];
  644. }
  645. throw new TypeError("Not a valid base 64 digit: " + aChar);
  646. };
  647. });
  648. /* -*- Mode: js; js-indent-level: 2; -*- */
  649. /*
  650. * Copyright 2011 Mozilla Foundation and contributors
  651. * Licensed under the New BSD license. See LICENSE or:
  652. * http://opensource.org/licenses/BSD-3-Clause
  653. */
  654. define('source-map/util', ['require', 'exports', 'module' , ], function(require, exports, module) {
  655. /**
  656. * This is a helper function for getting values from parameter/options
  657. * objects.
  658. *
  659. * @param args The object we are extracting values from
  660. * @param name The name of the property we are getting.
  661. * @param defaultValue An optional value to return if the property is missing
  662. * from the object. If this is not specified and the property is missing, an
  663. * error will be thrown.
  664. */
  665. function getArg(aArgs, aName, aDefaultValue) {
  666. if (aName in aArgs) {
  667. return aArgs[aName];
  668. } else if (arguments.length === 3) {
  669. return aDefaultValue;
  670. } else {
  671. throw new Error('"' + aName + '" is a required argument.');
  672. }
  673. }
  674. exports.getArg = getArg;
  675. var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/;
  676. var dataUrlRegexp = /^data:.+\,.+$/;
  677. function urlParse(aUrl) {
  678. var match = aUrl.match(urlRegexp);
  679. if (!match) {
  680. return null;
  681. }
  682. return {
  683. scheme: match[1],
  684. auth: match[2],
  685. host: match[3],
  686. port: match[4],
  687. path: match[5]
  688. };
  689. }
  690. exports.urlParse = urlParse;
  691. function urlGenerate(aParsedUrl) {
  692. var url = '';
  693. if (aParsedUrl.scheme) {
  694. url += aParsedUrl.scheme + ':';
  695. }
  696. url += '//';
  697. if (aParsedUrl.auth) {
  698. url += aParsedUrl.auth + '@';
  699. }
  700. if (aParsedUrl.host) {
  701. url += aParsedUrl.host;
  702. }
  703. if (aParsedUrl.port) {
  704. url += ":" + aParsedUrl.port
  705. }
  706. if (aParsedUrl.path) {
  707. url += aParsedUrl.path;
  708. }
  709. return url;
  710. }
  711. exports.urlGenerate = urlGenerate;
  712. /**
  713. * Normalizes a path, or the path portion of a URL:
  714. *
  715. * - Replaces consequtive slashes with one slash.
  716. * - Removes unnecessary '.' parts.
  717. * - Removes unnecessary '<dir>/..' parts.
  718. *
  719. * Based on code in the Node.js 'path' core module.
  720. *
  721. * @param aPath The path or url to normalize.
  722. */
  723. function normalize(aPath) {
  724. var path = aPath;
  725. var url = urlParse(aPath);
  726. if (url) {
  727. if (!url.path) {
  728. return aPath;
  729. }
  730. path = url.path;
  731. }
  732. var isAbsolute = (path.charAt(0) === '/');
  733. var parts = path.split(/\/+/);
  734. for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
  735. part = parts[i];
  736. if (part === '.') {
  737. parts.splice(i, 1);
  738. } else if (part === '..') {
  739. up++;
  740. } else if (up > 0) {
  741. if (part === '') {
  742. // The first part is blank if the path is absolute. Trying to go
  743. // above the root is a no-op. Therefore we can remove all '..' parts
  744. // directly after the root.
  745. parts.splice(i + 1, up);
  746. up = 0;
  747. } else {
  748. parts.splice(i, 2);
  749. up--;
  750. }
  751. }
  752. }
  753. path = parts.join('/');
  754. if (path === '') {
  755. path = isAbsolute ? '/' : '.';
  756. }
  757. if (url) {
  758. url.path = path;
  759. return urlGenerate(url);
  760. }
  761. return path;
  762. }
  763. exports.normalize = normalize;
  764. /**
  765. * Joins two paths/URLs.
  766. *
  767. * @param aRoot The root path or URL.
  768. * @param aPath The path or URL to be joined with the root.
  769. *
  770. * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
  771. * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
  772. * first.
  773. * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
  774. * is updated with the result and aRoot is returned. Otherwise the result
  775. * is returned.
  776. * - If aPath is absolute, the result is aPath.
  777. * - Otherwise the two paths are joined with a slash.
  778. * - Joining for example 'http://' and 'www.example.com' is also supported.
  779. */
  780. function join(aRoot, aPath) {
  781. var aPathUrl = urlParse(aPath);
  782. var aRootUrl = urlParse(aRoot);
  783. if (aRootUrl) {
  784. aRoot = aRootUrl.path || '/';
  785. }
  786. // `join(foo, '//www.example.org')`
  787. if (aPathUrl && !aPathUrl.scheme) {
  788. if (aRootUrl) {
  789. aPathUrl.scheme = aRootUrl.scheme;
  790. }
  791. return urlGenerate(aPathUrl);
  792. }
  793. if (aPathUrl || aPath.match(dataUrlRegexp)) {
  794. return aPath;
  795. }
  796. // `join('http://', 'www.example.com')`
  797. if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
  798. aRootUrl.host = aPath;
  799. return urlGenerate(aRootUrl);
  800. }
  801. var joined = aPath.charAt(0) === '/'
  802. ? aPath
  803. : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
  804. if (aRootUrl) {
  805. aRootUrl.path = joined;
  806. return urlGenerate(aRootUrl);
  807. }
  808. return joined;
  809. }
  810. exports.join = join;
  811. /**
  812. * Because behavior goes wacky when you set `__proto__` on objects, we
  813. * have to prefix all the strings in our set with an arbitrary character.
  814. *
  815. * See https://github.com/mozilla/source-map/pull/31 and
  816. * https://github.com/mozilla/source-map/issues/30
  817. *
  818. * @param String aStr
  819. */
  820. function toSetString(aStr) {
  821. return '$' + aStr;
  822. }
  823. exports.toSetString = toSetString;
  824. function fromSetString(aStr) {
  825. return aStr.substr(1);
  826. }
  827. exports.fromSetString = fromSetString;
  828. function relative(aRoot, aPath) {
  829. aRoot = aRoot.replace(/\/$/, '');
  830. var url = urlParse(aRoot);
  831. if (aPath.charAt(0) == "/" && url && url.path == "/") {
  832. return aPath.slice(1);
  833. }
  834. return aPath.indexOf(aRoot + '/') === 0
  835. ? aPath.substr(aRoot.length + 1)
  836. : aPath;
  837. }
  838. exports.relative = relative;
  839. function strcmp(aStr1, aStr2) {
  840. var s1 = aStr1 || "";
  841. var s2 = aStr2 || "";
  842. return (s1 > s2) - (s1 < s2);
  843. }
  844. /**
  845. * Comparator between two mappings where the original positions are compared.
  846. *
  847. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  848. * mappings with the same original source/line/column, but different generated
  849. * line and column the same. Useful when searching for a mapping with a
  850. * stubbed out mapping.
  851. */
  852. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  853. var cmp;
  854. cmp = strcmp(mappingA.source, mappingB.source);
  855. if (cmp) {
  856. return cmp;
  857. }
  858. cmp = mappingA.originalLine - mappingB.originalLine;
  859. if (cmp) {
  860. return cmp;
  861. }
  862. cmp = mappingA.originalColumn - mappingB.originalColumn;
  863. if (cmp || onlyCompareOriginal) {
  864. return cmp;
  865. }
  866. cmp = strcmp(mappingA.name, mappingB.name);
  867. if (cmp) {
  868. return cmp;
  869. }
  870. cmp = mappingA.generatedLine - mappingB.generatedLine;
  871. if (cmp) {
  872. return cmp;
  873. }
  874. return mappingA.generatedColumn - mappingB.generatedColumn;
  875. };
  876. exports.compareByOriginalPositions = compareByOriginalPositions;
  877. /**
  878. * Comparator between two mappings where the generated positions are
  879. * compared.
  880. *
  881. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  882. * mappings with the same generated line and column, but different
  883. * source/name/original line and column the same. Useful when searching for a
  884. * mapping with a stubbed out mapping.
  885. */
  886. function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
  887. var cmp;
  888. cmp = mappingA.generatedLine - mappingB.generatedLine;
  889. if (cmp) {
  890. return cmp;
  891. }
  892. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  893. if (cmp || onlyCompareGenerated) {
  894. return cmp;
  895. }
  896. cmp = strcmp(mappingA.source, mappingB.source);
  897. if (cmp) {
  898. return cmp;
  899. }
  900. cmp = mappingA.originalLine - mappingB.originalLine;
  901. if (cmp) {
  902. return cmp;
  903. }
  904. cmp = mappingA.originalColumn - mappingB.originalColumn;
  905. if (cmp) {
  906. return cmp;
  907. }
  908. return strcmp(mappingA.name, mappingB.name);
  909. };
  910. exports.compareByGeneratedPositions = compareByGeneratedPositions;
  911. });
  912. /* -*- Mode: js; js-indent-level: 2; -*- */
  913. /*
  914. * Copyright 2011 Mozilla Foundation and contributors
  915. * Licensed under the New BSD license. See LICENSE or:
  916. * http://opensource.org/licenses/BSD-3-Clause
  917. */
  918. define('source-map/array-set', ['require', 'exports', 'module' , 'source-map/util'], function(require, exports, module) {
  919. var util = require('./util');
  920. /**
  921. * A data structure which is a combination of an array and a set. Adding a new
  922. * member is O(1), testing for membership is O(1), and finding the index of an
  923. * element is O(1). Removing elements from the set is not supported. Only
  924. * strings are supported for membership.
  925. */
  926. function ArraySet() {
  927. this._array = [];
  928. this._set = {};
  929. }
  930. /**
  931. * Static method for creating ArraySet instances from an existing array.
  932. */
  933. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  934. var set = new ArraySet();
  935. for (var i = 0, len = aArray.length; i < len; i++) {
  936. set.add(aArray[i], aAllowDuplicates);
  937. }
  938. return set;
  939. };
  940. /**
  941. * Add the given string to this set.
  942. *
  943. * @param String aStr
  944. */
  945. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  946. var isDuplicate = this.has(aStr);
  947. var idx = this._array.length;
  948. if (!isDuplicate || aAllowDuplicates) {
  949. this._array.push(aStr);
  950. }
  951. if (!isDuplicate) {
  952. this._set[util.toSetString(aStr)] = idx;
  953. }
  954. };
  955. /**
  956. * Is the given string a member of this set?
  957. *
  958. * @param String aStr
  959. */
  960. ArraySet.prototype.has = function ArraySet_has(aStr) {
  961. return Object.prototype.hasOwnProperty.call(this._set,
  962. util.toSetString(aStr));
  963. };
  964. /**
  965. * What is the index of the given string in the array?
  966. *
  967. * @param String aStr
  968. */
  969. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  970. if (this.has(aStr)) {
  971. return this._set[util.toSetString(aStr)];
  972. }
  973. throw new Error('"' + aStr + '" is not in the set.');
  974. };
  975. /**
  976. * What is the element at the given index?
  977. *
  978. * @param Number aIdx
  979. */
  980. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  981. if (aIdx >= 0 && aIdx < this._array.length) {
  982. return this._array[aIdx];
  983. }
  984. throw new Error('No element indexed by ' + aIdx);
  985. };
  986. /**
  987. * Returns the array representation of this set (which has the proper indices
  988. * indicated by indexOf). Note that this is a copy of the internal array used
  989. * for storing the members so that no one can mess with internal state.
  990. */
  991. ArraySet.prototype.toArray = function ArraySet_toArray() {
  992. return this._array.slice();
  993. };
  994. exports.ArraySet = ArraySet;
  995. });
  996. /* -*- Mode: js; js-indent-level: 2; -*- */
  997. /*
  998. * Copyright 2011 Mozilla Foundation and contributors
  999. * Licensed under the New BSD license. See LICENSE or:
  1000. * http://opensource.org/licenses/BSD-3-Clause
  1001. */
  1002. define('source-map/source-map-consumer', ['require', 'exports', 'module' , 'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq'], function(require, exports, module) {
  1003. var util = require('./util');
  1004. var binarySearch = require('./binary-search');
  1005. var ArraySet = require('./array-set').ArraySet;
  1006. var base64VLQ = require('./base64-vlq');
  1007. /**
  1008. * A SourceMapConsumer instance represents a parsed source map which we can
  1009. * query for information about the original file positions by giving it a file
  1010. * position in the generated source.
  1011. *
  1012. * The only parameter is the raw source map (either as a JSON string, or
  1013. * already parsed to an object). According to the spec, source maps have the
  1014. * following attributes:
  1015. *
  1016. * - version: Which version of the source map spec this map is following.
  1017. * - sources: An array of URLs to the original source files.
  1018. * - names: An array of identifiers which can be referrenced by individual mappings.
  1019. * - sourceRoot: Optional. The URL root from which all sources are relative.
  1020. * - sourcesContent: Optional. An array of contents of the original source files.
  1021. * - mappings: A string of base64 VLQs which contain the actual mappings.
  1022. * - file: Optional. The generated file this source map is associated with.
  1023. *
  1024. * Here is an example source map, taken from the source map spec[0]:
  1025. *
  1026. * {
  1027. * version : 3,
  1028. * file: "out.js",
  1029. * sourceRoot : "",
  1030. * sources: ["foo.js", "bar.js"],
  1031. * names: ["src", "maps", "are", "fun"],
  1032. * mappings: "AA,AB;;ABCDE;"
  1033. * }
  1034. *
  1035. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  1036. */
  1037. function SourceMapConsumer(aSourceMap) {
  1038. var sourceMap = aSourceMap;
  1039. if (typeof aSourceMap === 'string') {
  1040. sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
  1041. }
  1042. var version = util.getArg(sourceMap, 'version');
  1043. var sources = util.getArg(sourceMap, 'sources');
  1044. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  1045. // requires the array) to play nice here.
  1046. var names = util.getArg(sourceMap, 'names', []);
  1047. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  1048. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  1049. var mappings = util.getArg(sourceMap, 'mappings');
  1050. var file = util.getArg(sourceMap, 'file', null);
  1051. // Once again, Sass deviates from the spec and supplies the version as a
  1052. // string rather than a number, so we use loose equality checking here.
  1053. if (version != this._version) {
  1054. throw new Error('Unsupported version: ' + version);
  1055. }
  1056. // Pass `true` below to allow duplicate names and sources. While source maps
  1057. // are intended to be compressed and deduplicated, the TypeScript compiler
  1058. // sometimes generates source maps with duplicates in them. See Github issue
  1059. // #72 and bugzil.la/889492.
  1060. this._names = ArraySet.fromArray(names, true);
  1061. this._sources = ArraySet.fromArray(sources, true);
  1062. this.sourceRoot = sourceRoot;
  1063. this.sourcesContent = sourcesContent;
  1064. this._mappings = mappings;
  1065. this.file = file;
  1066. }
  1067. /**
  1068. * Create a SourceMapConsumer from a SourceMapGenerator.
  1069. *
  1070. * @param SourceMapGenerator aSourceMap
  1071. * The source map that will be consumed.
  1072. * @returns SourceMapConsumer
  1073. */
  1074. SourceMapConsumer.fromSourceMap =
  1075. function SourceMapConsumer_fromSourceMap(aSourceMap) {
  1076. var smc = Object.create(SourceMapConsumer.prototype);
  1077. smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  1078. smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  1079. smc.sourceRoot = aSourceMap._sourceRoot;
  1080. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  1081. smc.sourceRoot);
  1082. smc.file = aSourceMap._file;
  1083. smc.__generatedMappings = aSourceMap._mappings.slice()
  1084. .sort(util.compareByGeneratedPositions);
  1085. smc.__originalMappings = aSourceMap._mappings.slice()
  1086. .sort(util.compareByOriginalPositions);
  1087. return smc;
  1088. };
  1089. /**
  1090. * The version of the source mapping spec that we are consuming.
  1091. */
  1092. SourceMapConsumer.prototype._version = 3;
  1093. /**
  1094. * The list of original sources.
  1095. */
  1096. Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
  1097. get: function () {
  1098. return this._sources.toArray().map(function (s) {
  1099. return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
  1100. }, this);
  1101. }
  1102. });
  1103. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  1104. // parsed mapping coordinates from the source map's "mappings" attribute. They
  1105. // are lazily instantiated, accessed via the `_generatedMappings` and
  1106. // `_originalMappings` getters respectively, and we only parse the mappings
  1107. // and create these arrays once queried for a source location. We jump through
  1108. // these hoops because there can be many thousands of mappings, and parsing
  1109. // them is expensive, so we only want to do it if we must.
  1110. //
  1111. // Each object in the arrays is of the form:
  1112. //
  1113. // {
  1114. // generatedLine: The line number in the generated code,
  1115. // generatedColumn: The column number in the generated code,
  1116. // source: The path to the original source file that generated this
  1117. // chunk of code,
  1118. // originalLine: The line number in the original source that
  1119. // corresponds to this chunk of generated code,
  1120. // originalColumn: The column number in the original source that
  1121. // corresponds to this chunk of generated code,
  1122. // name: The name of the original symbol which generated this chunk of
  1123. // code.
  1124. // }
  1125. //
  1126. // All properties except for `generatedLine` and `generatedColumn` can be
  1127. // `null`.
  1128. //
  1129. // `_generatedMappings` is ordered by the generated positions.
  1130. //
  1131. // `_originalMappings` is ordered by the original positions.
  1132. SourceMapConsumer.prototype.__generatedMappings = null;
  1133. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  1134. get: function () {
  1135. if (!this.__generatedMappings) {
  1136. this.__generatedMappings = [];
  1137. this.__originalMappings = [];
  1138. this._parseMappings(this._mappings, this.sourceRoot);
  1139. }
  1140. return this.__generatedMappings;
  1141. }
  1142. });
  1143. SourceMapConsumer.prototype.__originalMappings = null;
  1144. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  1145. get: function () {
  1146. if (!this.__originalMappings) {
  1147. this.__generatedMappings = [];
  1148. this.__originalMappings = [];
  1149. this._parseMappings(this._mappings, this.sourceRoot);
  1150. }
  1151. return this.__originalMappings;
  1152. }
  1153. });
  1154. /**
  1155. * Parse the mappings in a string in to a data structure which we can easily
  1156. * query (the ordered arrays in the `this.__generatedMappings` and
  1157. * `this.__originalMappings` properties).
  1158. */
  1159. SourceMapConsumer.prototype._parseMappings =
  1160. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  1161. var generatedLine = 1;
  1162. var previousGeneratedColumn = 0;
  1163. var previousOriginalLine = 0;
  1164. var previousOriginalColumn = 0;
  1165. var previousSource = 0;
  1166. var previousName = 0;
  1167. var mappingSeparator = /^[,;]/;
  1168. var str = aStr;
  1169. var mapping;
  1170. var temp;
  1171. while (str.length > 0) {
  1172. if (str.charAt(0) === ';') {
  1173. generatedLine++;
  1174. str = str.slice(1);
  1175. previousGeneratedColumn = 0;
  1176. }
  1177. else if (str.charAt(0) === ',') {
  1178. str = str.slice(1);
  1179. }
  1180. else {
  1181. mapping = {};
  1182. mapping.generatedLine = generatedLine;
  1183. // Generated column.
  1184. temp = base64VLQ.decode(str);
  1185. mapping.generatedColumn = previousGeneratedColumn + temp.value;
  1186. previousGeneratedColumn = mapping.generatedColumn;
  1187. str = temp.rest;
  1188. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  1189. // Original source.
  1190. temp = base64VLQ.decode(str);
  1191. mapping.source = this._sources.at(previousSource + temp.value);
  1192. previousSource += temp.value;
  1193. str = temp.rest;
  1194. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  1195. throw new Error('Found a source, but no line and column');
  1196. }
  1197. // Original line.
  1198. temp = base64VLQ.decode(str);
  1199. mapping.originalLine = previousOriginalLine + temp.value;
  1200. previousOriginalLine = mapping.originalLine;
  1201. // Lines are stored 0-based
  1202. mapping.originalLine += 1;
  1203. str = temp.rest;
  1204. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  1205. throw new Error('Found a source and line, but no column');
  1206. }
  1207. // Original column.
  1208. temp = base64VLQ.decode(str);
  1209. mapping.originalColumn = previousOriginalColumn + temp.value;
  1210. previousOriginalColumn = mapping.originalColumn;
  1211. str = temp.rest;
  1212. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  1213. // Original name.
  1214. temp = base64VLQ.decode(str);
  1215. mapping.name = this._names.at(previousName + temp.value);
  1216. previousName += temp.value;
  1217. str = temp.rest;
  1218. }
  1219. }
  1220. this.__generatedMappings.push(mapping);
  1221. if (typeof mapping.originalLine === 'number') {
  1222. this.__originalMappings.push(mapping);
  1223. }
  1224. }
  1225. }
  1226. this.__generatedMappings.sort(util.compareByGeneratedPositions);
  1227. this.__originalMappings.sort(util.compareByOriginalPositions);
  1228. };
  1229. /**
  1230. * Find the mapping that best matches the hypothetical "needle" mapping that
  1231. * we are searching for in the given "haystack" of mappings.
  1232. */
  1233. SourceMapConsumer.prototype._findMapping =
  1234. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  1235. aColumnName, aComparator) {
  1236. // To return the position we are searching for, we must first find the
  1237. // mapping for the given position and then return the opposite position it
  1238. // points to. Because the mappings are sorted, we can use binary search to
  1239. // find the best mapping.
  1240. if (aNeedle[aLineName] <= 0) {
  1241. throw new TypeError('Line must be greater than or equal to 1, got '
  1242. + aNeedle[aLineName]);
  1243. }
  1244. if (aNeedle[aColumnName] < 0) {
  1245. throw new TypeError('Column must be greater than or equal to 0, got '
  1246. + aNeedle[aColumnName]);
  1247. }
  1248. return binarySearch.search(aNeedle, aMappings, aComparator);
  1249. };
  1250. /**
  1251. * Returns the original source, line, and column information for the generated
  1252. * source's line and column positions provided. The only argument is an object
  1253. * with the following properties:
  1254. *
  1255. * - line: The line number in the generated source.
  1256. * - column: The column number in the generated source.
  1257. *
  1258. * and an object is returned with the following properties:
  1259. *
  1260. * - source: The original source file, or null.
  1261. * - line: The line number in the original source, or null.
  1262. * - column: The column number in the original source, or null.
  1263. * - name: The original identifier, or null.
  1264. */
  1265. SourceMapConsumer.prototype.originalPositionFor =
  1266. function SourceMapConsumer_originalPositionFor(aArgs) {
  1267. var needle = {
  1268. generatedLine: util.getArg(aArgs, 'line'),
  1269. generatedColumn: util.getArg(aArgs, 'column')
  1270. };
  1271. var mapping = this._findMapping(needle,
  1272. this._generatedMappings,
  1273. "generatedLine",
  1274. "generatedColumn",
  1275. util.compareByGeneratedPositions);
  1276. if (mapping && mapping.generatedLine === needle.generatedLine) {
  1277. var source = util.getArg(mapping, 'source', null);
  1278. if (source && this.sourceRoot) {
  1279. source = util.join(this.sourceRoot, source);
  1280. }
  1281. return {
  1282. source: source,
  1283. line: util.getArg(mapping, 'originalLine', null),
  1284. column: util.getArg(mapping, 'originalColumn', null),
  1285. name: util.getArg(mapping, 'name', null)
  1286. };
  1287. }
  1288. return {
  1289. source: null,
  1290. line: null,
  1291. column: null,
  1292. name: null
  1293. };
  1294. };
  1295. /**
  1296. * Returns the original source content. The only argument is the url of the
  1297. * original source file. Returns null if no original source content is
  1298. * availible.
  1299. */
  1300. SourceMapConsumer.prototype.sourceContentFor =
  1301. function SourceMapConsumer_sourceContentFor(aSource) {
  1302. if (!this.sourcesContent) {
  1303. return null;
  1304. }
  1305. if (this.sourceRoot) {
  1306. aSource = util.relative(this.sourceRoot, aSource);
  1307. }
  1308. if (this._sources.has(aSource)) {
  1309. return this.sourcesContent[this._sources.indexOf(aSource)];
  1310. }
  1311. var url;
  1312. if (this.sourceRoot
  1313. && (url = util.urlParse(this.sourceRoot))) {
  1314. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  1315. // many users. We can help them out when they expect file:// URIs to
  1316. // behave like it would if they were running a local HTTP server. See
  1317. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  1318. var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
  1319. if (url.scheme == "file"
  1320. && this._sources.has(fileUriAbsPath)) {
  1321. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  1322. }
  1323. if ((!url.path || url.path == "/")
  1324. && this._sources.has("/" + aSource)) {
  1325. return this.sourcesContent[this._sources.indexOf("/" + aSource)];
  1326. }
  1327. }
  1328. throw new Error('"' + aSource + '" is not in the SourceMap.');
  1329. };
  1330. /**
  1331. * Returns the generated line and column information for the original source,
  1332. * line, and column positions provided. The only argument is an object with
  1333. * the following properties:
  1334. *
  1335. * - source: The filename of the original source.
  1336. * - line: The line number in the original source.
  1337. * - column: The column number in the original source.
  1338. *
  1339. * and an object is returned with the following properties:
  1340. *
  1341. * - line: The line number in the generated source, or null.
  1342. * - co…

Large files files are truncated, but you can click here to view the full file