react / wstein / node_modules / browserify / node_modules / browser-pack / node_modules / combine-source-map / node_modules / source-map / lib / source-map / source-map-consumer.js
80559 views/* -*- Mode: js; js-indent-level: 2; -*- */1/*2* Copyright 2011 Mozilla Foundation and contributors3* Licensed under the New BSD license. See LICENSE or:4* http://opensource.org/licenses/BSD-3-Clause5*/6if (typeof define !== 'function') {7var define = require('amdefine')(module, require);8}9define(function (require, exports, module) {1011var util = require('./util');12var binarySearch = require('./binary-search');13var ArraySet = require('./array-set').ArraySet;14var base64VLQ = require('./base64-vlq');1516function SourceMapConsumer(aSourceMap) {17var sourceMap = aSourceMap;18if (typeof aSourceMap === 'string') {19sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));20}2122return sourceMap.sections != null23? new IndexedSourceMapConsumer(sourceMap)24: new BasicSourceMapConsumer(sourceMap);25}2627SourceMapConsumer.fromSourceMap = function(aSourceMap) {28return BasicSourceMapConsumer.fromSourceMap(aSourceMap);29}3031/**32* The version of the source mapping spec that we are consuming.33*/34SourceMapConsumer.prototype._version = 3;3536// `__generatedMappings` and `__originalMappings` are arrays that hold the37// parsed mapping coordinates from the source map's "mappings" attribute. They38// are lazily instantiated, accessed via the `_generatedMappings` and39// `_originalMappings` getters respectively, and we only parse the mappings40// and create these arrays once queried for a source location. We jump through41// these hoops because there can be many thousands of mappings, and parsing42// them is expensive, so we only want to do it if we must.43//44// Each object in the arrays is of the form:45//46// {47// generatedLine: The line number in the generated code,48// generatedColumn: The column number in the generated code,49// source: The path to the original source file that generated this50// chunk of code,51// originalLine: The line number in the original source that52// corresponds to this chunk of generated code,53// originalColumn: The column number in the original source that54// corresponds to this chunk of generated code,55// name: The name of the original symbol which generated this chunk of56// code.57// }58//59// All properties except for `generatedLine` and `generatedColumn` can be60// `null`.61//62// `_generatedMappings` is ordered by the generated positions.63//64// `_originalMappings` is ordered by the original positions.6566SourceMapConsumer.prototype.__generatedMappings = null;67Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {68get: function () {69if (!this.__generatedMappings) {70this.__generatedMappings = [];71this.__originalMappings = [];72this._parseMappings(this._mappings, this.sourceRoot);73}7475return this.__generatedMappings;76}77});7879SourceMapConsumer.prototype.__originalMappings = null;80Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {81get: function () {82if (!this.__originalMappings) {83this.__generatedMappings = [];84this.__originalMappings = [];85this._parseMappings(this._mappings, this.sourceRoot);86}8788return this.__originalMappings;89}90});9192SourceMapConsumer.prototype._nextCharIsMappingSeparator =93function SourceMapConsumer_nextCharIsMappingSeparator(aStr, index) {94var c = aStr.charAt(index);95return c === ";" || c === ",";96};9798/**99* Parse the mappings in a string in to a data structure which we can easily100* query (the ordered arrays in the `this.__generatedMappings` and101* `this.__originalMappings` properties).102*/103SourceMapConsumer.prototype._parseMappings =104function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {105throw new Error("Subclasses must implement _parseMappings");106};107108SourceMapConsumer.GENERATED_ORDER = 1;109SourceMapConsumer.ORIGINAL_ORDER = 2;110111SourceMapConsumer.GREATEST_LOWER_BOUND = 1;112SourceMapConsumer.LEAST_UPPER_BOUND = 2;113114/**115* Iterate over each mapping between an original source/line/column and a116* generated line/column in this source map.117*118* @param Function aCallback119* The function that is called with each mapping.120* @param Object aContext121* Optional. If specified, this object will be the value of `this` every122* time that `aCallback` is called.123* @param aOrder124* Either `SourceMapConsumer.GENERATED_ORDER` or125* `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to126* iterate over the mappings sorted by the generated file's line/column127* order or the original's source/line/column order, respectively. Defaults to128* `SourceMapConsumer.GENERATED_ORDER`.129*/130SourceMapConsumer.prototype.eachMapping =131function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {132var context = aContext || null;133var order = aOrder || SourceMapConsumer.GENERATED_ORDER;134135var mappings;136switch (order) {137case SourceMapConsumer.GENERATED_ORDER:138mappings = this._generatedMappings;139break;140case SourceMapConsumer.ORIGINAL_ORDER:141mappings = this._originalMappings;142break;143default:144throw new Error("Unknown order of iteration.");145}146147var sourceRoot = this.sourceRoot;148mappings.map(function (mapping) {149var source = mapping.source;150if (source != null && sourceRoot != null) {151source = util.join(sourceRoot, source);152}153return {154source: source,155generatedLine: mapping.generatedLine,156generatedColumn: mapping.generatedColumn,157originalLine: mapping.originalLine,158originalColumn: mapping.originalColumn,159name: mapping.name160};161}).forEach(aCallback, context);162};163164/**165* Returns all generated line and column information for the original source,166* line, and column provided. If no column is provided, returns all mappings167* corresponding to a single line. Otherwise, returns all mappings168* corresponding to a single line and column.169*170* The only argument is an object with the following properties:171*172* - source: The filename of the original source.173* - line: The line number in the original source.174* - column: Optional. the column number in the original source.175*176* and an array of objects is returned, each with the following properties:177*178* - line: The line number in the generated source, or null.179* - column: The column number in the generated source, or null.180*/181SourceMapConsumer.prototype.allGeneratedPositionsFor =182function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {183// When there is no exact match, BasicSourceMapConsumer.prototype._findMapping184// returns the index of the closest mapping less than the needle. By185// setting needle.originalColumn to 0, we thus find the last mapping for186// the given line, provided such a mapping exists.187var needle = {188source: util.getArg(aArgs, 'source'),189originalLine: util.getArg(aArgs, 'line'),190originalColumn: util.getArg(aArgs, 'column', 0)191};192193if (this.sourceRoot != null) {194needle.source = util.relative(this.sourceRoot, needle.source);195}196197var mappings = [];198199var index = this._findMapping(needle,200this._originalMappings,201"originalLine",202"originalColumn",203util.compareByOriginalPositions,204binarySearch.LEAST_UPPER_BOUND);205if (index >= 0) {206var mapping = this._originalMappings[index];207var originalLine = mapping.originalLine;208var originalColumn = mapping.originalColumn;209210// Iterate until either we run out of mappings, or we run into211// a mapping for a different line. Since mappings are sorted, this is212// guaranteed to find all mappings for the line we are searching for.213while (mapping && mapping.originalLine === originalLine &&214(aArgs.column === undefined ||215mapping.originalColumn === originalColumn)) {216mappings.push({217line: util.getArg(mapping, 'generatedLine', null),218column: util.getArg(mapping, 'generatedColumn', null),219lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)220});221222mapping = this._originalMappings[++index];223}224}225226return mappings;227};228229exports.SourceMapConsumer = SourceMapConsumer;230231/**232* A BasicSourceMapConsumer instance represents a parsed source map which we can233* query for information about the original file positions by giving it a file234* position in the generated source.235*236* The only parameter is the raw source map (either as a JSON string, or237* already parsed to an object). According to the spec, source maps have the238* following attributes:239*240* - version: Which version of the source map spec this map is following.241* - sources: An array of URLs to the original source files.242* - names: An array of identifiers which can be referrenced by individual mappings.243* - sourceRoot: Optional. The URL root from which all sources are relative.244* - sourcesContent: Optional. An array of contents of the original source files.245* - mappings: A string of base64 VLQs which contain the actual mappings.246* - file: Optional. The generated file this source map is associated with.247*248* Here is an example source map, taken from the source map spec[0]:249*250* {251* version : 3,252* file: "out.js",253* sourceRoot : "",254* sources: ["foo.js", "bar.js"],255* names: ["src", "maps", "are", "fun"],256* mappings: "AA,AB;;ABCDE;"257* }258*259* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#260*/261function BasicSourceMapConsumer(aSourceMap) {262var sourceMap = aSourceMap;263if (typeof aSourceMap === 'string') {264sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));265}266267var version = util.getArg(sourceMap, 'version');268var sources = util.getArg(sourceMap, 'sources');269// Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which270// requires the array) to play nice here.271var names = util.getArg(sourceMap, 'names', []);272var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);273var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);274var mappings = util.getArg(sourceMap, 'mappings');275var file = util.getArg(sourceMap, 'file', null);276277// Once again, Sass deviates from the spec and supplies the version as a278// string rather than a number, so we use loose equality checking here.279if (version != this._version) {280throw new Error('Unsupported version: ' + version);281}282283// Some source maps produce relative source paths like "./foo.js" instead of284// "foo.js". Normalize these first so that future comparisons will succeed.285// See bugzil.la/1090768.286sources = sources.map(util.normalize);287288// Pass `true` below to allow duplicate names and sources. While source maps289// are intended to be compressed and deduplicated, the TypeScript compiler290// sometimes generates source maps with duplicates in them. See Github issue291// #72 and bugzil.la/889492.292this._names = ArraySet.fromArray(names, true);293this._sources = ArraySet.fromArray(sources, true);294295this.sourceRoot = sourceRoot;296this.sourcesContent = sourcesContent;297this._mappings = mappings;298this.file = file;299}300301BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);302BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;303304/**305* Create a BasicSourceMapConsumer from a SourceMapGenerator.306*307* @param SourceMapGenerator aSourceMap308* The source map that will be consumed.309* @returns BasicSourceMapConsumer310*/311BasicSourceMapConsumer.fromSourceMap =312function SourceMapConsumer_fromSourceMap(aSourceMap) {313var smc = Object.create(BasicSourceMapConsumer.prototype);314315smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);316smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);317smc.sourceRoot = aSourceMap._sourceRoot;318smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),319smc.sourceRoot);320smc.file = aSourceMap._file;321322smc.__generatedMappings = aSourceMap._mappings.toArray().slice();323smc.__originalMappings = aSourceMap._mappings.toArray().slice()324.sort(util.compareByOriginalPositions);325326return smc;327};328329/**330* The version of the source mapping spec that we are consuming.331*/332BasicSourceMapConsumer.prototype._version = 3;333334/**335* The list of original sources.336*/337Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {338get: function () {339return this._sources.toArray().map(function (s) {340return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;341}, this);342}343});344345/**346* Parse the mappings in a string in to a data structure which we can easily347* query (the ordered arrays in the `this.__generatedMappings` and348* `this.__originalMappings` properties).349*/350BasicSourceMapConsumer.prototype._parseMappings =351function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {352var generatedLine = 1;353var previousGeneratedColumn = 0;354var previousOriginalLine = 0;355var previousOriginalColumn = 0;356var previousSource = 0;357var previousName = 0;358var length = aStr.length;359var index = 0;360var cachedValues = {};361var temp = {};362var mapping, str, values, end, value;363364while (index < length) {365if (aStr.charAt(index) === ';') {366generatedLine++;367++index;368previousGeneratedColumn = 0;369}370else if (aStr.charAt(index) === ',') {371++index;372}373else {374mapping = {};375mapping.generatedLine = generatedLine;376377// Because each offset is encoded relative to the previous one,378// many segments often have the same encoding. We can exploit this379// fact by caching the parsed variable length fields of each segment,380// allowing us to avoid a second parse if we encounter the same381// segment again.382for (end = index; end < length; ++end) {383if (this._nextCharIsMappingSeparator(aStr, end)) {384break;385}386}387str = aStr.slice(index, end);388389values = cachedValues[str];390if (values) {391index += str.length;392} else {393values = [];394while (index < end) {395base64VLQ.decode(aStr, index, temp);396value = temp.value;397index = temp.rest;398values.push(value);399}400cachedValues[str] = values;401}402403// Generated column.404mapping.generatedColumn = previousGeneratedColumn + values[0];405previousGeneratedColumn = mapping.generatedColumn;406407if (values.length > 1) {408// Original source.409mapping.source = this._sources.at(previousSource + values[1]);410previousSource += values[1];411if (values.length === 2) {412throw new Error('Found a source, but no line and column');413}414415// Original line.416mapping.originalLine = previousOriginalLine + values[2];417previousOriginalLine = mapping.originalLine;418// Lines are stored 0-based419mapping.originalLine += 1;420if (values.length === 3) {421throw new Error('Found a source and line, but no column');422}423424// Original column.425mapping.originalColumn = previousOriginalColumn + values[3];426previousOriginalColumn = mapping.originalColumn;427428if (values.length > 4) {429// Original name.430mapping.name = this._names.at(previousName + values[4]);431previousName += values[4];432}433}434435this.__generatedMappings.push(mapping);436if (typeof mapping.originalLine === 'number') {437this.__originalMappings.push(mapping);438}439}440}441442this.__generatedMappings.sort(util.compareByGeneratedPositions);443this.__originalMappings.sort(util.compareByOriginalPositions);444};445446/**447* Find the mapping that best matches the hypothetical "needle" mapping that448* we are searching for in the given "haystack" of mappings.449*/450BasicSourceMapConsumer.prototype._findMapping =451function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,452aColumnName, aComparator, aBias) {453// To return the position we are searching for, we must first find the454// mapping for the given position and then return the opposite position it455// points to. Because the mappings are sorted, we can use binary search to456// find the best mapping.457458if (aNeedle[aLineName] <= 0) {459throw new TypeError('Line must be greater than or equal to 1, got '460+ aNeedle[aLineName]);461}462if (aNeedle[aColumnName] < 0) {463throw new TypeError('Column must be greater than or equal to 0, got '464+ aNeedle[aColumnName]);465}466467return binarySearch.search(aNeedle, aMappings, aComparator, aBias);468};469470/**471* Compute the last column for each generated mapping. The last column is472* inclusive.473*/474BasicSourceMapConsumer.prototype.computeColumnSpans =475function SourceMapConsumer_computeColumnSpans() {476for (var index = 0; index < this._generatedMappings.length; ++index) {477var mapping = this._generatedMappings[index];478479// Mappings do not contain a field for the last generated columnt. We480// can come up with an optimistic estimate, however, by assuming that481// mappings are contiguous (i.e. given two consecutive mappings, the482// first mapping ends where the second one starts).483if (index + 1 < this._generatedMappings.length) {484var nextMapping = this._generatedMappings[index + 1];485486if (mapping.generatedLine === nextMapping.generatedLine) {487mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;488continue;489}490}491492// The last mapping for each line spans the entire line.493mapping.lastGeneratedColumn = Infinity;494}495};496497/**498* Returns the original source, line, and column information for the generated499* source's line and column positions provided. The only argument is an object500* with the following properties:501*502* - line: The line number in the generated source.503* - column: The column number in the generated source.504* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or505* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the506* closest element that is smaller than or greater than the one we are507* searching for, respectively, if the exact element cannot be found.508* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.509*510* and an object is returned with the following properties:511*512* - source: The original source file, or null.513* - line: The line number in the original source, or null.514* - column: The column number in the original source, or null.515* - name: The original identifier, or null.516*/517BasicSourceMapConsumer.prototype.originalPositionFor =518function SourceMapConsumer_originalPositionFor(aArgs) {519var needle = {520generatedLine: util.getArg(aArgs, 'line'),521generatedColumn: util.getArg(aArgs, 'column')522};523524var index = this._findMapping(525needle,526this._generatedMappings,527"generatedLine",528"generatedColumn",529util.compareByGeneratedPositions,530util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)531);532533if (index >= 0) {534var mapping = this._generatedMappings[index];535536if (mapping.generatedLine === needle.generatedLine) {537var source = util.getArg(mapping, 'source', null);538if (source != null && this.sourceRoot != null) {539source = util.join(this.sourceRoot, source);540}541return {542source: source,543line: util.getArg(mapping, 'originalLine', null),544column: util.getArg(mapping, 'originalColumn', null),545name: util.getArg(mapping, 'name', null)546};547}548}549550return {551source: null,552line: null,553column: null,554name: null555};556};557558/**559* Returns the original source content. The only argument is the url of the560* original source file. Returns null if no original source content is561* availible.562*/563BasicSourceMapConsumer.prototype.sourceContentFor =564function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {565if (!this.sourcesContent) {566return null;567}568569if (this.sourceRoot != null) {570aSource = util.relative(this.sourceRoot, aSource);571}572573if (this._sources.has(aSource)) {574return this.sourcesContent[this._sources.indexOf(aSource)];575}576577var url;578if (this.sourceRoot != null579&& (url = util.urlParse(this.sourceRoot))) {580// XXX: file:// URIs and absolute paths lead to unexpected behavior for581// many users. We can help them out when they expect file:// URIs to582// behave like it would if they were running a local HTTP server. See583// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.584var fileUriAbsPath = aSource.replace(/^file:\/\//, "");585if (url.scheme == "file"586&& this._sources.has(fileUriAbsPath)) {587return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]588}589590if ((!url.path || url.path == "/")591&& this._sources.has("/" + aSource)) {592return this.sourcesContent[this._sources.indexOf("/" + aSource)];593}594}595596// This function is used recursively from597// IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we598// don't want to throw if we can't find the source - we just want to599// return null, so we provide a flag to exit gracefully.600if (nullOnMissing) {601return null;602}603else {604throw new Error('"' + aSource + '" is not in the SourceMap.');605}606};607608/**609* Returns the generated line and column information for the original source,610* line, and column positions provided. The only argument is an object with611* the following properties:612*613* - source: The filename of the original source.614* - line: The line number in the original source.615* - column: The column number in the original source.616* - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or617* 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the618* closest element that is smaller than or greater than the one we are619* searching for, respectively, if the exact element cannot be found.620* Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.621*622* and an object is returned with the following properties:623*624* - line: The line number in the generated source, or null.625* - column: The column number in the generated source, or null.626*/627BasicSourceMapConsumer.prototype.generatedPositionFor =628function SourceMapConsumer_generatedPositionFor(aArgs) {629var needle = {630source: util.getArg(aArgs, 'source'),631originalLine: util.getArg(aArgs, 'line'),632originalColumn: util.getArg(aArgs, 'column')633};634635if (this.sourceRoot != null) {636needle.source = util.relative(this.sourceRoot, needle.source);637}638639var index = this._findMapping(640needle,641this._originalMappings,642"originalLine",643"originalColumn",644util.compareByOriginalPositions,645util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)646);647648if (index >= 0) {649var mapping = this._originalMappings[index];650651if (mapping.source === needle.source) {652return {653line: util.getArg(mapping, 'generatedLine', null),654column: util.getArg(mapping, 'generatedColumn', null),655lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)656};657}658}659660return {661line: null,662column: null,663lastColumn: null664};665};666667exports.BasicSourceMapConsumer = BasicSourceMapConsumer;668669/**670* An IndexedSourceMapConsumer instance represents a parsed source map which671* we can query for information. It differs from BasicSourceMapConsumer in672* that it takes "indexed" source maps (i.e. ones with a "sections" field) as673* input.674*675* The only parameter is a raw source map (either as a JSON string, or already676* parsed to an object). According to the spec for indexed source maps, they677* have the following attributes:678*679* - version: Which version of the source map spec this map is following.680* - file: Optional. The generated file this source map is associated with.681* - sections: A list of section definitions.682*683* Each value under the "sections" field has two fields:684* - offset: The offset into the original specified at which this section685* begins to apply, defined as an object with a "line" and "column"686* field.687* - map: A source map definition. This source map could also be indexed,688* but doesn't have to be.689*690* Instead of the "map" field, it's also possible to have a "url" field691* specifying a URL to retrieve a source map from, but that's currently692* unsupported.693*694* Here's an example source map, taken from the source map spec[0], but695* modified to omit a section which uses the "url" field.696*697* {698* version : 3,699* file: "app.js",700* sections: [{701* offset: {line:100, column:10},702* map: {703* version : 3,704* file: "section.js",705* sources: ["foo.js", "bar.js"],706* names: ["src", "maps", "are", "fun"],707* mappings: "AAAA,E;;ABCDE;"708* }709* }],710* }711*712* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt713*/714function IndexedSourceMapConsumer(aSourceMap) {715var sourceMap = aSourceMap;716if (typeof aSourceMap === 'string') {717sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));718}719720var version = util.getArg(sourceMap, 'version');721var sections = util.getArg(sourceMap, 'sections');722723if (version != this._version) {724throw new Error('Unsupported version: ' + version);725}726727var lastOffset = {728line: -1,729column: 0730};731this._sections = sections.map(function (s) {732if (s.url) {733// The url field will require support for asynchronicity.734// See https://github.com/mozilla/source-map/issues/16735throw new Error('Support for url field in sections not implemented.');736}737var offset = util.getArg(s, 'offset');738var offsetLine = util.getArg(offset, 'line');739var offsetColumn = util.getArg(offset, 'column');740741if (offsetLine < lastOffset.line ||742(offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {743throw new Error('Section offsets must be ordered and non-overlapping.');744}745lastOffset = offset;746747return {748generatedOffset: {749// The offset fields are 0-based, but we use 1-based indices when750// encoding/decoding from VLQ.751generatedLine: offsetLine + 1,752generatedColumn: offsetColumn + 1753},754consumer: new SourceMapConsumer(util.getArg(s, 'map'))755}756});757}758759IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);760IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;761762/**763* The version of the source mapping spec that we are consuming.764*/765IndexedSourceMapConsumer.prototype._version = 3;766767/**768* The list of original sources.769*/770Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {771get: function () {772var sources = [];773for (var i = 0; i < this._sections.length; i++) {774for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {775sources.push(this._sections[i].consumer.sources[j]);776}777};778return sources;779}780});781782/**783* Returns the original source, line, and column information for the generated784* source's line and column positions provided. The only argument is an object785* with the following properties:786*787* - line: The line number in the generated source.788* - column: The column number in the generated source.789*790* and an object is returned with the following properties:791*792* - source: The original source file, or null.793* - line: The line number in the original source, or null.794* - column: The column number in the original source, or null.795* - name: The original identifier, or null.796*/797IndexedSourceMapConsumer.prototype.originalPositionFor =798function IndexedSourceMapConsumer_originalPositionFor(aArgs) {799var needle = {800generatedLine: util.getArg(aArgs, 'line'),801generatedColumn: util.getArg(aArgs, 'column')802};803804// Find the section containing the generated position we're trying to map805// to an original position.806var sectionIndex = binarySearch.search(needle, this._sections,807function(needle, section) {808var cmp = needle.generatedLine - section.generatedOffset.generatedLine;809if (cmp) {810return cmp;811}812813return (needle.generatedColumn -814section.generatedOffset.generatedColumn);815});816var section = this._sections[sectionIndex];817818if (!section) {819return {820source: null,821line: null,822column: null,823name: null824};825}826827return section.consumer.originalPositionFor({828line: needle.generatedLine -829(section.generatedOffset.generatedLine - 1),830column: needle.generatedColumn -831(section.generatedOffset.generatedLine === needle.generatedLine832? section.generatedOffset.generatedColumn - 1833: 0),834bias: aArgs.bias835});836};837838/**839* Returns the original source content. The only argument is the url of the840* original source file. Returns null if no original source content is841* available.842*/843IndexedSourceMapConsumer.prototype.sourceContentFor =844function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {845for (var i = 0; i < this._sections.length; i++) {846var section = this._sections[i];847848var content = section.consumer.sourceContentFor(aSource, true);849if (content) {850return content;851}852}853if (nullOnMissing) {854return null;855}856else {857throw new Error('"' + aSource + '" is not in the SourceMap.');858}859};860861/**862* Returns the generated line and column information for the original source,863* line, and column positions provided. The only argument is an object with864* the following properties:865*866* - source: The filename of the original source.867* - line: The line number in the original source.868* - column: The column number in the original source.869*870* and an object is returned with the following properties:871*872* - line: The line number in the generated source, or null.873* - column: The column number in the generated source, or null.874*/875IndexedSourceMapConsumer.prototype.generatedPositionFor =876function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {877for (var i = 0; i < this._sections.length; i++) {878var section = this._sections[i];879880// Only consider this section if the requested source is in the list of881// sources of the consumer.882if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {883continue;884}885var generatedPosition = section.consumer.generatedPositionFor(aArgs);886if (generatedPosition) {887var ret = {888line: generatedPosition.line +889(section.generatedOffset.generatedLine - 1),890column: generatedPosition.column +891(section.generatedOffset.generatedLine === generatedPosition.line892? section.generatedOffset.generatedColumn - 1893: 0)894};895return ret;896}897}898899return {900line: null,901column: null902};903};904905/**906* Parse the mappings in a string in to a data structure which we can easily907* query (the ordered arrays in the `this.__generatedMappings` and908* `this.__originalMappings` properties).909*/910IndexedSourceMapConsumer.prototype._parseMappings =911function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {912this.__generatedMappings = [];913this.__originalMappings = [];914for (var i = 0; i < this._sections.length; i++) {915var section = this._sections[i];916var sectionMappings = section.consumer._generatedMappings;917for (var j = 0; j < sectionMappings.length; j++) {918var mapping = sectionMappings[i];919920var source = mapping.source;921var sourceRoot = section.consumer.sourceRoot;922923if (source != null && sourceRoot != null) {924source = util.join(sourceRoot, source);925}926927// The mappings coming from the consumer for the section have928// generated positions relative to the start of the section, so we929// need to offset them to be relative to the start of the concatenated930// generated file.931var adjustedMapping = {932source: source,933generatedLine: mapping.generatedLine +934(section.generatedOffset.generatedLine - 1),935generatedColumn: mapping.column +936(section.generatedOffset.generatedLine === mapping.generatedLine)937? section.generatedOffset.generatedColumn - 1938: 0,939originalLine: mapping.originalLine,940originalColumn: mapping.originalColumn,941name: mapping.name942};943944this.__generatedMappings.push(adjustedMapping);945if (typeof adjustedMapping.originalLine === 'number') {946this.__originalMappings.push(adjustedMapping);947}948};949};950951this.__generatedMappings.sort(util.compareByGeneratedPositions);952this.__originalMappings.sort(util.compareByOriginalPositions);953};954955exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;956957});958959960