Skip to content

Commit

Permalink
Merge pull request #236 from fitzgen/more-numbers-where-we-should-hav…
Browse files Browse the repository at this point in the history
…e-strings

Ensure that sources and names are non-numeric when consuming source maps
  • Loading branch information
fitzgen committed May 2, 2016
2 parents 8ff9aaa + 182f445 commit 7bc77b0
Show file tree
Hide file tree
Showing 12 changed files with 106 additions and 32 deletions.
12 changes: 8 additions & 4 deletions dist/source-map.debug.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions dist/source-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ return /******/ (function(modules) { // webpackBootstrap
this._validateMapping(generated, original, source, name);
}

if (source != null && !this._sources.has(source)) {
this._sources.add(source);
if (source != null) {
source = String(source);
if (!this._sources.has(source)) {
this._sources.add(source);
}
}

if (name != null) {
Expand Down Expand Up @@ -1616,6 +1619,7 @@ return /******/ (function(modules) { // webpackBootstrap
}

sources = sources
.map(String)
// Some source maps produce relative source paths like "./foo.js" instead of
// "foo.js". Normalize these first so that future comparisons will succeed.
// See bugzil.la/1090768.
Expand All @@ -1634,7 +1638,7 @@ return /******/ (function(modules) { // webpackBootstrap
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
// #72 and bugzil.la/889492.
this._names = ArraySet.fromArray(names, true);
this._names = ArraySet.fromArray(names.map(String), true);
this._sources = ArraySet.fromArray(sources, true);

this.sourceRoot = sourceRoot;
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.

12 changes: 8 additions & 4 deletions dist/test/test_api.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/test/test_dog_fooding.js

Large diffs are not rendered by default.

33 changes: 29 additions & 4 deletions dist/test/test_source_map_consumer.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/test/test_source_map_generator.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions dist/test/test_source_node.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ function BasicSourceMapConsumer(aSourceMap) {
}

sources = sources
.map(String)
// Some source maps produce relative source paths like "./foo.js" instead of
// "foo.js". Normalize these first so that future comparisons will succeed.
// See bugzil.la/1090768.
Expand All @@ -320,7 +321,7 @@ function BasicSourceMapConsumer(aSourceMap) {
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
// #72 and bugzil.la/889492.
this._names = ArraySet.fromArray(names, true);
this._names = ArraySet.fromArray(names.map(String), true);
this._sources = ArraySet.fromArray(sources, true);

this.sourceRoot = sourceRoot;
Expand Down
7 changes: 5 additions & 2 deletions lib/source-map-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ SourceMapGenerator.prototype.addMapping =
this._validateMapping(generated, original, source, name);
}

if (source != null && !this._sources.has(source)) {
this._sources.add(source);
if (source != null) {
source = String(source);
if (!this._sources.has(source)) {
this._sources.add(source);
}
}

if (name != null) {
Expand Down
21 changes: 21 additions & 0 deletions test/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1098,3 +1098,24 @@ exports['test sources where their prefix is the source root and the source root
consumer.sources.forEach(consumerHasSource);
testSourceMap.sources.forEach(consumerHasSource);
};

exports['test consuming names and sources that are numbers'] = function (assert) {
var testSourceMap = {
"version": 3,
"sources": [0],
"names": [1],
"mappings": "AAAAA",
};

var consumer = new SourceMapConsumer(testSourceMap);

assert.equal(consumer.sources.length, 1);
assert.equal(consumer.sources[0], "0");

var i = 0;
consumer.eachMapping(function (m) {
i++;
assert.equal(m.name, "1");
});
assert.equal(i, 1);
};

0 comments on commit 7bc77b0

Please sign in to comment.