From 649da9a3e5339d621181ff37e0b6aa46b3d52a6b Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Sat, 26 Apr 2014 12:24:31 -0700 Subject: [PATCH] be careful about a null url for data URLs --- source-map-support.js | 7 +++---- test.js | 9 +++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source-map-support.js b/source-map-support.js index 45d824c..7ef6a56 100644 --- a/source-map-support.js +++ b/source-map-support.js @@ -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; } } diff --git a/test.js b/test.js index ec016f8..8b3fbf3 100644 --- a/test.js +++ b/test.js @@ -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(), [ '',