Avoid validating visitors produced by traverse.visitors.merge#16699
Avoid validating visitors produced by traverse.visitors.merge#16699nicolo-ribaudo merged 2 commits intobabel:mainfrom
traverse.visitors.merge#16699Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57541 |
| if (!process.env.BABEL_8_BREAKING) { | ||
| // For compatibility with old Babel versions, we must hide _verified and _exploded. | ||
| // Otherwise, old versions of the validator will throw sayng that `true` is not | ||
| // a function, because it tries to validate it as a visitor. | ||
| Object.defineProperty(mergedVisitor, "_exploded", { enumerable: false }); | ||
| Object.defineProperty(mergedVisitor, "_verified", { enumerable: false }); | ||
| } |
There was a problem hiding this comment.
I'm surprised they would fail for enumerable _exploded but still work for non-enumerable _exploded.
There was a problem hiding this comment.
They do Object.keys :)
There was a problem hiding this comment.
I have some concerns that visitors will still be revalidated on these versions. (I'm not sure how older versions did it)
Since they throw on _exploded, that means they probably don't follow _exploded and validate again.
There was a problem hiding this comment.
They check visitor._verified, so it works even if it's non-enumerable.
traverse.visitors.mergetraverse.visitors.merge
|
I'll release once we land #16700 |
This PR marks as "already validated" all visitors produced by
traverse.visitor.merge, which internally does validation of all of its inputs. This means that passing those visitors to older versions of@babel/traversewill not throw anymore.With this change I can get the example from #16689 (comment) to build, even if then fails with "regeneratorRuntime is not defined" (which is a completely separate problem, probably a bug in my setup)