When writing Babel plugins, what can I assume about the same node being processed more than once? When or how can this happen? What are common protections if I don't want my annotations to appear twice? Should I always check if I've "seen" this node already?
-
-
Replying to @dan_abramov
You should always check if you’ve seen it. A WeakSet is the best option. There’s literally no memorable logic between when nodes are retraversed.
2 replies 0 retweets 9 likes -
Replying to @sebmck @dan_abramov
@sebmck what scenario will get you to process the same node again?2 replies 0 retweets 0 likes -
Replying to @sag1v @dan_abramov
Another plugin replacing a parent will trigger a retraversal of the subtree, running your visitor again. There’s other scenarios. I’ll look into it and get some code pointers when I can.
2 replies 0 retweets 1 like -
Does this look legit? https://github.com/facebook/react/pull/15733/commits/f6881a8e74b4a47f0916ebf64682d8467dc86ef2 …
2 replies 1 retweet 2 likes
Yeah looks legit. Same pattern is used in the "official" Babel plugins: https://github.com/babel/babel/blob/8c7d4b55c99ff34cb9d493d452472e59b5ed1e70/packages/babel-plugin-transform-react-constant-elements/src/index.js#L85-L86 … etc
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
he/him 