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.
Depends on #4815.
This refactors the hoist transform in a similar way to how #4815 did for the linker, replacing
@babel/traverse
with a custom implementation, and using a custom scope tracker. It's ~35% faster to build the asset graph on the esbuild benchmark after this transform. Looking at a profile, actual transformation is no longer the bottleneck.The hoist transform now happens in a single pass over the AST, rather than waiting for babel's scope tracker to do a first pass before our transform. Now, we collect scope information as we traverse the AST using a custom scope implementation which tracks bindings and references. All renaming of variables happens at the when exiting each scope, once all references are known.
For any transforms that need scope information, the traversal function now allows you to return a function from your visitor. This marks the node as needing to be revisited at the end of the traversal. Once the whole AST has been traversed, the functions for nodes to be revisited are executed, and any nodes that are returned are inserted into the AST at that point.