be careful about a null url for data URLs

This commit is contained in:
Evan Wallace 2014-04-26 12:24:31 -07:00
parent 7fa445e16f
commit 649da9a3e5
2 changed files with 12 additions and 4 deletions

View File

@ -46,6 +46,7 @@ function retrieveFile(path) {
// Support URLs relative to a directory, but be careful about a protocol prefix
// in case we are in the browser (i.e. directories may start with "http://")
function supportRelativeURL(file, url) {
if (!file) return url;
var dir = path.dirname(file);
var match = /^\w+:\/\/[^\/]*/.exec(dir);
var protocol = match ? match[0] : '';
@ -122,10 +123,8 @@ function mapSourcePosition(position) {
// better to give a precise location in the compiled file than a vague
// location in the original file.
if (originalPosition.source !== null) {
if (sourceMap.url) {
originalPosition.source = supportRelativeURL(
sourceMap.url, originalPosition.source);
}
originalPosition.source = supportRelativeURL(
sourceMap.url, originalPosition.source);
return originalPosition;
}
}

View File

@ -241,6 +241,15 @@ it('throw with source map with gap', function() {
]);
});
it('sourcesContent with data URL', function() {
compareStackTrace(createMultiLineSourceMapWithSourcesContent(), [
'throw new Error("test");'
], [
'Error: test',
/^ at Object\.exports\.test \(.*\/original.js:1001:5\)$/
]);
});
it('default options', function(done) {
compareStdout(done, createSingleLineSourceMap(), [
'',