Avoid validating visitors produced by traverse.visitors.merge#16699
Merged
nicolo-ribaudo merged 2 commits intobabel:mainfrom Jul 30, 2024
Merged
Avoid validating visitors produced by traverse.visitors.merge#16699nicolo-ribaudo merged 2 commits intobabel:mainfrom
traverse.visitors.merge#16699nicolo-ribaudo merged 2 commits intobabel:mainfrom
Conversation
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57541 |
liuxingbaoyu
approved these changes
Jul 30, 2024
Comment on lines
+249
to
+255
| 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 }); | ||
| } |
Member
There was a problem hiding this comment.
I'm surprised they would fail for enumerable _exploded but still work for non-enumerable _exploded.
Member
Author
There was a problem hiding this comment.
They do Object.keys :)
Member
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.
Member
Author
There was a problem hiding this comment.
They check visitor._verified, so it works even if it's non-enumerable.
JLHwung
approved these changes
Jul 30, 2024
traverse.visitors.mergetraverse.visitors.merge
Member
Author
|
I'll release once we land #16700 |
This was referenced Aug 21, 2024
This was referenced Aug 21, 2024
Open
This was referenced Aug 22, 2024
This was referenced Oct 27, 2024
This was referenced Oct 27, 2024
This was referenced Oct 27, 2024
Open
This was referenced Oct 29, 2024
This was referenced Oct 29, 2024
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
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)