This repository was archived by the owner on Jun 24, 2024. It is now read-only.
Define how to extract the sourceMappingURL comment#30
Draft
nicolo-ribaudo wants to merge 1 commit intotc39:mainfrom
Draft
Define how to extract the sourceMappingURL comment#30nicolo-ribaudo wants to merge 1 commit intotc39:mainfrom
sourceMappingURL comment#30nicolo-ribaudo wants to merge 1 commit intotc39:mainfrom
Conversation
a70a804 to
1e39da2
Compare
This patch explicitly defines how to extract such comments from JavaScript, CSS and WebAssembly sources. It defines multiple ways to do so: either by actually parsing the code, or by just going through all the lines of the program looking for what "looks like" a comment. This is so that different implementations can choose what's best for them, depending on whether they are already parsing the code or not. To ensure consist behavior accross implementations that choose different strategies, the specification enforces additional requirements on tools that append a `sourceMappingURL` comment to the generated code: the comment must be placed in such a way that all extraction methods yield the same result. This is not an unresonable burden, since if the progeram is syntactically valid, simply adding the comment at the end of the file only potentially followed by other tool-injected comments is enough. This requirement is lifted if the input code given to the tool is already "maliciously crafted", since we would otherwise require tool to go rewrite that code (for example, splitting strings that contain something that looks like a comment). I have left the CSS extraction method as TODO because first I want to check how do you feel about the JS one. It has the following properties: - It iterates line by line. Implementations can thus optimize it by going through each line _in reverse order_, and then scanning through its characters from the beginning to the end (which is what a regexp would do). - It expects multi-line comments to actually be in a single line. - It returns the last `sourceMappingURL` comment (or well, comment-like) found in the source. - It only considers comments after the last piece of code (i.e. it discards any comment found so far every time it sees some non-comment non-whitespace characters). - It has no requirements about what is _before_ a comment. Adding the comment at the end of the file without first ensuring that there is a newline before it is valid.
1e39da2 to
d422607
Compare
gibson042
reviewed
Mar 20, 2024
Comment on lines
+455
to
+456
| 1. [=Collect a sequence of code points=] that are [=white space code points|ECMAScript | ||
| white space code points=] from |line| given |position|. |
Member
There was a problem hiding this comment.
Is it a problem that ECMAScript white space is subject to change over time as future Unicode editions change the set of code points in general category "Space_Separator"?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR follows the discussion from last week about tc39/ecma426#64. It's marked as a draft because I still haven't "translated" the JS part to CSS, but please already check the JS part and express your opinion :)
Rendered version: https://nicolo-ribaudo.github.io/source-map-spec/source-map.html#linking-generated-code
This patch explicitly defines how to extract such comments from JavaScript, CSS and WebAssembly sources.
It defines multiple ways to do so: either by actually parsing the code, or by just going through all the lines of the program looking for what "looks like" a comment. This is so that different implementations can choose what's best for them, depending on whether they are already parsing the code or not.
To ensure consist behavior accross implementations that choose different strategies, the specification enforces additional requirements on tools that append a
sourceMappingURLcomment to the generated code: the comment must be placed in such a way that all extraction methods yield the same result. This is not an unresonable burden, since if the progeram is syntactically valid, simply adding the comment at the end of the file only potentially followed by other tool-injected comments is enough. This requirement is lifted if the input code given to the tool is already "maliciously crafted", since we would otherwise require tool to go rewrite that code (for example, splitting strings that contain something that looks like a comment).I have left the CSS extraction method as TODO because first I want to check how do you feel about the JS one. It has the following properties:
sourceMappingURLcomment (or well, comment-like) found in the source.