Skip to content

Commit 1d77c0b

Browse files
authored
Merge pull request #289 from tromey/m-c-fixes
M-C fixes
2 parents 83d389f + 2c6fb7e commit 1d77c0b

11 files changed

+422
-252
lines changed

dist/source-map.debug.js

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,8 +1448,8 @@ return /******/ (function(modules) { // webpackBootstrap
14481448
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
14491449
}
14501450

1451-
SourceMapConsumer.fromSourceMap = function(aSourceMap) {
1452-
return BasicSourceMapConsumer.fromSourceMap(aSourceMap);
1451+
SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
1452+
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
14531453
}
14541454

14551455
/**
@@ -1619,13 +1619,10 @@ return /******/ (function(modules) { // webpackBootstrap
16191619
originalColumn: util.getArg(aArgs, 'column', 0)
16201620
};
16211621

1622-
if (this.sourceRoot != null) {
1623-
needle.source = util.relative(this.sourceRoot, needle.source);
1624-
}
1625-
if (!this._sources.has(needle.source)) {
1622+
needle.source = this._findSourceIndex(needle.source);
1623+
if (needle.source < 0) {
16261624
return [];
16271625
}
1628-
needle.source = this._sources.indexOf(needle.source);
16291626

16301627
var mappings = [];
16311628

@@ -1763,6 +1760,10 @@ return /******/ (function(modules) { // webpackBootstrap
17631760
this._names = ArraySet.fromArray(names.map(String), true);
17641761
this._sources = ArraySet.fromArray(sources, true);
17651762

1763+
this._absoluteSources = this._sources.toArray().map(function (s) {
1764+
return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
1765+
});
1766+
17661767
this.sourceRoot = sourceRoot;
17671768
this.sourcesContent = sourcesContent;
17681769
this._mappings = mappings;
@@ -1773,6 +1774,32 @@ return /******/ (function(modules) { // webpackBootstrap
17731774
BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
17741775
BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
17751776

1777+
/**
1778+
* Utility function to find the index of a source. Returns -1 if not
1779+
* found.
1780+
*/
1781+
BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
1782+
var relativeSource = aSource;
1783+
if (this.sourceRoot != null) {
1784+
relativeSource = util.relative(this.sourceRoot, relativeSource);
1785+
}
1786+
1787+
if (this._sources.has(relativeSource)) {
1788+
return this._sources.indexOf(relativeSource);
1789+
}
1790+
1791+
// Maybe aSource is an absolute URL as returned by |sources|. In
1792+
// this case we can't simply undo the transform.
1793+
var i;
1794+
for (i = 0; i < this._absoluteSources.length; ++i) {
1795+
if (this._absoluteSources[i] == aSource) {
1796+
return i;
1797+
}
1798+
}
1799+
1800+
return -1;
1801+
};
1802+
17761803
/**
17771804
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
17781805
*
@@ -1793,6 +1820,9 @@ return /******/ (function(modules) { // webpackBootstrap
17931820
smc.sourceRoot);
17941821
smc.file = aSourceMap._file;
17951822
smc._sourceMapURL = aSourceMapURL;
1823+
smc._absoluteSources = smc._sources.toArray().map(function (s) {
1824+
return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
1825+
});
17961826

17971827
// Because we are modifying the entries (by converting string sources and
17981828
// names to indices into the sources and names ArraySets), we have to make
@@ -1839,9 +1869,7 @@ return /******/ (function(modules) { // webpackBootstrap
18391869
*/
18401870
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
18411871
get: function () {
1842-
return this._sources.toArray().map(function (s) {
1843-
return util.computeSourceURL(this.sourceRoot, s, this._sourceMapURL);
1844-
}, this);
1872+
return this._absoluteSources.slice();
18451873
}
18461874
});
18471875

@@ -2111,25 +2139,16 @@ return /******/ (function(modules) { // webpackBootstrap
21112139
return null;
21122140
}
21132141

2142+
var index = this._findSourceIndex(aSource);
2143+
if (index >= 0) {
2144+
return this.sourcesContent[index];
2145+
}
2146+
21142147
var relativeSource = aSource;
21152148
if (this.sourceRoot != null) {
21162149
relativeSource = util.relative(this.sourceRoot, relativeSource);
21172150
}
21182151

2119-
if (this._sources.has(relativeSource)) {
2120-
return this.sourcesContent[this._sources.indexOf(relativeSource)];
2121-
}
2122-
2123-
// Maybe aSource is an absolute URL as returned by |sources|. In
2124-
// this case we can't simply undo the transform.
2125-
var sourceArray = this.sources;
2126-
var i;
2127-
for (i = 0; i < sourceArray.length; ++i) {
2128-
if (sourceArray[i] == aSource) {
2129-
return this.sourcesContent[i];
2130-
}
2131-
}
2132-
21332152
var url;
21342153
if (this.sourceRoot != null
21352154
&& (url = util.urlParse(this.sourceRoot))) {
@@ -2187,17 +2206,14 @@ return /******/ (function(modules) { // webpackBootstrap
21872206
BasicSourceMapConsumer.prototype.generatedPositionFor =
21882207
function SourceMapConsumer_generatedPositionFor(aArgs) {
21892208
var source = util.getArg(aArgs, 'source');
2190-
if (this.sourceRoot != null) {
2191-
source = util.relative(this.sourceRoot, source);
2192-
}
2193-
if (!this._sources.has(source)) {
2209+
source = this._findSourceIndex(source);
2210+
if (source < 0) {
21942211
return {
21952212
line: null,
21962213
column: null,
21972214
lastColumn: null
21982215
};
21992216
}
2200-
source = this._sources.indexOf(source);
22012217

22022218
var needle = {
22032219
source: source,
@@ -2474,7 +2490,7 @@ return /******/ (function(modules) { // webpackBootstrap
24742490

24752491
// Only consider this section if the requested source is in the list of
24762492
// sources of the consumer.
2477-
if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {
2493+
if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
24782494
continue;
24792495
}
24802496
var generatedPosition = section.consumer.generatedPositionFor(aArgs);

dist/source-map.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/source-map.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_api.js

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_dog_fooding.js

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_map_consumer.js

Lines changed: 70 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_map_generator.js

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/test/test_source_node.js

Lines changed: 47 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/source-map-consumer.js

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ function SourceMapConsumer(aSourceMap, aSourceMapURL) {
2222
: new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
2323
}
2424

25-
SourceMapConsumer.fromSourceMap = function(aSourceMap) {
26-
return BasicSourceMapConsumer.fromSourceMap(aSourceMap);
25+
SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) {
26+
return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
2727
}
2828

2929
/**
@@ -193,13 +193,10 @@ SourceMapConsumer.prototype.allGeneratedPositionsFor =
193193
originalColumn: util.getArg(aArgs, 'column', 0)
194194
};
195195

196-
if (this.sourceRoot != null) {
197-
needle.source = util.relative(this.sourceRoot, needle.source);
198-
}
199-
if (!this._sources.has(needle.source)) {
196+
needle.source = this._findSourceIndex(needle.source);
197+
if (needle.source < 0) {
200198
return [];
201199
}
202-
needle.source = this._sources.indexOf(needle.source);
203200

204201
var mappings = [];
205202

@@ -337,6 +334,10 @@ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
337334
this._names = ArraySet.fromArray(names.map(String), true);
338335
this._sources = ArraySet.fromArray(sources, true);
339336

337+
this._absoluteSources = this._sources.toArray().map(function (s) {
338+
return util.computeSourceURL(sourceRoot, s, aSourceMapURL);
339+
});
340+
340341
this.sourceRoot = sourceRoot;
341342
this.sourcesContent = sourcesContent;
342343
this._mappings = mappings;
@@ -347,6 +348,32 @@ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
347348
BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
348349
BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
349350

351+
/**
352+
* Utility function to find the index of a source. Returns -1 if not
353+
* found.
354+
*/
355+
BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
356+
var relativeSource = aSource;
357+
if (this.sourceRoot != null) {
358+
relativeSource = util.relative(this.sourceRoot, relativeSource);
359+
}
360+
361+
if (this._sources.has(relativeSource)) {
362+
return this._sources.indexOf(relativeSource);
363+
}
364+
365+
// Maybe aSource is an absolute URL as returned by |sources|. In
366+
// this case we can't simply undo the transform.
367+
var i;
368+
for (i = 0; i < this._absoluteSources.length; ++i) {
369+
if (this._absoluteSources[i] == aSource) {
370+
return i;
371+
}
372+
}
373+
374+
return -1;
375+
};
376+
350377
/**
351378
* Create a BasicSourceMapConsumer from a SourceMapGenerator.
352379
*
@@ -367,6 +394,9 @@ BasicSourceMapConsumer.fromSourceMap =
367394
smc.sourceRoot);
368395
smc.file = aSourceMap._file;
369396
smc._sourceMapURL = aSourceMapURL;
397+
smc._absoluteSources = smc._sources.toArray().map(function (s) {
398+
return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
399+
});
370400

371401
// Because we are modifying the entries (by converting string sources and
372402
// names to indices into the sources and names ArraySets), we have to make
@@ -413,9 +443,7 @@ BasicSourceMapConsumer.prototype._version = 3;
413443
*/
414444
Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
415445
get: function () {
416-
return this._sources.toArray().map(function (s) {
417-
return util.computeSourceURL(this.sourceRoot, s, this._sourceMapURL);
418-
}, this);
446+
return this._absoluteSources.slice();
419447
}
420448
});
421449

@@ -685,25 +713,16 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
685713
return null;
686714
}
687715

716+
var index = this._findSourceIndex(aSource);
717+
if (index >= 0) {
718+
return this.sourcesContent[index];
719+
}
720+
688721
var relativeSource = aSource;
689722
if (this.sourceRoot != null) {
690723
relativeSource = util.relative(this.sourceRoot, relativeSource);
691724
}
692725

693-
if (this._sources.has(relativeSource)) {
694-
return this.sourcesContent[this._sources.indexOf(relativeSource)];
695-
}
696-
697-
// Maybe aSource is an absolute URL as returned by |sources|. In
698-
// this case we can't simply undo the transform.
699-
var sourceArray = this.sources;
700-
var i;
701-
for (i = 0; i < sourceArray.length; ++i) {
702-
if (sourceArray[i] == aSource) {
703-
return this.sourcesContent[i];
704-
}
705-
}
706-
707726
var url;
708727
if (this.sourceRoot != null
709728
&& (url = util.urlParse(this.sourceRoot))) {
@@ -761,17 +780,14 @@ BasicSourceMapConsumer.prototype.sourceContentFor =
761780
BasicSourceMapConsumer.prototype.generatedPositionFor =
762781
function SourceMapConsumer_generatedPositionFor(aArgs) {
763782
var source = util.getArg(aArgs, 'source');
764-
if (this.sourceRoot != null) {
765-
source = util.relative(this.sourceRoot, source);
766-
}
767-
if (!this._sources.has(source)) {
783+
source = this._findSourceIndex(source);
784+
if (source < 0) {
768785
return {
769786
line: null,
770787
column: null,
771788
lastColumn: null
772789
};
773790
}
774-
source = this._sources.indexOf(source);
775791

776792
var needle = {
777793
source: source,
@@ -1048,7 +1064,7 @@ IndexedSourceMapConsumer.prototype.generatedPositionFor =
10481064

10491065
// Only consider this section if the requested source is in the list of
10501066
// sources of the consumer.
1051-
if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {
1067+
if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) {
10521068
continue;
10531069
}
10541070
var generatedPosition = section.consumer.generatedPositionFor(aArgs);

0 commit comments

Comments
 (0)