Support more fine-grained source location tracking and use it for functions #3463
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 is a fix for https://phabricator.babeljs.io/T7258 / https://phabricator.babeljs.io/T7255 so @kpdecker I'd love your thoughts if you have a minute.
Basically, this uses the call stack and scoping to track the current ast node's source location as the code is being generated. As code is generated, Babel will read the currently active source location, and create a mapping for the content that is being generated. This allows us to have more direct control over the maps that are generated. We can use this control to clear the source location entirely, or to set a new location part-way through rendering.
In this case, I'm using the ability to change the location to point to the end of the function when we generate the last line of a function. This allows us to solve https://phabricator.babeljs.io/T7258.