Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 97 additions & 27 deletions dist/source-map.debug.js

Large diffs are not rendered by default.

122 changes: 96 additions & 26 deletions dist/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,59 @@ return /******/ (function(modules) { // webpackBootstrap
}
exports.parseSourceMapInput = parseSourceMapInput;

/**
* Compute the URL of a source given the the source root, the source's
* URL, and the source map's URL.
*/
function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
sourceURL = sourceURL || '';

if (sourceRoot) {
// This follows what Chrome does.
if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
sourceRoot += '/';
}
// The spec says:
// Line 4: An optional source root, useful for relocating source
// files on a server or removing repeated values in the
// “sources” entry. This value is prepended to the individual
// entries in the “source” field.
sourceURL = sourceRoot + sourceURL;
}

// Historically, SourceMapConsumer did not take the sourceMapURL as
// a parameter. This mode is still somewhat supported, which is why
// this code block is conditional. However, it's preferable to pass
// the source map URL to SourceMapConsumer, so that this function
// can implement the source URL resolution algorithm as outlined in
// the spec. This block is basically the equivalent of:
// new URL(sourceURL, sourceMapURL).toString()
// ... except it avoids using URL, which wasn't available in the
// older releases of node still supported by this library.
//
// The spec says:
// If the sources are not absolute URLs after prepending of the
// “sourceRoot”, the sources are resolved relative to the
// SourceMap (like resolving script src in a html document).
if (sourceMapURL) {
var parsed = urlParse(sourceMapURL);
if (!parsed) {
throw new Error("sourceMapURL could not be parsed");
}
if (parsed.path) {
// Strip the last path component, but keep the "/".
var index = parsed.path.lastIndexOf('/');
if (index >= 0) {
parsed.path = parsed.path.substring(0, index + 1);
}
}
sourceURL = join(urlGenerate(parsed), sourceURL);
}

return normalize(sourceURL);
}
exports.computeSourceURL = computeSourceURL;


