Skip to content

Prevent new lines written by write_str from breaking source maps #971

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thecrypticace
Copy link

Right now putting license comments in a file causes invalid source maps to be generated.

For example, running this file through lightning with source maps will produce incorrect generated locations:

/*! foo 
 foo 
 foo 
 foo */
/*! bar */
.flex {
  display: flex;
}
.hidden {
  display: none;
}

Here's a screenshot of the source map visualizer for the generated CSS:
Screenshot showing incorrectly generated source locations

This happens because Lightning computes the column offset to be the length of the comment plus the new line character at the end and this happens for each license comment in the file. Additionally, license comments are one of the few things that basically preserve the content as is including new lines. So if the license comment itself contains new lines than the generated mappings can be pretty far off — as the screenshot above shows.

This PR fixes this by tracking new lines and resetting the appropriate state when printing the CSS in write_str.

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.

1 participant