Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use RegExp to extract sourcemap #20

Merged
merged 1 commit into from Oct 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions index.js
Expand Up @@ -11,17 +11,15 @@ var createSourceMapLocatorPreprocessor = function(args, logger, helper) {
}

function inlineMap(inlineData){
var data;
var b64Match = inlineData.match(/^data:.+\/(.+);base64,(.*)$/);
if (b64Match !== null && b64Match.length == 3) {
if (/^;base64,/.test(inlineData)) {
// base64-encoded JSON string
log.debug('base64-encoded source map for', file.originalPath);
var buffer = new Buffer(b64Match[2], 'base64');
var buffer = new Buffer(inlineData.slice(';base64,'.length), 'base64');
sourceMapData(buffer.toString());
} else {
// straight-up URL-encoded JSON string
log.debug('raw inline source map for', file.originalPath);
sourceMapData(decodeURIComponent(inlineData.slice('data:application/json'.length)));
sourceMapData(decodeURIComponent(inlineData));
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed in the caller


Expand Down Expand Up @@ -51,7 +49,7 @@ var createSourceMapLocatorPreprocessor = function(args, logger, helper) {
if (!mapUrl) {
fileMap(file.path + ".map");
} else if (/^data:application\/json/.test(mapUrl)) {
inlineMap(mapUrl);
inlineMap(mapUrl.slice('data:application/json'.length));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The start was only used in the regexp in inlineMap, so not interesting and can be discarded

} else {
fileMap(path.resolve(path.dirname(file.path), mapUrl));
}
Expand Down