fixed data-url bugs and added tests, closes #14

This commit is contained in:
Evan Wallace 2013-06-26 22:51:13 -07:00
parent 77d1b5c05b
commit 2c7e1ce87a
3 changed files with 18 additions and 4 deletions

View File

@ -1,7 +1,7 @@
{
"name": "source-map-support",
"description": "Fixes stack traces for files with source maps",
"version": "0.1.6",
"version": "0.1.7",
"main": "./source-map-support.js",
"scripts": {
"test": "node_modules/mocha/bin/mocha"

View File

@ -11,9 +11,9 @@ exports.mapSourcePosition = mapSourcePosition = function(cache, position) {
if (!match) return position;
var sourceMappingURL = match[1];
// Read the contents of the source map
var sourceMapData;
var dataUrlPrefix = "data:application/json,base64,";
var dataUrlPrefix = "data:application/json;base64,";
if (sourceMappingURL.slice(0, dataUrlPrefix.length).toLowerCase() == dataUrlPrefix) {
// Support source map URL as a data url
sourceMapData = new Buffer(sourceMappingURL.slice(dataUrlPrefix.length), "base64").toString();
@ -28,7 +28,7 @@ exports.mapSourcePosition = mapSourcePosition = function(cache, position) {
}
}
if (sourceMapDat) {
if (sourceMapData) {
sourceMap = {
url: sourceMappingURL,
map: new SourceMapConsumer(sourceMapData)

14
test.js
View File

@ -29,6 +29,8 @@ function compareStackTrace(source, expected) {
source: 'line' + i + '.js'
});
}
// Check once with a separate source map
fs.writeFileSync('.generated.js.map', sourceMap);
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
source.join('\n') + '};//@ sourceMappingURL=.generated.js.map');
@ -40,6 +42,18 @@ function compareStackTrace(source, expected) {
}
fs.unlinkSync('.generated.js');
fs.unlinkSync('.generated.js.map');
// Check again with an inline source map (in a data URL)
fs.writeFileSync('.generated.js', 'exports.test = function() {' +
source.join('\n') + '};//@ sourceMappingURL=data:application/json;base64,' +
new Buffer(sourceMap.toString()).toString('base64'));
try {
delete require.cache[require.resolve('./.generated')];
require('./.generated').test();
} catch (e) {
compareLines(e.stack.split('\n'), expected);
}
fs.unlinkSync('.generated.js');
}
function compareStdout(done, source, expected) {