/***/ }),
/* 5 */
Expand Down Expand Up @@ -1384,15 +1437,15 @@ return /******/ (function(modules) { // webpackBootstrap
var base64VLQ = __webpack_require__(2);
var quickSort = __webpack_require__(9).quickSort;

function SourceMapConsumer(aSourceMap) {
function SourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
}

return sourceMap.sections != null
? new IndexedSourceMapConsumer(sourceMap)
: new BasicSourceMapConsumer(sourceMap);
? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
}

SourceMapConsumer.fromSourceMap = function(aSourceMap) {
Expand Down Expand Up @@ -1518,9 +1571,7 @@ return /******/ (function(modules) { // webpackBootstrap
var sourceRoot = this.sourceRoot;
mappings.map(function (mapping) {
var source = mapping.source === null ? null : this._sources.at(mapping.source);
if (source != null && sourceRoot != null) {
source = util.join(sourceRoot, source);
}
source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL);
return {
source: source,
generatedLine: mapping.generatedLine,
Expand Down Expand Up @@ -1634,7 +1685,7 @@ return /******/ (function(modules) { // webpackBootstrap
* query for information about the original file positions by giving it a file
* position in the generated source.
*
* The only parameter is the raw source map (either as a JSON string, or
* The first parameter is the raw source map (either as a JSON string, or
* already parsed to an object). According to the spec, source maps have the
* following attributes:
*
Expand All @@ -1657,9 +1708,13 @@ return /******/ (function(modules) { // webpackBootstrap
* mappings: "AA,AB;;ABCDE;"
* }
*
* The second parameter, if given, is a string whose value is the URL
* at which the source map was found. This URL is used to compute the
* sources array.
*
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
*/
function BasicSourceMapConsumer(aSourceMap) {
function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
Expand Down Expand Up @@ -1711,6 +1766,7 @@ return /******/ (function(modules) { // webpackBootstrap
this.sourceRoot = sourceRoot;
this.sourcesContent = sourcesContent;
this._mappings = mappings;
this._sourceMapURL = aSourceMapURL;
this.file = file;
}

Expand All @@ -1722,10 +1778,12 @@ return /******/ (function(modules) { // webpackBootstrap
*
* @param SourceMapGenerator aSourceMap
* The source map that will be consumed.
* @param String aSourceMapURL
* The URL at which the source map can be found (optional)
* @returns BasicSourceMapConsumer
*/
BasicSourceMapConsumer.fromSourceMap =
function SourceMapConsumer_fromSourceMap(aSourceMap) {
function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
var smc = Object.create(BasicSourceMapConsumer.prototype);

var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
Expand All @@ -1734,6 +1792,7 @@ return /******/ (function(modules) { // webpackBootstrap
smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
smc.sourceRoot);
smc.file = aSourceMap._file;
smc._sourceMapURL = aSourceMapURL;

// Because we are modifying the entries (by converting string sources and
// names to indices into the sources and names ArraySets), we have to make
Expand Down Expand Up @@ -1781,7 +1840,7 @@ return /******/ (function(modules) { // webpackBootstrap
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
get: function () {
return this._sources.toArray().map(function (s) {
return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;
return util.computeSourceURL(this.sourceRoot, s, this._sourceMapURL);
}, this);
}
});
Expand Down Expand Up @@ -2005,9 +2064,7 @@ return /******/ (function(modules) { // webpackBootstrap
var source = util.getArg(mapping, 'source', null);
if (source !== null) {
source = this._sources.at(source);
if (this.sourceRoot != null) {
source = util.join(this.sourceRoot, source);
}
source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
}
var name = util.getArg(mapping, 'name', null);
if (name !== null) {
Expand Down Expand Up @@ -2054,12 +2111,23 @@ return /******/ (function(modules) { // webpackBootstrap
return null;
}

var relativeSource = aSource;
if (this.sourceRoot != null) {
aSource = util.relative(this.sourceRoot, aSource);
relativeSource = util.relative(this.sourceRoot, relativeSource);
}

if (this._sources.has(relativeSource)) {
return this.sourcesContent[this._sources.indexOf(relativeSource)];
}

if (this._sources.has(aSource)) {
return this.sourcesContent[this._sources.indexOf(aSource)];
// Maybe aSource is an absolute URL as returned by |sources|. In
// this case we can't simply undo the transform.
var sourceArray = this.sources;
var i;
for (i = 0; i < sourceArray.length; ++i) {
if (sourceArray[i] == aSource) {
return this.sourcesContent[i];
}
}

var url;
Expand All @@ -2069,15 +2137,15 @@ return /******/ (function(modules) { // webpackBootstrap
// many users. We can help them out when they expect file:// URIs to
// behave like it would if they were running a local HTTP server. See
// https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
if (url.scheme == "file"
&& this._sources.has(fileUriAbsPath)) {
return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
}

if ((!url.path || url.path == "/")
&& this._sources.has("/" + aSource)) {
return this.sourcesContent[this._sources.indexOf("/" + aSource)];
&& this._sources.has("/" + relativeSource)) {
return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
}
}

Expand All @@ -2089,7 +2157,7 @@ return /******/ (function(modules) { // webpackBootstrap
return null;
}
else {
throw new Error('"' + aSource + '" is not in the SourceMap.');
throw new Error('"' + relativeSource + '" is not in the SourceMap.');
}
};

Expand Down Expand Up @@ -2173,7 +2241,7 @@ return /******/ (function(modules) { // webpackBootstrap
* that it takes "indexed" source maps (i.e. ones with a "sections" field) as
* input.
*
* The only parameter is a raw source map (either as a JSON string, or already
* The first parameter is a raw source map (either as a JSON string, or already
* parsed to an object). According to the spec for indexed source maps, they
* have the following attributes:
*
Expand Down Expand Up @@ -2210,9 +2278,13 @@ return /******/ (function(modules) { // webpackBootstrap
* }],
* }
*
* The second parameter, if given, is a string whose value is the URL
* at which the source map was found. This URL is used to compute the
* sources array.
*
* [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
*/
function IndexedSourceMapConsumer(aSourceMap) {
function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
var sourceMap = aSourceMap;
if (typeof aSourceMap === 'string') {
sourceMap = util.parseSourceMapInput(aSourceMap);
Expand Down Expand Up @@ -2255,7 +2327,7 @@ return /******/ (function(modules) { // webpackBootstrap
generatedLine: offsetLine + 1,
generatedColumn: offsetColumn + 1
},
consumer: new SourceMapConsumer(util.getArg(s, 'map'))
consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL)
}
});
}
Expand Down Expand Up @@ -2441,9 +2513,7 @@ return /******/ (function(modules) { // webpackBootstrap
var mapping = sectionMappings[j];

var source = section.consumer._sources.at(mapping.source);
if (section.consumer.sourceRoot !== null) {
source = util.join(section.consumer.sourceRoot, source);
}
source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
this._sources.add(source);
source = this._sources.indexOf(source);

Expand Down
2 changes: 1 addition & 1 deletion dist/source-map.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/source-map.min.js.map

Large diffs are not rendered by default.

Loading