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
Sourcemap link is not the last thing in file. #3148
Comments
Sorry to anyone subscribed to this repository, I accidentally hit ctrl-enter which submitted the issue before filling it in. I have updated the issue description now though. |
I disagree. The source map spec is informal and editors commonly add either \n or \r\n to the end of files if a source map URL is added manually. Any good source map URL reading implementation would handle the presence or absence of newlines as all browsers currently do. |
@kzc While I tend to agree that sourcemap users should be permissive in what they accept (and I believe there is an open PR for es-module-shims to make it more permissive), I also believe that Rollup should follow the strictest interpretation of the specification to obtain maximum compatibility. This follows the Robustness Principle design guideline:
|
The source map spec provided states:
It appears to be a dead link, but here's an archived copy of that web page: An actual code fragment with a regular expression is provided:
I assume that the web archive dropped the necessary backslashes to make this valid JS. If one fixes the regexp you can see that optional trailing whitespace - including newlines - is permissible:
Just to back up that assertion, I see that that web page makes mention of: which in turn mentions: https://web.archive.org/web/20161221094120/https://bugs.webkit.org/show_bug.cgi?id=25475 which provides this valid JS:
So any source map URI at the end of the source code with or without trailing whitespace - including newlines - are conforming according to the sourcemap spec. |
Rollup is generating a file that has a trailing newline. This MAY go against an implementation of the source map specification.
https://sourcemaps.info/spec.html#h.9ppdoan5f016
One could interpret this to mean that the last characters of the file are the sourcemap comment, without a newline. If one did (as
es-module-shims
does currently), then the sourcemap comment in a rollup generated file would be invalid.1.21.4
v12.3.0
How Do We Reproduce?
https://github.com/just-dont/sourcemaps-with-shims
Expected Behavior
There is no newline at the end of the sourceMappingURL comment.
Actual Behavior
There is a newline at the end of the sourceMappingURL comment.
Suggested fix:
Don't append a newline in order to maintain maximum compatibility.
The text was updated successfully, but these errors were encountered: