You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

source-map.js 100KB

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