Prevent @babel/traverse path cache side-effects in generateFunctionMap#906
Closed
robhogan wants to merge 1 commit intofacebook:mainfrom
Closed
Prevent @babel/traverse path cache side-effects in generateFunctionMap#906robhogan wants to merge 1 commit intofacebook:mainfrom
@babel/traverse path cache side-effects in generateFunctionMap#906robhogan wants to merge 1 commit intofacebook:mainfrom
Conversation
…nMap` Summary: ## Motivation For performance reasons, we'd like to have the option to re-use an AST (without cloning) after deriving source map information from it. However, due to babel/babel#6437, traversing the AST within `generateFunctionMap` causes the `babel/traverse` path cache to be populated with entries Babel transform plugins can't use - in particular because `hub` is assumed to be set. ## Change This diffs saves and clears the traverse cache before traversal, and then restores it afterwards. This isn't pretty but it's the cleanest approach I could find - we include tests to verify that this is (and continues to be) necessary. ## Other approaches I tried some other things before resorting to manipulating `babel/traverse` internals: - Actually providing a `hub` so that it's set on the cache means adding a dependency on `babel/core`, and requires a similar level of hackery / assumptions of Babel internals. - Clearing the bad cache with `traverse.clearNode(ast)` or `traverse.cache.clearPath()` doesn't work because other tools (eg, Jest) rely on `properties` held in the path cache. Changelog: [Internal] Differential Revision: D42068914 fbshipit-source-id: f473f67f17ffe92c9fc378ef54f3dc40bcf25f7a
Contributor
|
This pull request was exported from Phabricator. Differential Revision: D42068914 |
Contributor
|
This pull request has been merged in 29bb5f2. |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary:
Motivation
For performance reasons, we'd like to have the option to re-use an AST (without cloning) after deriving source map information from it. However, due to babel/babel#6437, traversing the AST within
generateFunctionMapcauses thebabel/traversepath cache to be populated with entries Babel transform plugins can't use - in particular becausehubis assumed to be set.Change
This diffs saves and clears the traverse cache before traversal, and then restores it afterwards. This isn't pretty but it's the cleanest approach I could find - we include tests to verify that this is (and continues to be) necessary.
Other approaches
I tried some other things before resorting to manipulating
babel/traverseinternals:hubso that it's set on the cache means adding a dependency onbabel/core, and requires a similar level of hackery / assumptions of Babel internals.traverse.clearNode(ast)ortraverse.cache.clearPath()doesn't work because other tools (eg, Jest) rely onpropertiesheld in the path cache.Changelog: [Internal]
Differential Revision: D42068914