Skip to content

Avoid validating visitors produced by traverse.visitors.merge#16699

Merged
nicolo-ribaudo merged 2 commits intobabel:mainfrom
nicolo-ribaudo:no-explode-validate
Jul 30, 2024
Merged

Avoid validating visitors produced by traverse.visitors.merge#16699
nicolo-ribaudo merged 2 commits intobabel:mainfrom
nicolo-ribaudo:no-explode-validate

Conversation

@nicolo-ribaudo
Copy link
Member

Q                       A
Fixed Issues? Fixes #16689 (comment)
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

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/traverse will 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)

@nicolo-ribaudo nicolo-ribaudo added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jul 30, 2024
@babel-bot
Copy link
Collaborator

babel-bot commented Jul 30, 2024

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/57541

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 });
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised they would fail for enumerable _exploded but still work for non-enumerable _exploded.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do Object.keys :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They check visitor._verified, so it works even if it's non-enumerable.

@nicolo-ribaudo nicolo-ribaudo changed the title Avoid re-validating visitors produced by traverse.visitors.merge Avoid validating visitors produced by traverse.visitors.merge Jul 30, 2024
@nicolo-ribaudo nicolo-ribaudo merged commit 992c6e0 into babel:main Jul 30, 2024
@nicolo-ribaudo nicolo-ribaudo deleted the no-explode-validate branch July 30, 2024 20:48
@nicolo-ribaudo
Copy link
Member Author

I'll release once we land #16700

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 30, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Something tricky with the latest babel/traverse

4 participants