source-map.js 108 KB

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