Prevent new lines written by write_str
from breaking source maps
#971
+55
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Here's a screenshot of the source map visualizer for the generated CSS:

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
.