-
Notifications
You must be signed in to change notification settings - Fork 0
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
Improve macros for inherited enums? #15
Comments
The above match prop_key {
PropertyKey::StaticIdentifier(id) => id.do_stuff(),
PropertyKey::PrivateIdentifier(id) = id.do_stuff(),
expr @ (
PropertyKey::BooleanLiteral(_)
| PropertyKey::NullLiteral(_)
/* ...and all the other Expression variants */
) => {
let expr = expr.to_expression();
expr.do_stuff()
}
} |
I've mulled it over for a couple of days, I still believe it adds to the code noise and makes stuff harder to follow. But if we are committing to this, Let's do it all the way! |
@hyf0 suggested an alternative on Discord: Extend existing match expr {
match_member_expression!(member_expr @ Expression) => member_expr.do_stuff()
} which would expand to: match expr {
_temp @ (
Expression::ComputedMemberExpression(_)
| Expression::StaticMemberExpression(_)
| Expression::PrivateFieldExpression(_)
) => {
let member_expr = _temp.to_member_expression();
member_expr.do_stuff()
}
} I think this is really good! @rzvxa you like? |
Yes, I like what I'm seeing. I'm glad we gave this issue a bit of time because it seems like a more natural way of expressing the same thing we wanted in the original comment. Small nit, Shouldn't we expand to this? match expr {
member_expr @ (
Expression::ComputedMemberExpression(_)
| Expression::StaticMemberExpression(_)
| Expression::PrivateFieldExpression(_)
) => {
let member_expr = member_expr.to_member_expression();
member_expr.do_stuff()
}
} |
Yes, you're right. That's better. |
Argh I forgot I tried this before, and it doesn't work! It'd have to be: match expr {
match_member_expression!( member_expr @ Expression => member_expr.do_stuff() )
} And macros do not support expanding to match arms. |
I was about to point out the match arms issue😅 |
Last bit of unfinished business after oxc-project/oxc#3115...
That PR introduced squashed/inherited enums. The least ergonomic API is for matching, which requires a set of
match_*
macros e.g.:Would this be better?
This reduces boilerplate and makes the code easier to read. But is it too much magic?
@rzvxa You had strong opinions on this matter. Would you like to chime in?
The text was updated successfully, but these errors were encountered: