Skip to content

Commit

Permalink
issue-363: cleaned up commentFormatter code to handle css correctly o…
Browse files Browse the repository at this point in the history
…n preExisting
  • Loading branch information
nmccready committed Feb 7, 2019
1 parent 5a99012 commit 05c859c
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ So we either need to use a new instance of a regex everywhere.
*/
var sourceMapUrlRegEx = function(){ return /\/\/\# sourceMappingURL\=.*/g;};

var commentFormatters = {
css: function cssCommentFormatter(preLine, newline, url) {
return preLine + "/*# sourceMappingURL=" + url + " */" + newline;
},
js: function jsCommentFormatter(preLine, newline, url) {
return preLine + "//# sourceMappingURL=" + url + newline;
},
'default': function defaultFormatter() {
return '';
}
}


var getCommentFormatter = function (file) {
var extension = file.relative.split('.').pop(),
fileContents = file.contents.toString(),
newline = detectNewline.graceful(fileContents || ''),
newlinePre = newline,
commentFormatter = function(url) {
return '';
};
fileContents = file.contents.toString(),
newline = detectNewline.graceful(fileContents || '');

if (file.sourceMap.preExistingComment){
debug(function() { return 'preExistingComment commentFormatter'; });
newlinePre = '';
}
var commentFormatter = commentFormatters.default;

switch (extension) {
case 'css':
debug(function() { return 'css commentFormatter';});
commentFormatter = function(url) {
return newlinePre + "/*# sourceMappingURL=" + url + " */" + newline;
};
break;
case 'js':
debug(function() { return 'js commentFormatter'; });
commentFormatter = function(url) {
return newlinePre + "//# sourceMappingURL=" + url + newline;
};
break;
default:
debug(function() { return 'unknown commentFormatter'; });
if (file.sourceMap.preExistingComment) {
commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, '', newline)
debug(function () {
return 'preExistingComment commentFormatter ' + commentFormatter.name;
});
} else {
commentFormatter = (commentFormatters[extension] || commentFormatter).bind(undefined, newline, newline);
}

debug(function () {
return 'commentFormatter ' + commentFormatter.name;
});
return commentFormatter;
};

Expand Down

0 comments on commit 05c859c

Please sign in to comment.