source-map.min.js 109 KB

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