source-map-0.1.31.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933
  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. To create a new one, you must pass an object
  146. * with the following properties:
  147. *
  148. * - file: The filename of the generated source.
  149. * - sourceRoot: An optional root for all URLs in this source map.
  150. */
  151. function SourceMapGenerator(aArgs) {
  152. this._file = util.getArg(aArgs, 'file');
  153. this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  154. this._sources = new ArraySet();
  155. this._names = new ArraySet();
  156. this._mappings = [];
  157. this._sourcesContents = null;
  158. }
  159. SourceMapGenerator.prototype._version = 3;
  160. /**
  161. * Creates a new SourceMapGenerator based on a SourceMapConsumer
  162. *
  163. * @param aSourceMapConsumer The SourceMap.
  164. */
  165. SourceMapGenerator.fromSourceMap =
  166. function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  167. var sourceRoot = aSourceMapConsumer.sourceRoot;
  168. var generator = new SourceMapGenerator({
  169. file: aSourceMapConsumer.file,
  170. sourceRoot: sourceRoot
  171. });
  172. aSourceMapConsumer.eachMapping(function (mapping) {
  173. var newMapping = {
  174. generated: {
  175. line: mapping.generatedLine,
  176. column: mapping.generatedColumn
  177. }
  178. };
  179. if (mapping.source) {
  180. newMapping.source = mapping.source;
  181. if (sourceRoot) {
  182. newMapping.source = util.relative(sourceRoot, newMapping.source);
  183. }
  184. newMapping.original = {
  185. line: mapping.originalLine,
  186. column: mapping.originalColumn
  187. };
  188. if (mapping.name) {
  189. newMapping.name = mapping.name;
  190. }
  191. }
  192. generator.addMapping(newMapping);
  193. });
  194. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  195. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  196. if (content) {
  197. generator.setSourceContent(sourceFile, content);
  198. }
  199. });
  200. return generator;
  201. };
  202. /**
  203. * Add a single mapping from original source line and column to the generated
  204. * source's line and column for this source map being created. The mapping
  205. * object should have the following properties:
  206. *
  207. * - generated: An object with the generated line and column positions.
  208. * - original: An object with the original line and column positions.
  209. * - source: The original source file (relative to the sourceRoot).
  210. * - name: An optional original token name for this mapping.
  211. */
  212. SourceMapGenerator.prototype.addMapping =
  213. function SourceMapGenerator_addMapping(aArgs) {
  214. var generated = util.getArg(aArgs, 'generated');
  215. var original = util.getArg(aArgs, 'original', null);
  216. var source = util.getArg(aArgs, 'source', null);
  217. var name = util.getArg(aArgs, 'name', null);
  218. this._validateMapping(generated, original, source, name);
  219. if (source && !this._sources.has(source)) {
  220. this._sources.add(source);
  221. }
  222. if (name && !this._names.has(name)) {
  223. this._names.add(name);
  224. }
  225. this._mappings.push({
  226. generatedLine: generated.line,
  227. generatedColumn: generated.column,
  228. originalLine: original != null && original.line,
  229. originalColumn: original != null && original.column,
  230. source: source,
  231. name: name
  232. });
  233. };
  234. /**
  235. * Set the source content for a source file.
  236. */
  237. SourceMapGenerator.prototype.setSourceContent =
  238. function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  239. var source = aSourceFile;
  240. if (this._sourceRoot) {
  241. source = util.relative(this._sourceRoot, source);
  242. }
  243. if (aSourceContent !== null) {
  244. // Add the source content to the _sourcesContents map.
  245. // Create a new _sourcesContents map if the property is null.
  246. if (!this._sourcesContents) {
  247. this._sourcesContents = {};
  248. }
  249. this._sourcesContents[util.toSetString(source)] = aSourceContent;
  250. } else {
  251. // Remove the source file from the _sourcesContents map.
  252. // If the _sourcesContents map is empty, set the property to null.
  253. delete this._sourcesContents[util.toSetString(source)];
  254. if (Object.keys(this._sourcesContents).length === 0) {
  255. this._sourcesContents = null;
  256. }
  257. }
  258. };
  259. /**
  260. * Applies the mappings of a sub-source-map for a specific source file to the
  261. * source map being generated. Each mapping to the supplied source file is
  262. * rewritten using the supplied source map. Note: The resolution for the
  263. * resulting mappings is the minimium of this map and the supplied map.
  264. *
  265. * @param aSourceMapConsumer The source map to be applied.
  266. * @param aSourceFile Optional. The filename of the source file.
  267. * If omitted, SourceMapConsumer's file property will be used.
  268. */
  269. SourceMapGenerator.prototype.applySourceMap =
  270. function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
  271. // If aSourceFile is omitted, we will use the file property of the SourceMap
  272. if (!aSourceFile) {
  273. aSourceFile = aSourceMapConsumer.file;
  274. }
  275. var sourceRoot = this._sourceRoot;
  276. // Make "aSourceFile" relative if an absolute Url is passed.
  277. if (sourceRoot) {
  278. aSourceFile = util.relative(sourceRoot, aSourceFile);
  279. }
  280. // Applying the SourceMap can add and remove items from the sources and
  281. // the names array.
  282. var newSources = new ArraySet();
  283. var newNames = new ArraySet();
  284. // Find mappings for the "aSourceFile"
  285. this._mappings.forEach(function (mapping) {
  286. if (mapping.source === aSourceFile && mapping.originalLine) {
  287. // Check if it can be mapped by the source map, then update the mapping.
  288. var original = aSourceMapConsumer.originalPositionFor({
  289. line: mapping.originalLine,
  290. column: mapping.originalColumn
  291. });
  292. if (original.source !== null) {
  293. // Copy mapping
  294. if (sourceRoot) {
  295. mapping.source = util.relative(sourceRoot, original.source);
  296. } else {
  297. mapping.source = original.source;
  298. }
  299. mapping.originalLine = original.line;
  300. mapping.originalColumn = original.column;
  301. if (original.name !== null && mapping.name !== null) {
  302. // Only use the identifier name if it's an identifier
  303. // in both SourceMaps
  304. mapping.name = original.name;
  305. }
  306. }
  307. }
  308. var source = mapping.source;
  309. if (source && !newSources.has(source)) {
  310. newSources.add(source);
  311. }
  312. var name = mapping.name;
  313. if (name && !newNames.has(name)) {
  314. newNames.add(name);
  315. }
  316. }, this);
  317. this._sources = newSources;
  318. this._names = newNames;
  319. // Copy sourcesContents of applied map.
  320. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  321. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  322. if (content) {
  323. if (sourceRoot) {
  324. sourceFile = util.relative(sourceRoot, sourceFile);
  325. }
  326. this.setSourceContent(sourceFile, content);
  327. }
  328. }, this);
  329. };
  330. /**
  331. * A mapping can have one of the three levels of data:
  332. *
  333. * 1. Just the generated position.
  334. * 2. The Generated position, original position, and original source.
  335. * 3. Generated and original position, original source, as well as a name
  336. * token.
  337. *
  338. * To maintain consistency, we validate that any new mapping being added falls
  339. * in to one of these categories.
  340. */
  341. SourceMapGenerator.prototype._validateMapping =
  342. function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  343. aName) {
  344. if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  345. && aGenerated.line > 0 && aGenerated.column >= 0
  346. && !aOriginal && !aSource && !aName) {
  347. // Case 1.
  348. return;
  349. }
  350. else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  351. && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  352. && aGenerated.line > 0 && aGenerated.column >= 0
  353. && aOriginal.line > 0 && aOriginal.column >= 0
  354. && aSource) {
  355. // Cases 2 and 3.
  356. return;
  357. }
  358. else {
  359. throw new Error('Invalid mapping: ' + JSON.stringify({
  360. generated: aGenerated,
  361. source: aSource,
  362. original: aOriginal,
  363. name: aName
  364. }));
  365. }
  366. };
  367. /**
  368. * Serialize the accumulated mappings in to the stream of base 64 VLQs
  369. * specified by the source map format.
  370. */
  371. SourceMapGenerator.prototype._serializeMappings =
  372. function SourceMapGenerator_serializeMappings() {
  373. var previousGeneratedColumn = 0;
  374. var previousGeneratedLine = 1;
  375. var previousOriginalColumn = 0;
  376. var previousOriginalLine = 0;
  377. var previousName = 0;
  378. var previousSource = 0;
  379. var result = '';
  380. var mapping;
  381. // The mappings must be guaranteed to be in sorted order before we start
  382. // serializing them or else the generated line numbers (which are defined
  383. // via the ';' separators) will be all messed up. Note: it might be more
  384. // performant to maintain the sorting as we insert them, rather than as we
  385. // serialize them, but the big O is the same either way.
  386. this._mappings.sort(util.compareByGeneratedPositions);
  387. for (var i = 0, len = this._mappings.length; i < len; i++) {
  388. mapping = this._mappings[i];
  389. if (mapping.generatedLine !== previousGeneratedLine) {
  390. previousGeneratedColumn = 0;
  391. while (mapping.generatedLine !== previousGeneratedLine) {
  392. result += ';';
  393. previousGeneratedLine++;
  394. }
  395. }
  396. else {
  397. if (i > 0) {
  398. if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
  399. continue;
  400. }
  401. result += ',';
  402. }
  403. }
  404. result += base64VLQ.encode(mapping.generatedColumn
  405. - previousGeneratedColumn);
  406. previousGeneratedColumn = mapping.generatedColumn;
  407. if (mapping.source) {
  408. result += base64VLQ.encode(this._sources.indexOf(mapping.source)
  409. - previousSource);
  410. previousSource = this._sources.indexOf(mapping.source);
  411. // lines are stored 0-based in SourceMap spec version 3
  412. result += base64VLQ.encode(mapping.originalLine - 1
  413. - previousOriginalLine);
  414. previousOriginalLine = mapping.originalLine - 1;
  415. result += base64VLQ.encode(mapping.originalColumn
  416. - previousOriginalColumn);
  417. previousOriginalColumn = mapping.originalColumn;
  418. if (mapping.name) {
  419. result += base64VLQ.encode(this._names.indexOf(mapping.name)
  420. - previousName);
  421. previousName = this._names.indexOf(mapping.name);
  422. }
  423. }
  424. }
  425. return result;
  426. };
  427. SourceMapGenerator.prototype._generateSourcesContent =
  428. function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  429. return aSources.map(function (source) {
  430. if (!this._sourcesContents) {
  431. return null;
  432. }
  433. if (aSourceRoot) {
  434. source = util.relative(aSourceRoot, source);
  435. }
  436. var key = util.toSetString(source);
  437. return Object.prototype.hasOwnProperty.call(this._sourcesContents,
  438. key)
  439. ? this._sourcesContents[key]
  440. : null;
  441. }, this);
  442. };
  443. /**
  444. * Externalize the source map.
  445. */
  446. SourceMapGenerator.prototype.toJSON =
  447. function SourceMapGenerator_toJSON() {
  448. var map = {
  449. version: this._version,
  450. file: this._file,
  451. sources: this._sources.toArray(),
  452. names: this._names.toArray(),
  453. mappings: this._serializeMappings()
  454. };
  455. if (this._sourceRoot) {
  456. map.sourceRoot = this._sourceRoot;
  457. }
  458. if (this._sourcesContents) {
  459. map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  460. }
  461. return map;
  462. };
  463. /**
  464. * Render the source map being generated to a string.
  465. */
  466. SourceMapGenerator.prototype.toString =
  467. function SourceMapGenerator_toString() {
  468. return JSON.stringify(this);
  469. };
  470. exports.SourceMapGenerator = SourceMapGenerator;
  471. });
  472. /* -*- Mode: js; js-indent-level: 2; -*- */
  473. /*
  474. * Copyright 2011 Mozilla Foundation and contributors
  475. * Licensed under the New BSD license. See LICENSE or:
  476. * http://opensource.org/licenses/BSD-3-Clause
  477. *
  478. * Based on the Base 64 VLQ implementation in Closure Compiler:
  479. * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
  480. *
  481. * Copyright 2011 The Closure Compiler Authors. All rights reserved.
  482. * Redistribution and use in source and binary forms, with or without
  483. * modification, are permitted provided that the following conditions are
  484. * met:
  485. *
  486. * * Redistributions of source code must retain the above copyright
  487. * notice, this list of conditions and the following disclaimer.
  488. * * Redistributions in binary form must reproduce the above
  489. * copyright notice, this list of conditions and the following
  490. * disclaimer in the documentation and/or other materials provided
  491. * with the distribution.
  492. * * Neither the name of Google Inc. nor the names of its
  493. * contributors may be used to endorse or promote products derived
  494. * from this software without specific prior written permission.
  495. *
  496. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  497. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  498. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  499. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  500. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  501. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  502. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  503. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  504. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  505. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  506. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  507. */
  508. define('source-map/base64-vlq', ['require', 'exports', 'module' , 'source-map/base64'], function(require, exports, module) {
  509. var base64 = require('./base64');
  510. // A single base 64 digit can contain 6 bits of data. For the base 64 variable
  511. // length quantities we use in the source map spec, the first bit is the sign,
  512. // the next four bits are the actual value, and the 6th bit is the
  513. // continuation bit. The continuation bit tells us whether there are more
  514. // digits in this value following this digit.
  515. //
  516. // Continuation
  517. // | Sign
  518. // | |
  519. // V V
  520. // 101011
  521. var VLQ_BASE_SHIFT = 5;
  522. // binary: 100000
  523. var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
  524. // binary: 011111
  525. var VLQ_BASE_MASK = VLQ_BASE - 1;
  526. // binary: 100000
  527. var VLQ_CONTINUATION_BIT = VLQ_BASE;
  528. /**
  529. * Converts from a two-complement value to a value where the sign bit is
  530. * is placed in the least significant bit. For example, as decimals:
  531. * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
  532. * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
  533. */
  534. function toVLQSigned(aValue) {
  535. return aValue < 0
  536. ? ((-aValue) << 1) + 1
  537. : (aValue << 1) + 0;
  538. }
  539. /**
  540. * Converts to a two-complement value from a value where the sign bit is
  541. * is placed in the least significant bit. For example, as decimals:
  542. * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
  543. * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
  544. */
  545. function fromVLQSigned(aValue) {
  546. var isNegative = (aValue & 1) === 1;
  547. var shifted = aValue >> 1;
  548. return isNegative
  549. ? -shifted
  550. : shifted;
  551. }
  552. /**
  553. * Returns the base 64 VLQ encoded value.
  554. */
  555. exports.encode = function base64VLQ_encode(aValue) {
  556. var encoded = "";
  557. var digit;
  558. var vlq = toVLQSigned(aValue);
  559. do {
  560. digit = vlq & VLQ_BASE_MASK;
  561. vlq >>>= VLQ_BASE_SHIFT;
  562. if (vlq > 0) {
  563. // There are still more digits in this value, so we must make sure the
  564. // continuation bit is marked.
  565. digit |= VLQ_CONTINUATION_BIT;
  566. }
  567. encoded += base64.encode(digit);
  568. } while (vlq > 0);
  569. return encoded;
  570. };
  571. /**
  572. * Decodes the next base 64 VLQ value from the given string and returns the
  573. * value and the rest of the string.
  574. */
  575. exports.decode = function base64VLQ_decode(aStr) {
  576. var i = 0;
  577. var strLen = aStr.length;
  578. var result = 0;
  579. var shift = 0;
  580. var continuation, digit;
  581. do {
  582. if (i >= strLen) {
  583. throw new Error("Expected more digits in base 64 VLQ value.");
  584. }
  585. digit = base64.decode(aStr.charAt(i++));
  586. continuation = !!(digit & VLQ_CONTINUATION_BIT);
  587. digit &= VLQ_BASE_MASK;
  588. result = result + (digit << shift);
  589. shift += VLQ_BASE_SHIFT;
  590. } while (continuation);
  591. return {
  592. value: fromVLQSigned(result),
  593. rest: aStr.slice(i)
  594. };
  595. };
  596. });
  597. /* -*- Mode: js; js-indent-level: 2; -*- */
  598. /*
  599. * Copyright 2011 Mozilla Foundation and contributors
  600. * Licensed under the New BSD license. See LICENSE or:
  601. * http://opensource.org/licenses/BSD-3-Clause
  602. */
  603. define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
  604. var charToIntMap = {};
  605. var intToCharMap = {};
  606. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  607. .split('')
  608. .forEach(function (ch, index) {
  609. charToIntMap[ch] = index;
  610. intToCharMap[index] = ch;
  611. });
  612. /**
  613. * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  614. */
  615. exports.encode = function base64_encode(aNumber) {
  616. if (aNumber in intToCharMap) {
  617. return intToCharMap[aNumber];
  618. }
  619. throw new TypeError("Must be between 0 and 63: " + aNumber);
  620. };
  621. /**
  622. * Decode a single base 64 digit to an integer.
  623. */
  624. exports.decode = function base64_decode(aChar) {
  625. if (aChar in charToIntMap) {
  626. return charToIntMap[aChar];
  627. }
  628. throw new TypeError("Not a valid base 64 digit: " + aChar);
  629. };
  630. });
  631. /* -*- Mode: js; js-indent-level: 2; -*- */
  632. /*
  633. * Copyright 2011 Mozilla Foundation and contributors
  634. * Licensed under the New BSD license. See LICENSE or:
  635. * http://opensource.org/licenses/BSD-3-Clause
  636. */
  637. define('source-map/util', ['require', 'exports', 'module' , ], function(require, exports, module) {
  638. /**
  639. * This is a helper function for getting values from parameter/options
  640. * objects.
  641. *
  642. * @param args The object we are extracting values from
  643. * @param name The name of the property we are getting.
  644. * @param defaultValue An optional value to return if the property is missing
  645. * from the object. If this is not specified and the property is missing, an
  646. * error will be thrown.
  647. */
  648. function getArg(aArgs, aName, aDefaultValue) {
  649. if (aName in aArgs) {
  650. return aArgs[aName];
  651. } else if (arguments.length === 3) {
  652. return aDefaultValue;
  653. } else {
  654. throw new Error('"' + aName + '" is a required argument.');
  655. }
  656. }
  657. exports.getArg = getArg;
  658. var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
  659. var dataUrlRegexp = /^data:.+\,.+/;
  660. function urlParse(aUrl) {
  661. var match = aUrl.match(urlRegexp);
  662. if (!match) {
  663. return null;
  664. }
  665. return {
  666. scheme: match[1],
  667. auth: match[3],
  668. host: match[4],
  669. port: match[6],
  670. path: match[7]
  671. };
  672. }
  673. exports.urlParse = urlParse;
  674. function urlGenerate(aParsedUrl) {
  675. var url = aParsedUrl.scheme + "://";
  676. if (aParsedUrl.auth) {
  677. url += aParsedUrl.auth + "@"
  678. }
  679. if (aParsedUrl.host) {
  680. url += aParsedUrl.host;
  681. }
  682. if (aParsedUrl.port) {
  683. url += ":" + aParsedUrl.port
  684. }
  685. if (aParsedUrl.path) {
  686. url += aParsedUrl.path;
  687. }
  688. return url;
  689. }
  690. exports.urlGenerate = urlGenerate;
  691. function join(aRoot, aPath) {
  692. var url;
  693. if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
  694. return aPath;
  695. }
  696. if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
  697. url.path = aPath;
  698. return urlGenerate(url);
  699. }
  700. return aRoot.replace(/\/$/, '') + '/' + aPath;
  701. }
  702. exports.join = join;
  703. /**
  704. * Because behavior goes wacky when you set `__proto__` on objects, we
  705. * have to prefix all the strings in our set with an arbitrary character.
  706. *
  707. * See https://github.com/mozilla/source-map/pull/31 and
  708. * https://github.com/mozilla/source-map/issues/30
  709. *
  710. * @param String aStr
  711. */
  712. function toSetString(aStr) {
  713. return '$' + aStr;
  714. }
  715. exports.toSetString = toSetString;
  716. function fromSetString(aStr) {
  717. return aStr.substr(1);
  718. }
  719. exports.fromSetString = fromSetString;
  720. function relative(aRoot, aPath) {
  721. aRoot = aRoot.replace(/\/$/, '');
  722. var url = urlParse(aRoot);
  723. if (aPath.charAt(0) == "/" && url && url.path == "/") {
  724. return aPath.slice(1);
  725. }
  726. return aPath.indexOf(aRoot + '/') === 0
  727. ? aPath.substr(aRoot.length + 1)
  728. : aPath;
  729. }
  730. exports.relative = relative;
  731. function strcmp(aStr1, aStr2) {
  732. var s1 = aStr1 || "";
  733. var s2 = aStr2 || "";
  734. return (s1 > s2) - (s1 < s2);
  735. }
  736. /**
  737. * Comparator between two mappings where the original positions are compared.
  738. *
  739. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  740. * mappings with the same original source/line/column, but different generated
  741. * line and column the same. Useful when searching for a mapping with a
  742. * stubbed out mapping.
  743. */
  744. function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
  745. var cmp;
  746. cmp = strcmp(mappingA.source, mappingB.source);
  747. if (cmp) {
  748. return cmp;
  749. }
  750. cmp = mappingA.originalLine - mappingB.originalLine;
  751. if (cmp) {
  752. return cmp;
  753. }
  754. cmp = mappingA.originalColumn - mappingB.originalColumn;
  755. if (cmp || onlyCompareOriginal) {
  756. return cmp;
  757. }
  758. cmp = strcmp(mappingA.name, mappingB.name);
  759. if (cmp) {
  760. return cmp;
  761. }
  762. cmp = mappingA.generatedLine - mappingB.generatedLine;
  763. if (cmp) {
  764. return cmp;
  765. }
  766. return mappingA.generatedColumn - mappingB.generatedColumn;
  767. };
  768. exports.compareByOriginalPositions = compareByOriginalPositions;
  769. /**
  770. * Comparator between two mappings where the generated positions are
  771. * compared.
  772. *
  773. * Optionally pass in `true` as `onlyCompareGenerated` to consider two
  774. * mappings with the same generated line and column, but different
  775. * source/name/original line and column the same. Useful when searching for a
  776. * mapping with a stubbed out mapping.
  777. */
  778. function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
  779. var cmp;
  780. cmp = mappingA.generatedLine - mappingB.generatedLine;
  781. if (cmp) {
  782. return cmp;
  783. }
  784. cmp = mappingA.generatedColumn - mappingB.generatedColumn;
  785. if (cmp || onlyCompareGenerated) {
  786. return cmp;
  787. }
  788. cmp = strcmp(mappingA.source, mappingB.source);
  789. if (cmp) {
  790. return cmp;
  791. }
  792. cmp = mappingA.originalLine - mappingB.originalLine;
  793. if (cmp) {
  794. return cmp;
  795. }
  796. cmp = mappingA.originalColumn - mappingB.originalColumn;
  797. if (cmp) {
  798. return cmp;
  799. }
  800. return strcmp(mappingA.name, mappingB.name);
  801. };
  802. exports.compareByGeneratedPositions = compareByGeneratedPositions;
  803. });
  804. /* -*- Mode: js; js-indent-level: 2; -*- */
  805. /*
  806. * Copyright 2011 Mozilla Foundation and contributors
  807. * Licensed under the New BSD license. See LICENSE or:
  808. * http://opensource.org/licenses/BSD-3-Clause
  809. */
  810. define('source-map/array-set', ['require', 'exports', 'module' , 'source-map/util'], function(require, exports, module) {
  811. var util = require('./util');
  812. /**
  813. * A data structure which is a combination of an array and a set. Adding a new
  814. * member is O(1), testing for membership is O(1), and finding the index of an
  815. * element is O(1). Removing elements from the set is not supported. Only
  816. * strings are supported for membership.
  817. */
  818. function ArraySet() {
  819. this._array = [];
  820. this._set = {};
  821. }
  822. /**
  823. * Static method for creating ArraySet instances from an existing array.
  824. */
  825. ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
  826. var set = new ArraySet();
  827. for (var i = 0, len = aArray.length; i < len; i++) {
  828. set.add(aArray[i], aAllowDuplicates);
  829. }
  830. return set;
  831. };
  832. /**
  833. * Add the given string to this set.
  834. *
  835. * @param String aStr
  836. */
  837. ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
  838. var isDuplicate = this.has(aStr);
  839. var idx = this._array.length;
  840. if (!isDuplicate || aAllowDuplicates) {
  841. this._array.push(aStr);
  842. }
  843. if (!isDuplicate) {
  844. this._set[util.toSetString(aStr)] = idx;
  845. }
  846. };
  847. /**
  848. * Is the given string a member of this set?
  849. *
  850. * @param String aStr
  851. */
  852. ArraySet.prototype.has = function ArraySet_has(aStr) {
  853. return Object.prototype.hasOwnProperty.call(this._set,
  854. util.toSetString(aStr));
  855. };
  856. /**
  857. * What is the index of the given string in the array?
  858. *
  859. * @param String aStr
  860. */
  861. ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
  862. if (this.has(aStr)) {
  863. return this._set[util.toSetString(aStr)];
  864. }
  865. throw new Error('"' + aStr + '" is not in the set.');
  866. };
  867. /**
  868. * What is the element at the given index?
  869. *
  870. * @param Number aIdx
  871. */
  872. ArraySet.prototype.at = function ArraySet_at(aIdx) {
  873. if (aIdx >= 0 && aIdx < this._array.length) {
  874. return this._array[aIdx];
  875. }
  876. throw new Error('No element indexed by ' + aIdx);
  877. };
  878. /**
  879. * Returns the array representation of this set (which has the proper indices
  880. * indicated by indexOf). Note that this is a copy of the internal array used
  881. * for storing the members so that no one can mess with internal state.
  882. */
  883. ArraySet.prototype.toArray = function ArraySet_toArray() {
  884. return this._array.slice();
  885. };
  886. exports.ArraySet = ArraySet;
  887. });
  888. /* -*- Mode: js; js-indent-level: 2; -*- */
  889. /*
  890. * Copyright 2011 Mozilla Foundation and contributors
  891. * Licensed under the New BSD license. See LICENSE or:
  892. * http://opensource.org/licenses/BSD-3-Clause
  893. */
  894. 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) {
  895. var util = require('./util');
  896. var binarySearch = require('./binary-search');
  897. var ArraySet = require('./array-set').ArraySet;
  898. var base64VLQ = require('./base64-vlq');
  899. /**
  900. * A SourceMapConsumer instance represents a parsed source map which we can
  901. * query for information about the original file positions by giving it a file
  902. * position in the generated source.
  903. *
  904. * The only parameter is the raw source map (either as a JSON string, or
  905. * already parsed to an object). According to the spec, source maps have the
  906. * following attributes:
  907. *
  908. * - version: Which version of the source map spec this map is following.
  909. * - sources: An array of URLs to the original source files.
  910. * - names: An array of identifiers which can be referrenced by individual mappings.
  911. * - sourceRoot: Optional. The URL root from which all sources are relative.
  912. * - sourcesContent: Optional. An array of contents of the original source files.
  913. * - mappings: A string of base64 VLQs which contain the actual mappings.
  914. * - file: The generated file this source map is associated with.
  915. *
  916. * Here is an example source map, taken from the source map spec[0]:
  917. *
  918. * {
  919. * version : 3,
  920. * file: "out.js",
  921. * sourceRoot : "",
  922. * sources: ["foo.js", "bar.js"],
  923. * names: ["src", "maps", "are", "fun"],
  924. * mappings: "AA,AB;;ABCDE;"
  925. * }
  926. *
  927. * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
  928. */
  929. function SourceMapConsumer(aSourceMap) {
  930. var sourceMap = aSourceMap;
  931. if (typeof aSourceMap === 'string') {
  932. sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
  933. }
  934. var version = util.getArg(sourceMap, 'version');
  935. var sources = util.getArg(sourceMap, 'sources');
  936. // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
  937. // requires the array) to play nice here.
  938. var names = util.getArg(sourceMap, 'names', []);
  939. var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
  940. var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
  941. var mappings = util.getArg(sourceMap, 'mappings');
  942. var file = util.getArg(sourceMap, 'file', null);
  943. // Once again, Sass deviates from the spec and supplies the version as a
  944. // string rather than a number, so we use loose equality checking here.
  945. if (version != this._version) {
  946. throw new Error('Unsupported version: ' + version);
  947. }
  948. // Pass `true` below to allow duplicate names and sources. While source maps
  949. // are intended to be compressed and deduplicated, the TypeScript compiler
  950. // sometimes generates source maps with duplicates in them. See Github issue
  951. // #72 and bugzil.la/889492.
  952. this._names = ArraySet.fromArray(names, true);
  953. this._sources = ArraySet.fromArray(sources, true);
  954. this.sourceRoot = sourceRoot;
  955. this.sourcesContent = sourcesContent;
  956. this._mappings = mappings;
  957. this.file = file;
  958. }
  959. /**
  960. * Create a SourceMapConsumer from a SourceMapGenerator.
  961. *
  962. * @param SourceMapGenerator aSourceMap
  963. * The source map that will be consumed.
  964. * @returns SourceMapConsumer
  965. */
  966. SourceMapConsumer.fromSourceMap =
  967. function SourceMapConsumer_fromSourceMap(aSourceMap) {
  968. var smc = Object.create(SourceMapConsumer.prototype);
  969. smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
  970. smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
  971. smc.sourceRoot = aSourceMap._sourceRoot;
  972. smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
  973. smc.sourceRoot);
  974. smc.file = aSourceMap._file;
  975. smc.__generatedMappings = aSourceMap._mappings.slice()
  976. .sort(util.compareByGeneratedPositions);
  977. smc.__originalMappings = aSourceMap._mappings.slice()
  978. .sort(util.compareByOriginalPositions);
  979. return smc;
  980. };
  981. /**
  982. * The version of the source mapping spec that we are consuming.
  983. */
  984. SourceMapConsumer.prototype._version = 3;
  985. /**
  986. * The list of original sources.
  987. */
  988. Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
  989. get: function () {
  990. return this._sources.toArray().map(function (s) {
  991. return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
  992. }, this);
  993. }
  994. });
  995. // `__generatedMappings` and `__originalMappings` are arrays that hold the
  996. // parsed mapping coordinates from the source map's "mappings" attribute. They
  997. // are lazily instantiated, accessed via the `_generatedMappings` and
  998. // `_originalMappings` getters respectively, and we only parse the mappings
  999. // and create these arrays once queried for a source location. We jump through
  1000. // these hoops because there can be many thousands of mappings, and parsing
  1001. // them is expensive, so we only want to do it if we must.
  1002. //
  1003. // Each object in the arrays is of the form:
  1004. //
  1005. // {
  1006. // generatedLine: The line number in the generated code,
  1007. // generatedColumn: The column number in the generated code,
  1008. // source: The path to the original source file that generated this
  1009. // chunk of code,
  1010. // originalLine: The line number in the original source that
  1011. // corresponds to this chunk of generated code,
  1012. // originalColumn: The column number in the original source that
  1013. // corresponds to this chunk of generated code,
  1014. // name: The name of the original symbol which generated this chunk of
  1015. // code.
  1016. // }
  1017. //
  1018. // All properties except for `generatedLine` and `generatedColumn` can be
  1019. // `null`.
  1020. //
  1021. // `_generatedMappings` is ordered by the generated positions.
  1022. //
  1023. // `_originalMappings` is ordered by the original positions.
  1024. SourceMapConsumer.prototype.__generatedMappings = null;
  1025. Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
  1026. get: function () {
  1027. if (!this.__generatedMappings) {
  1028. this.__generatedMappings = [];
  1029. this.__originalMappings = [];
  1030. this._parseMappings(this._mappings, this.sourceRoot);
  1031. }
  1032. return this.__generatedMappings;
  1033. }
  1034. });
  1035. SourceMapConsumer.prototype.__originalMappings = null;
  1036. Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
  1037. get: function () {
  1038. if (!this.__originalMappings) {
  1039. this.__generatedMappings = [];
  1040. this.__originalMappings = [];
  1041. this._parseMappings(this._mappings, this.sourceRoot);
  1042. }
  1043. return this.__originalMappings;
  1044. }
  1045. });
  1046. /**
  1047. * Parse the mappings in a string in to a data structure which we can easily
  1048. * query (the ordered arrays in the `this.__generatedMappings` and
  1049. * `this.__originalMappings` properties).
  1050. */
  1051. SourceMapConsumer.prototype._parseMappings =
  1052. function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
  1053. var generatedLine = 1;
  1054. var previousGeneratedColumn = 0;
  1055. var previousOriginalLine = 0;
  1056. var previousOriginalColumn = 0;
  1057. var previousSource = 0;
  1058. var previousName = 0;
  1059. var mappingSeparator = /^[,;]/;
  1060. var str = aStr;
  1061. var mapping;
  1062. var temp;
  1063. while (str.length > 0) {
  1064. if (str.charAt(0) === ';') {
  1065. generatedLine++;
  1066. str = str.slice(1);
  1067. previousGeneratedColumn = 0;
  1068. }
  1069. else if (str.charAt(0) === ',') {
  1070. str = str.slice(1);
  1071. }
  1072. else {
  1073. mapping = {};
  1074. mapping.generatedLine = generatedLine;
  1075. // Generated column.
  1076. temp = base64VLQ.decode(str);
  1077. mapping.generatedColumn = previousGeneratedColumn + temp.value;
  1078. previousGeneratedColumn = mapping.generatedColumn;
  1079. str = temp.rest;
  1080. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  1081. // Original source.
  1082. temp = base64VLQ.decode(str);
  1083. mapping.source = this._sources.at(previousSource + temp.value);
  1084. previousSource += temp.value;
  1085. str = temp.rest;
  1086. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  1087. throw new Error('Found a source, but no line and column');
  1088. }
  1089. // Original line.
  1090. temp = base64VLQ.decode(str);
  1091. mapping.originalLine = previousOriginalLine + temp.value;
  1092. previousOriginalLine = mapping.originalLine;
  1093. // Lines are stored 0-based
  1094. mapping.originalLine += 1;
  1095. str = temp.rest;
  1096. if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
  1097. throw new Error('Found a source and line, but no column');
  1098. }
  1099. // Original column.
  1100. temp = base64VLQ.decode(str);
  1101. mapping.originalColumn = previousOriginalColumn + temp.value;
  1102. previousOriginalColumn = mapping.originalColumn;
  1103. str = temp.rest;
  1104. if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
  1105. // Original name.
  1106. temp = base64VLQ.decode(str);
  1107. mapping.name = this._names.at(previousName + temp.value);
  1108. previousName += temp.value;
  1109. str = temp.rest;
  1110. }
  1111. }
  1112. this.__generatedMappings.push(mapping);
  1113. if (typeof mapping.originalLine === 'number') {
  1114. this.__originalMappings.push(mapping);
  1115. }
  1116. }
  1117. }
  1118. this.__originalMappings.sort(util.compareByOriginalPositions);
  1119. };
  1120. /**
  1121. * Find the mapping that best matches the hypothetical "needle" mapping that
  1122. * we are searching for in the given "haystack" of mappings.
  1123. */
  1124. SourceMapConsumer.prototype._findMapping =
  1125. function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
  1126. aColumnName, aComparator) {
  1127. // To return the position we are searching for, we must first find the
  1128. // mapping for the given position and then return the opposite position it
  1129. // points to. Because the mappings are sorted, we can use binary search to
  1130. // find the best mapping.
  1131. if (aNeedle[aLineName] <= 0) {
  1132. throw new TypeError('Line must be greater than or equal to 1, got '
  1133. + aNeedle[aLineName]);
  1134. }
  1135. if (aNeedle[aColumnName] < 0) {
  1136. throw new TypeError('Column must be greater than or equal to 0, got '
  1137. + aNeedle[aColumnName]);
  1138. }
  1139. return binarySearch.search(aNeedle, aMappings, aComparator);
  1140. };
  1141. /**
  1142. * Returns the original source, line, and column information for the generated
  1143. * source's line and column positions provided. The only argument is an object
  1144. * with the following properties:
  1145. *
  1146. * - line: The line number in the generated source.
  1147. * - column: The column number in the generated source.
  1148. *
  1149. * and an object is returned with the following properties:
  1150. *
  1151. * - source: The original source file, or null.
  1152. * - line: The line number in the original source, or null.
  1153. * - column: The column number in the original source, or null.
  1154. * - name: The original identifier, or null.
  1155. */
  1156. SourceMapConsumer.prototype.originalPositionFor =
  1157. function SourceMapConsumer_originalPositionFor(aArgs) {
  1158. var needle = {
  1159. generatedLine: util.getArg(aArgs, 'line'),
  1160. generatedColumn: util.getArg(aArgs, 'column')
  1161. };
  1162. var mapping = this._findMapping(needle,
  1163. this._generatedMappings,
  1164. "generatedLine",
  1165. "generatedColumn",
  1166. util.compareByGeneratedPositions);
  1167. if (mapping) {
  1168. var source = util.getArg(mapping, 'source', null);
  1169. if (source && this.sourceRoot) {
  1170. source = util.join(this.sourceRoot, source);
  1171. }
  1172. return {
  1173. source: source,
  1174. line: util.getArg(mapping, 'originalLine', null),
  1175. column: util.getArg(mapping, 'originalColumn', null),
  1176. name: util.getArg(mapping, 'name', null)
  1177. };
  1178. }
  1179. return {
  1180. source: null,
  1181. line: null,
  1182. column: null,
  1183. name: null
  1184. };
  1185. };
  1186. /**
  1187. * Returns the original source content. The only argument is the url of the
  1188. * original source file. Returns null if no original source content is
  1189. * available.
  1190. */
  1191. SourceMapConsumer.prototype.sourceContentFor =
  1192. function SourceMapConsumer_sourceContentFor(aSource) {
  1193. if (!this.sourcesContent) {
  1194. return null;
  1195. }
  1196. if (this.sourceRoot) {
  1197. aSource = util.relative(this.sourceRoot, aSource);
  1198. }
  1199. if (this._sources.has(aSource)) {
  1200. return this.sourcesContent[this._sources.indexOf(aSource)];
  1201. }
  1202. var url;
  1203. if (this.sourceRoot
  1204. && (url = util.urlParse(this.sourceRoot))) {
  1205. // XXX: file:// URIs and absolute paths lead to unexpected behavior for
  1206. // many users. We can help them out when they expect file:// URIs to
  1207. // behave like it would if they were running a local HTTP server. See
  1208. // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
  1209. var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
  1210. if (url.scheme == "file"
  1211. && this._sources.has(fileUriAbsPath)) {
  1212. return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
  1213. }
  1214. if ((!url.path || url.path == "/")
  1215. && this._sources.has("/" + aSource)) {
  1216. return this.sourcesContent[this._sources.indexOf("/" + aSource)];
  1217. }
  1218. }
  1219. throw new Error('"' + aSource + '" is not in the SourceMap.');
  1220. };
  1221. /**
  1222. * Returns the generated line and column information for the original source,
  1223. * line, and column positions provided. The only argument is an object with
  1224. * the following properties:
  1225. *
  1226. * - source: The filename of the original source.
  1227. * - line: The line number in the original source.
  1228. * - column: The column number in the original source.
  1229. *
  1230. * and an object is returned with the following properties:
  1231. *
  1232. * - line: The line number in the generated source, or null.
  1233. * - column: The column number in the generated source, or null.
  1234. */
  1235. SourceMapConsumer.prototype.generatedPositionFor =
  1236. function SourceMapConsumer_generatedPositionFor(aArgs) {
  1237. var needle = {
  1238. source: util.getArg(aArgs, 'source'),
  1239. originalLine: util.getArg(aArgs, 'line'),
  1240. originalColumn: util.getArg(aArgs, 'column')
  1241. };
  1242. if (this.sourceRoot) {
  1243. needle.source = util.relative(this.sourceRoot, needle.source);
  1244. }
  1245. var mapping = this._findMapping(needle,
  1246. this._originalMappings,
  1247. "originalLine",
  1248. "originalColumn",
  1249. util.compareByOriginalPositions);
  1250. if (mapping) {
  1251. return {
  1252. line: util.getArg(mapping, 'generatedLine', null),
  1253. column: util.getArg(mapping, 'generatedColumn', null)
  1254. };
  1255. }
  1256. return {
  1257. line: null,
  1258. column: null
  1259. };
  1260. };
  1261. SourceMapConsumer.GENERATED_ORDER = 1;
  1262. SourceMapConsumer.ORIGINAL_ORDER = 2;
  1263. /**
  1264. * Iterate over each mapping between an original source/line/column and a
  1265. * generated line/column in this source map.
  1266. *
  1267. * @param Function aCallback
  1268. * The function that is called with each mapping.
  1269. * @param Object aContext
  1270. * Optional. If specified, this object will be the value of `this` every
  1271. * time that `aCallback` is called.
  1272. * @param aOrder
  1273. * Either `SourceMapConsumer.GENERATED_ORDER` or
  1274. * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
  1275. * iterate over the mappings sorted by the generated file's line/column
  1276. * order or the original's source/line/column order, respectively. Defaults to
  1277. * `SourceMapConsumer.GENERATED_ORDER`.
  1278. */
  1279. SourceMapConsumer.prototype.eachMapping =
  1280. function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
  1281. var context = aContext || null;
  1282. var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
  1283. var mappings;
  1284. switch (order) {
  1285. case SourceMapConsumer.GENERATED_ORDER:
  1286. mappings = this._generatedMappings;
  1287. break;
  1288. case SourceMapConsumer.ORIGINAL_ORDER:
  1289. mappings = this._originalMappings;
  1290. break;
  1291. default:
  1292. throw new Error("Unknown order of iteration.");
  1293. }
  1294. var sourceRoot = this.sourceRoot;
  1295. mappings.map(function (mapping) {
  1296. var source = mapping.source;
  1297. if (source && sourceRoot) {
  1298. source = util.join(sourceRoot, source);
  1299. }
  1300. return {
  1301. source: source,
  1302. generatedLine: mapping.generatedLine,
  1303. generatedColumn: mapping.generatedColumn,
  1304. originalLine: mapping.originalLine,
  1305. originalColumn: mapping.originalColumn,
  1306. name: mapping.name
  1307. };
  1308. }).forEach(aCallback, context);
  1309. };
  1310. exports.SourceMapConsumer = SourceMapConsumer;
  1311. });
  1312. /* -*- Mode: js; js-indent-level: 2; -*- */
  1313. /*
  1314. * Copyright 2011 Mozilla Foundation and contributors
  1315. * Licensed under the New BSD license. See LICENSE or:
  1316. * http://opensource.org/licenses/BSD-3-Clause
  1317. */
  1318. define('source-map/binary-search', ['require', 'exports', 'module' , ], function(require, exports, module) {
  1319. /**
  1320. * Recursive implementation of binary search.
  1321. *
  1322. * @param aLow Indices here and lower do not contain the needle.
  1323. * @param aHigh Indices here and higher do not contain the needle.
  1324. * @param aNeedle The element being searched for.
  1325. * @param aHaystack The non-empty array being searched.
  1326. * @param aCompare Function which takes two elements and returns -1, 0, or 1.
  1327. */
  1328. function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
  1329. // This function terminates when one of the following is true:
  1330. //
  1331. // 1. We find the exact element we are looking for.
  1332. //
  1333. // 2. We did not find the exact element, but we can return the next
  1334. // closest element that is less than that element.
  1335. //
  1336. // 3. We did not find the exact element, and there is no next-closest
  1337. // element which is less than the one we are searching for, so we
  1338. // return null.
  1339. var mid = Math.floor((aHigh - aLow) / 2) + aLow;
  1340. var cmp = aCompare(aNeedle, aHaystack[mid], true);
  1341. if (cmp === 0) {
  1342. // Found the element we are looking for.
  1343. return aHaystack[mid];
  1344. }
  1345. else if (cmp > 0) {
  1346. // aHaystack[mid] is greater than our needle.
  1347. if (aHigh - mid > 1) {
  1348. // The element is in the upper half.
  1349. return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
  1350. }
  1351. // We did not find an exact match, return the next closest one
  1352. // (termination case 2).
  1353. return aHaystack[mid];
  1354. }
  1355. else {
  1356. // aHaystack[mid] is less than our needle.
  1357. if (mid - aLow > 1) {
  1358. // The element is in the lower half.
  1359. return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
  1360. }
  1361. // The exact needle element was not found in this haystack. Determine if
  1362. // we are in termination case (2) or (3) and return the appropriate thing.
  1363. return aLow < 0
  1364. ? null
  1365. : aHaystack[aLow];
  1366. }
  1367. }
  1368. /**
  1369. * This is an implementation of binary search which will always try and return
  1370. * the next lowest value checked if there is no exact hit. This is because
  1371. * mappings between original and generated line/col pairs are single points,
  1372. * and there is an implicit region between each of them, so a miss just means
  1373. * that you aren't on the very start of a region.
  1374. *
  1375. * @param aNeedle The element you are looking for.
  1376. * @param aHaystack The array that is being searched.
  1377. * @param aCompare A function which takes the needle and an element in the
  1378. * array and returns -1, 0, or 1 depending on whether the needle is less
  1379. * than, equal to, or greater than the element, respectively.
  1380. */
  1381. exports.search = function search(aNeedle, aHaystack, aCompare) {
  1382. return aHaystack.length > 0
  1383. ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
  1384. : null;
  1385. };
  1386. });
  1387. /* -*- Mode: js; js-indent-level: 2; -*- */
  1388. /*
  1389. * Copyright 2011 Mozilla Foundation and contributors
  1390. * Licensed under the New BSD license. See LICENSE or:
  1391. * http://opensource.org/licenses/BSD-3-Clause
  1392. */
  1393. define('source-map/source-node', ['require', 'exports', 'module' , 'source-map/source-map-generator', 'source-map/util'], function(require, exports, module) {
  1394. var SourceMapGenerator = require('./source-map-generator').SourceMapGenerator;
  1395. var util = require('./util');
  1396. /**
  1397. * SourceNodes provide a way to abstract over interpolating/concatenating
  1398. * snippets of generated JavaScript source code while maintaining the line and
  1399. * column information associated with the original source code.
  1400. *
  1401. * @param aLine The original line number.
  1402. * @param aColumn The original column number.
  1403. * @param aSource The original source's filename.
  1404. * @param aChunks Optional. An array of strings which are snippets of
  1405. * generated JS, or other SourceNodes.
  1406. * @param aName The original identifier.
  1407. */
  1408. function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  1409. this.children = [];
  1410. this.sourceContents = {};
  1411. this.line = aLine === undefined ? null : aLine;
  1412. this.column = aColumn === undefined ? null : aColumn;
  1413. this.source = aSource === undefined ? null : aSource;
  1414. this.name = aName === undefined ? null : aName;
  1415. if (aChunks != null) this.add(aChunks);
  1416. }
  1417. /**
  1418. * Creates a SourceNode from generated code and a SourceMapConsumer.
  1419. *
  1420. * @param aGeneratedCode The generated code
  1421. * @param aSourceMapConsumer The SourceMap for the generated code
  1422. */
  1423. SourceNode.fromStringWithSourceMap =
  1424. function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
  1425. // The SourceNode we want to fill with the generated code
  1426. // and the SourceMap
  1427. var node = new SourceNode();
  1428. // The generated code
  1429. // Processed fragments are removed from this array.
  1430. var remainingLines = aGeneratedCode.split('\n');
  1431. // We need to remember the position of "remainingLines"
  1432. var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  1433. // The generate SourceNodes we need a code range.
  1434. // To extract it current and last mapping is used.
  1435. // Here we store the last mapping.
  1436. var lastMapping = null;
  1437. aSourceMapConsumer.eachMapping(function (mapping) {
  1438. if (lastMapping === null) {
  1439. // We add the generated code until the first mapping
  1440. // to the SourceNode without any mapping.
  1441. // Each line is added as separate string.
  1442. while (lastGeneratedLine < mapping.generatedLine) {
  1443. node.add(remainingLines.shift() + "\n");
  1444. lastGeneratedLine++;
  1445. }
  1446. if (lastGeneratedColumn < mapping.generatedColumn) {
  1447. var nextLine = remainingLines[0];
  1448. node.add(nextLine.substr(0, mapping.generatedColumn));
  1449. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  1450. lastGeneratedColumn = mapping.generatedColumn;
  1451. }
  1452. } else {
  1453. // We add the code from "lastMapping" to "mapping":
  1454. // First check if there is a new line in between.
  1455. if (lastGeneratedLine < mapping.generatedLine) {
  1456. var code = "";
  1457. // Associate full lines with "lastMapping"
  1458. do {
  1459. code += remainingLines.shift() + "\n";
  1460. lastGeneratedLine++;
  1461. lastGeneratedColumn = 0;
  1462. } while (lastGeneratedLine < mapping.generatedLine);
  1463. // When we reached the correct line, we add code until we
  1464. // reach the correct column too.
  1465. if (lastGeneratedColumn < mapping.generatedColumn) {
  1466. var nextLine = remainingLines[0];
  1467. code += nextLine.substr(0, mapping.generatedColumn);
  1468. remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  1469. lastGeneratedColumn = mapping.generatedColumn;
  1470. }
  1471. // Create the SourceNode.
  1472. addMappingWithCode(lastMapping, code);
  1473. } else {
  1474. // There is no new line in between.
  1475. // Associate the code between "lastGeneratedColumn" and
  1476. // "mapping.generatedColumn" with "lastMapping"
  1477. var nextLine = remainingLines[0];
  1478. var code = nextLine.substr(0, mapping.generatedColumn -
  1479. lastGeneratedColumn);
  1480. remainingLines[0] = nextLine.substr(mapping.generatedColumn -
  1481. lastGeneratedColumn);
  1482. lastGeneratedColumn = mapping.generatedColumn;
  1483. addMappingWithCode(lastMapping, code);
  1484. }
  1485. }
  1486. lastMapping = mapping;
  1487. }, this);
  1488. // We have processed all mappings.
  1489. // Associate the remaining code in the current line with "lastMapping"
  1490. // and add the remaining lines without any mapping
  1491. addMappingWithCode(lastMapping, remainingLines.join("\n"));
  1492. // Copy sourcesContent into SourceNode
  1493. aSourceMapConsumer.sources.forEach(function (sourceFile) {
  1494. var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  1495. if (content) {
  1496. node.setSourceContent(sourceFile, content);
  1497. }
  1498. });
  1499. return node;
  1500. function addMappingWithCode(mapping, code) {
  1501. if (mapping === null || mapping.source === undefined) {
  1502. node.add(code);
  1503. } else {
  1504. node.add(new SourceNode(mapping.originalLine,
  1505. mapping.originalColumn,
  1506. mapping.source,
  1507. code,
  1508. mapping.name));
  1509. }
  1510. }
  1511. };
  1512. /**
  1513. * Add a chunk of generated JS to this source node.
  1514. *
  1515. * @param aChunk A string snippet of generated JS code, another instance of
  1516. * SourceNode, or an array where each member is one of those things.
  1517. */
  1518. SourceNode.prototype.add = function SourceNode_add(aChunk) {
  1519. if (Array.isArray(aChunk)) {
  1520. aChunk.forEach(function (chunk) {
  1521. this.add(chunk);
  1522. }, this);
  1523. }
  1524. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  1525. if (aChunk) {
  1526. this.children.push(aChunk);
  1527. }
  1528. }
  1529. else {
  1530. throw new TypeError(
  1531. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  1532. );
  1533. }
  1534. return this;
  1535. };
  1536. /**
  1537. * Add a chunk of generated JS to the beginning of this source node.
  1538. *
  1539. * @param aChunk A string snippet of generated JS code, another instance of
  1540. * SourceNode, or an array where each member is one of those things.
  1541. */
  1542. SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  1543. if (Array.isArray(aChunk)) {
  1544. for (var i = aChunk.length-1; i >= 0; i--) {
  1545. this.prepend(aChunk[i]);
  1546. }
  1547. }
  1548. else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  1549. this.children.unshift(aChunk);
  1550. }
  1551. else {
  1552. throw new TypeError(
  1553. "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  1554. );
  1555. }
  1556. return this;
  1557. };
  1558. /**
  1559. * Walk over the tree of JS snippets in this node and its children. The
  1560. * walking function is called once for each snippet of JS and is passed that
  1561. * snippet and the its original associated source's line/column location.
  1562. *
  1563. * @param aFn The traversal function.
  1564. */
  1565. SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  1566. var chunk;
  1567. for (var i = 0, len = this.children.length; i < len; i++) {
  1568. chunk = this.children[i];
  1569. if (chunk instanceof SourceNode) {
  1570. chunk.walk(aFn);
  1571. }
  1572. else {
  1573. if (chunk !== '') {
  1574. aFn(chunk, { source: this.source,
  1575. line: this.line,
  1576. column: this.column,
  1577. name: this.name });
  1578. }
  1579. }
  1580. }
  1581. };
  1582. /**
  1583. * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  1584. * each of `this.children`.
  1585. *
  1586. * @param aSep The separator.
  1587. */
  1588. SourceNode.prototype.join = function SourceNode_join(aSep) {
  1589. var newChildren;
  1590. var i;
  1591. var len = this.children.length;
  1592. if (len > 0) {
  1593. newChildren = [];
  1594. for (i = 0; i < len-1; i++) {
  1595. newChildren.push(this.children[i]);
  1596. newChildren.push(aSep);
  1597. }
  1598. newChildren.push(this.children[i]);
  1599. this.children = newChildren;
  1600. }
  1601. return this;
  1602. };
  1603. /**
  1604. * Call String.prototype.replace on the very right-most source snippet. Useful
  1605. * for trimming whitespace from the end of a source node, etc.
  1606. *
  1607. * @param aPattern The pattern to replace.
  1608. * @param aReplacement The thing to replace the pattern with.
  1609. */
  1610. SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  1611. var lastChild = this.children[this.children.length - 1];
  1612. if (lastChild instanceof SourceNode) {
  1613. lastChild.replaceRight(aPattern, aReplacement);
  1614. }
  1615. else if (typeof lastChild === 'string') {
  1616. this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  1617. }
  1618. else {
  1619. this.children.push(''.replace(aPattern, aReplacement));
  1620. }
  1621. return this;
  1622. };
  1623. /**
  1624. * Set the source content for a source file. This will be added to the SourceMapGenerator
  1625. * in the sourcesContent field.
  1626. *
  1627. * @param aSourceFile The filename of the source file
  1628. * @param aSourceContent The content of the source file
  1629. */
  1630. SourceNode.prototype.setSourceContent =
  1631. function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  1632. this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  1633. };
  1634. /**
  1635. * Walk over the tree of SourceNodes. The walking function is called for each
  1636. * source file content and is passed the filename and source content.
  1637. *
  1638. * @param aFn The traversal function.
  1639. */
  1640. SourceNode.prototype.walkSourceContents =
  1641. function SourceNode_walkSourceContents(aFn) {
  1642. for (var i = 0, len = this.children.length; i < len; i++) {
  1643. if (this.children[i] instanceof SourceNode) {
  1644. this.children[i].walkSourceContents(aFn);
  1645. }
  1646. }
  1647. var sources = Object.keys(this.sourceContents);
  1648. for (var i = 0, len = sources.length; i < len; i++) {
  1649. aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  1650. }
  1651. };
  1652. /**
  1653. * Return the string representation of this source node. Walks over the tree
  1654. * and concatenates all the various snippets together to one string.
  1655. */
  1656. SourceNode.prototype.toString = function SourceNode_toString() {
  1657. var str = "";
  1658. this.walk(function (chunk) {
  1659. str += chunk;
  1660. });
  1661. return str;
  1662. };
  1663. /**
  1664. * Returns the string representation of this source node along with a source
  1665. * map.
  1666. */
  1667. SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  1668. var generated = {
  1669. code: "",
  1670. line: 1,
  1671. column: 0
  1672. };
  1673. var map = new SourceMapGenerator(aArgs);
  1674. var sourceMappingActive = false;
  1675. var lastOriginalSource = null;
  1676. var lastOriginalLine = null;
  1677. var lastOriginalColumn = null;
  1678. var lastOriginalName = null;
  1679. this.walk(function (chunk, original) {
  1680. generated.code += chunk;
  1681. if (original.source !== null
  1682. && original.line !== null
  1683. && original.column !== null) {
  1684. if (lastOriginalSource !== original.source
  1685. || lastOriginalLine !== original.line
  1686. || lastOriginalColumn !== original.column
  1687. || lastOriginalName !== original.name) {
  1688. map.addMapping({
  1689. source: original.source,
  1690. original: {
  1691. line: original.line,
  1692. column: original.column
  1693. },
  1694. generated: {
  1695. line: generated.line,
  1696. column: generated.column
  1697. },
  1698. name: original.name
  1699. });
  1700. }
  1701. lastOriginalSource = original.source;
  1702. lastOriginalLine = original.line;
  1703. lastOriginalColumn = original.column;
  1704. lastOriginalName = original.name;
  1705. sourceMappingActive = true;
  1706. } else if (sourceMappingActive) {
  1707. map.addMapping({
  1708. generated: {
  1709. line: generated.line,
  1710. column: generated.column
  1711. }
  1712. });
  1713. lastOriginalSource = null;
  1714. sourceMappingActive = false;
  1715. }
  1716. chunk.split('').forEach(function (ch) {
  1717. if (ch === '\n') {
  1718. generated.line++;
  1719. generated.column = 0;
  1720. } else {
  1721. generated.column++;
  1722. }
  1723. });
  1724. });
  1725. this.walkSourceContents(function (sourceFile, sourceContent) {
  1726. map.setSourceContent(sourceFile, sourceContent);
  1727. });
  1728. return { code: generated.code, map: map };
  1729. };
  1730. exports.SourceNode = SourceNode;
  1731. });
  1732. /* -*- Mode: js; js-indent-level: 2; -*- */
  1733. ///////////////////////////////////////////////////////////////////////////////
  1734. this.sourceMap = {
  1735. SourceMapConsumer: require('source-map/source-map-consumer').SourceMapConsumer,
  1736. SourceMapGenerator: require('source-map/source-map-generator').SourceMapGenerator,
  1737. SourceNode: require('source-map/source-node').SourceNode
  1738. };