-
Notifications
You must be signed in to change notification settings - Fork 794
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
Sprockets Semicolon insertion causes sourcemap to be off by (n) number of lines #388
Comments
I started to look into this a little more but was unsure what a correct solution should be. I wondered if we could change the way semicolon addition works to simply append a semicolon on the last line of the JS file and omit the extra newline. If someone has a thought on how to address this, I'll work on a PR |
Inserting on the same line seems fine |
I wonder if the semicolon appending is even needed these days... |
Thanks for posing that question @SamSaffron - I had wondered about that as well...especially since we are ensuring there is a newline before concatenating now which was not the case previously. Anyone have thoughts/opinions if this is still necessary? |
@danshultz yeah the newline stuff isn't necessary, just appending a semicolon should be OK. Appending them is still needed I think, as not adding a semicolon at the end of the file is fairly common and valid JS. |
We need to be careful to ensure there is a newline between the two files when they are concatenated. Otherwise the last line of the first file and the first line of the second file will get appended onto the same line and break source maps. It will need to check if the file ends in a newline, and append the semicolon before the newline, otherwise append a semicolon + newline. |
Any news on this one? |
Expected behavior
When using sprockets with source maps, it's expected the sourcemap lines up with the original source.
Actual behavior
Each source file will be off by (n) number of lines based upon the order it was appended and the (n) number of semicolons inserted.
The semicolons are inserted here which is after default source maps are created it appears.
System configuration
Example App
This can be reproduced in the test suite by introspecting the source map generation that happens during the appends missing semicolons test run.
The input JS is
test/fixtures/asset/semicolons/bar.js
test/fixtures/asset/semicolons/index.js
The output of the JS is
The source map representation is
The text was updated successfully, but these errors were encountered: