Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As mentioned on the task https://phabricator.babeljs.io/T7179 having this cache on the AST leads to all sorts of portability and reuse bugs. This moves the cache into a clearable WeakMap which will fix the following: 1. Moving the AST between different babel versions or tools will not lead into sharing potentially outdated cached information 2. `.clear()` can be called on the cache by a plugin to clear potentially outdated information. This is helpful when implementing two seperate pipelines that should not share information. I think the next step (which is harder, I tried) is to isolate cache and make it live on a transform or pipeline level state (like the `hub`). The reason it is hard is because the `babel-traverse` main API -- although requires the state object to be passed -- not many callers do. To fix this we should release a patch version that warns about this and fix all the internal callers. Next couple of releases we can start throwing when no state is passed (or we can create our own state).
- Loading branch information
Showing
5 changed files
with
34 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
let wm = new WeakMap(); | ||
|
||
// To implement clear we need to export a facade. | ||
export default { | ||
clear() { | ||
wm = new WeakMap(); | ||
}, | ||
|
||
delete(k) { | ||
return wm.delete(k) | ||
}, | ||
|
||
get(k) { | ||
return wm.get(k) | ||
}, | ||
|
||
has(k) { | ||
return wm.has(k) | ||
}, | ||
|
||
set(k, v) { | ||
wm.set(k, v); | ||
return wm; | ||
}, | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
@amasad I'm not sure having this cache be global to a particular version of
@babel/traverse
solves this issue either, I'm still running into issues of information from one traversal unexpectedly leaking to another and clobbering visitors in #12570.