re-implement babel traverse cache pollution bug workaround using a second copy of babel traverse #1340
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.
The issue
Traverse in babel 7 is currently polluting the cache with BabelNode that has no
hub
entry (see babel/babel#6437). Since the traverse cache is used by other babel operations (mostly transform) which might expecthub
to be present, this breaks the code in all kind of unexpected scenarios.While this issue has been fixed in babel 8 (not released at this moment), it is still an issue in the latest version of babel 7.
The previous workaround
We've implemented a workaround for that issue in #854 (comment) however updating to the latest version of
@babel/traverse
, that workaround is not working anymore (more about that below).The new workaround
Instead, we are implementing a different workaround that installs traverse twice, including installing it's cache file twice. We use the second copy of traverse
@babel/traverse--for-generate-function-map
only inforEachMapping
, allowing the rest of the system to use the traverse caching from the main copy of traverse (@babel/traverse
) without the pollution issue mentioned above.Why the previous workaround stopped working
Due to the use of a
let export
in the latest version of traverse cache, and how it's used in the latest version, we can't re-writetraverse.cache.path
anymore.This cache is exported with a
let export
:https://github.com/babel/babel/blob/5ebab544af2f1c6fc6abdaae6f4e5426975c9a16/packages/babel-traverse/src/cache.ts#L6-L20
And it compiles to:
and then used like this:
Which means that re-writing the export like we used to do breaks the traverse cache because
exports.path
is re-written, but notpathsCache
while the latter is used inside the file: