Skip to content

Commit

Permalink
Merge pull request #145 from jryans/rel-prefix
Browse files Browse the repository at this point in the history
Allow ./ prefix in source paths
  • Loading branch information
fitzgen committed Dec 17, 2014
2 parents 93373db + ad8c075 commit 599769d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/source-map/source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ define(function (require, exports, module) {
throw new Error('Unsupported version: ' + version);
}

// 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.
sources = sources.map(util.normalize);

// Pass `true` below to allow duplicate names and sources. While source maps
// are intended to be compressed and deduplicated, the TypeScript compiler
// sometimes generates source maps with duplicates in them. See Github issue
Expand Down
19 changes: 19 additions & 0 deletions test/source-map/test-source-map-consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ define(function (require, exports, module) {
}, Error);
};

exports['test that we can get the original source content with relative source paths'] = function (assert, util) {
var map = new SourceMapConsumer(util.testMapRelativeSources);
var sources = map.sources;

assert.equal(map.sourceContentFor(sources[0]), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor(sources[1]), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.equal(map.sourceContentFor("one.js"), ' ONE.foo = function (bar) {\n return baz(bar);\n };');
assert.equal(map.sourceContentFor("two.js"), ' TWO.inc = function (n) {\n return n + 1;\n };');
assert.throws(function () {
map.sourceContentFor("");
}, Error);
assert.throws(function () {
map.sourceContentFor("/the/root/three.js");
}, Error);
assert.throws(function () {
map.sourceContentFor("three.js");
}, Error);
};

exports['test sourceRoot + generatedPositionFor'] = function (assert, util) {
var map = new SourceMapGenerator({
sourceRoot: 'foo/bar',
Expand Down
16 changes: 16 additions & 0 deletions test/source-map/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ define(function (require, exports, module) {
sourceRoot: '/the/root',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
exports.testMapRelativeSources = {
version: 3,
file: 'min.js',
names: ['bar', 'baz', 'n'],
sources: ['./one.js', './two.js'],
sourcesContent: [
' ONE.foo = function (bar) {\n' +
' return baz(bar);\n' +
' };',
' TWO.inc = function (n) {\n' +
' return n + 1;\n' +
' };'
],
sourceRoot: '/the/root',
mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
exports.emptyMap = {
version: 3,
file: 'min.js',
Expand Down

0 comments on commit 599769d

Please sign in to comment.