source-map.js 98 KB

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