-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Allow traverseFast
to exit early
#17169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
liuxingbaoyu
commented
Mar 8, 2025
Q | A |
---|---|
Fixed Issues? | Fixes #7462 |
Patch: Bug Fix? | |
Major: Breaking Change? | |
Minor: New Feature? | |
Tests Added + Pass? | Yes |
Documentation PR Link | |
Any Dependency Changes? | |
License | MIT |
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/58914 |
d561813
to
7410110
Compare
@@ -7,28 +7,39 @@ import type * as t from "../index.ts"; | |||
*/ | |||
export default function traverseFast<Options = object>( | |||
node: t.Node | null | undefined, | |||
enter: (node: t.Node, opts?: Options) => void, | |||
enter: (node: t.Node, opts?: Options) => void | "skip" | "stop", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about returning t.traferseFast.skip
and t.traverseFast.stop
symbols instead of strings? We usually don't have this type of magic strings to control behavior in our public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strings seem to be a bit clearer in terms of type definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried playing around with this, and it can be done: https://www.typescriptlang.org/play/?#code/MYewdgzgLgBA+hA1gSwA4C4YFczII5YCmMEAngLYBGIANjALwwDKF1NAFAJQDcAUAGY5gUZOBhQATgEMAboQkRCAMSnR2wSpi4MAfDBkhkAExgAfcaVSEQ-cdLkLlqqADokaTjADeAX16TZeUUVaDcUVAZ4d1Q+I0JgGikJYjApckIIVClgYgCHYOdvXhgSmEIAD1QQCVhQSFhozChLa1sEcL4-f3sgpzVtej0vYtKAelGYEEQRkuSoLAkwO0DHENdozs5eXnGYVTLK+KhCIwAaMokJaph2SixYKAALYnkriRh0iAgpAHNiZAgMDAIFgDlIMB+IBAZxgABUmCRHiAsDQTMhyKgrnIYMgoFs8r01uwBkMZjA5gsliwqLQuJttkA
However, the autocomplete experience is much better when using strings, so up to you. Feel free to merge this PR as-is if you still think strings are better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like @JLHwung prefers symbols too, so I'll use that. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice
} | ||
return t.traverseFast(expression, node => { | ||
if (t.isPrivateName(node)) { | ||
return "stop"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this guaranteed to use a new-enough version of babel types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this is using @babel/core
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving assuming that the answer to the two comments is positive.
4fe0b15
to
3e0af8d
Compare