[cli] Avoid SourceMapGenerator for simple map concatenation#14479
Merged
nicolo-ribaudo merged 2 commits intobabel:mainfrom Apr 21, 2022
Merged
[cli] Avoid SourceMapGenerator for simple map concatenation#14479nicolo-ribaudo merged 2 commits intobabel:mainfrom
SourceMapGenerator for simple map concatenation#14479nicolo-ribaudo merged 2 commits intobabel:mainfrom
Conversation
This removes the last use of `source-map` package from babel-cli. Instead, we use a [SectionedSourceMap](https://github.com/jridgewell/trace-mapping/blob/8db5df070b15e2a669277b710a9d69ad0676524d/src/types.ts#L28-L32), which is purpose built for simple file concatenation like this. This should be considerably faster to generate sourcemaps now. And, if a sourcemaps are not needed, it's essentially free. As an added benefit, this gives us proper `names` support: ```diff --- a 2022-04-20 11:01:49.000000000 -0400 +++ b 2022-04-20 11:01:55.000000000 -0400 @@ -1,12 +1,17 @@ { "version": 3, "file": "script2.js", - "names": [], + "names": [ "arr", "map", "x", "MULTIPLIER" ], "sources": [ "script.js" ], "sourcesContent": [ "arr.map(x => x * MULTIPLIER);" ], - "mappings": ";;AAAA,GAAG,CAAC,GAAJ,CAAQ,UAAA,CAAC;AAAA,SAAI,CAAC,GAAG,UAAR;AAAA,CAAT" + "mappings": ";;AAAAA,GAAG,CAACC,GAAJ,CAAQ,UAAAC,CAAC;AAAA,SAAIA,CAAC,GAAGC,UAAR;AAAA,CAAT" } ```
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51708/ |
JLHwung
approved these changes
Apr 20, 2022
| function countNewlines(code: string): number { | ||
| let count = 0; | ||
| let index = -1; | ||
| while ((index = code.indexOf("\n", index + 1)) !== -1) { |
Member
There was a problem hiding this comment.
I think we need to handle all the possible newlines. Even if we always print \n, multiline template literals may still contain different line terminators.
Member
Author
There was a problem hiding this comment.
This is just a faster version of the code.split("\n").length that was there before. We can add more newline support, could we wait until a followup?
Member
There was a problem hiding this comment.
Oh ok sure, I didn't realize it was already like this 👍 (and no one ever complained, so it's super low priority).
SourceMapGenerator for simple map concatenation
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.
@jridgewell/trace-mappingand removes ancientsource-mapThis removes the last use of
source-mappackage from babel-cli. Instead, we use a SectionedSourceMap, which is purpose built for simple file concatenation like this.This should be considerably faster to generate sourcemaps now. If sourcemaps are not needed, it's essentially free. And as an added benefit, this gives us proper
namessupport:(That fifth letter that appears in some mappings segments is the
namespointer)