Skip to content

Commit

Permalink
Update: Use extname for commentFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Jun 17, 2017
1 parent 7cdb9e2 commit f2ea47c
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,14 @@ function createSourceMapFile(opts) {
});
}

// TODO: any way to make this function not require file?
function commentFormatter(file, url) {
function commentFormatter(extname, url) {
// TODO: Not sure I agree with this
if (file.extname !== '.js' && file.extname !== '.css') {
if (extname !== '.js' && extname !== '.css') {
return '';
}

var opts = {
multiline: (file.extname === '.css')
multiline: (extname === '.css')
};

return convert.generateMapFileComment(url, opts);
Expand Down Expand Up @@ -251,7 +250,7 @@ function contentIncluded(file, state, options, callback) {
// encode source map into comment
var base64Map = convert.fromObject(state.sourceMap).toBase64();
// TODO: use convert-source-map .toComment() when we upgrade and have charset support
comment = commentFormatter(file, 'data:application/json;charset=utf8;base64,' + base64Map);
comment = commentFormatter(file.extname, 'data:application/json;charset=utf8;base64,' + base64Map);
} else {
var mapFile = path.join(state.destPath, file.relative) + '.map';

Expand Down Expand Up @@ -292,15 +291,15 @@ function contentIncluded(file, state, options, callback) {
}

if (!isRemoteSource(sourceMapPathRelative)) {
comment = commentFormatter(file, normalizePath(sourceMapPathRelative));
comment = commentFormatter(file.extname, normalizePath(sourceMapPathRelative));
} else {
comment = commentFormatter(file, sourceMapPathRelative);
comment = commentFormatter(file.extname, sourceMapPathRelative);
}

// A function option here would have already been resolved higher up
// TODO: need a test for this as a string
if (options.sourceMappingURL) {
comment = commentFormatter(file, options.sourceMappingURL);
comment = commentFormatter(file.extname, options.sourceMappingURL);
}
}

Expand Down

0 comments on commit f2ea47c

Please sign in to comment.