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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper comment format for css with pre-existing comment. #364

Closed
wants to merge 1 commit into from
Closed

Use proper comment format for css with pre-existing comment. #364

wants to merge 1 commit into from

Conversation

coreyfarrell
Copy link
Contributor

If a pre-existing sourceMappingURL comment is loaded the write process
always used .js format without a preceding line-feed. This alters the
logic so sources with pre-existing sourceMappingURL is written with the
correct type of comment for the output file.

Fixes #363

If a pre-existing sourceMappingURL comment is loaded the write process
always used `.js` format without a preceding line-feed.  This alters the
logic so sources with pre-existing sourceMappingURL is written with the
correct type of comment for the output file.

Fixes #363
@coreyfarrell
Copy link
Contributor Author

I think the drop in coverage is due to removal of lines. In theory we should add a test for css with existing coverage map, though I'm unsure how to create such a test file.

@benjclark
Copy link

Have just tested this and looks good to me! 🎉 Thank you

commentFormatter = function(url) {
return '';
};

if (file.sourceMap.preExistingComment){
debug(function() { return 'preExistingComment commentFormatter'; });
commentFormatter = function(url) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a major change, I need to look into what the preExistingComment handle was for. But your no longer returning a function here. Seems like we're missing a test that needs to exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For current code preExistingComment prevents returning a string that starts with a line-feed. The existing code was fine for JS but not for CSS (// isn't a comment in CSS). We have a test for JS with a pre-existing comment but not for CSS with pre-existing comment. Honestly I'm not sure how to create a CSS file with a valid pre-existing source-map comment.

I'm not sure that it's very important to avoid adding a blank line between the source and the new comment, but the newlinePre variable is used to avoid that blank line and maintain current behavior.

@@ -24,29 +24,27 @@ var getCommentFormatter = function (file) {
var extension = file.relative.split('.').pop(),
fileContents = file.contents.toString(),
newline = detectNewline.graceful(fileContents || ''),
newlinePre = newline,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need another variable which is the same thing. Just keep it as newline.

}

switch (extension) {
case 'css':
debug(function() { return 'css commentFormatter';});
commentFormatter = function(url) {
return newline + "/*# sourceMappingURL=" + url + " */" + newline;
return newlinePre + "/*# sourceMappingURL=" + url + " */" + newline;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just make it newline.

return "//# sourceMappingURL=" + url + newline;
};
return commentFormatter;
newlinePre = '';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not?

commentFormatter = function(url) {	
 
      return newLine + "//# sourceMappingURL=" + url + newline;	
    };	
    return commentFormatter;	
  }

@nmccready
Copy link
Collaborator

I'm going to merge this locally and fix any outstanding issues.

@nmccready
Copy link
Collaborator

Closing in favor of #366 ; @benjclark AND @coreyfarrell please see if the PR is good for you . If so I will merge and publish the patch.

@nmccready nmccready closed this Feb 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants