4
1

source-map.js 104 KB

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