-
-
Notifications
You must be signed in to change notification settings - Fork 736
refactor(ast)!: Remove AstKind for Argument #13902
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
refactor(ast)!: Remove AstKind for Argument #13902
Conversation
b9c702a to
1d021ce
Compare
CodSpeed Performance ReportMerging #13902 will improve performances by 5.8%Comparing Summary
Benchmarks breakdown
Footnotes |
|
the CI is fully passing now! I still need to take some time to review my own changes, but I think generally this is ready for review now |
206c534 to
3356209
Compare
f5a0c3a to
65e8711
Compare
Add `has_argument_with_span()` and `is_callee_with_span()` helper methods to `AstKind` to simplify AST traversal after the removal of `AstKind::Argument`.
These methods help downstream tools (like rolldown) avoid verbose span-matching patterns when determining:
- Whether a node is an argument to a CallExpression/NewExpression
- Whether a node is the callee of a CallExpression/NewExpression
Example usage:
```rust
// Before: verbose span matching
if let Some(arg) = call_expr.arguments.iter()
.find(|arg| arg.span() == node.span()) { ... }
// After: clean API
if parent.has_argument_with_span(node.span()) { ... }
```
Addresses review feedback from PR oxc-project#13902.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
@taearls Sorry this has taken so long to get to, and thanks for constantly keeping the PR updated. We're aiming to (finally) get this merged next week. @camc314 and @Dunqing are reviewing the parts related to linter and formatter respectively, and then I'm going to do a 2nd pass through the whole thing. I'll co-ordinate with them both on Monday. |
hey! I appreciate that a lot. It's all good! I know this is a big change so I can understand that it's harder to prioritize this with everything else that's in flight right now, especially with the formatter. I just rebased onto main earlier today and got the conformance tests to the same baseline as was on main (with some minor improvements!) so it's all ready to go. |
|
Amazing. Thank you. Can I please ask one thing? Could you please rebase onto main (rebase not merge) and squash everything down to a single commit? The list of commits on this page is so long that it's quite hard to find the review comments! |
47d87eb to
ee46d2c
Compare
done! |
e4b038f to
f777c5c
Compare
f777c5c to
9ef5df9
Compare
9ef5df9 to
be22770
Compare
|
@taearls Thank you for your work on this! |
|
Yes, thank you thank you thank you @taearls. I've actually not reviewed yet, but we decided best to just get it merged now before it accrues more merge conflicts, and I'll go through it later this week, and I can make any follow-ups then. |
That makes sense. I'm happy to help! This effort taught me a lot about working with this project, and I feel much more comfortable in it as a whole because of it. Let me know if I can be helpful with any follow-up items. |
Part of #11490
had to open this new PR because #12525 was closed by mistake.
Motivation
AstKind::Argumentwas an architectural inconsistency. The AstKind system is designed for struct types, butArgumentis an enum (SpreadElement | Expression). This created unnecessary complexity in the AST traversal system.Solution
Replace AST-based argument detection with span-based utilities. Instead of traversing the tree to find
AstKind::Argumentnodes, we now use direct span containment checks.New Utilities
Added to
oxc_linter/src/ast_util.rs:Checks if a node is exactly a direct argument to its parent call expression by checking if the parent is a call and the node's span matches one of the argument spans.
Checks if a node is nested within a specific argument at the given index of the provided call expression.
Added to
oxc_ast/src/ast_kind_impl.rs:Checks if this
AstKindis a call expression with an argument matching the given span.Checks if this
AstKindis a call expression whose callee matches the given span.Architecture Change
Before:
After:
Impact
AstKind::Argumentvariant, reducedAST_TYPE_MAXfrom 186 → 185AstKind::Argumentcaused the formatter to make different formatting decisions for arrow functions and object expressions used as arguments, generally producing more compact output (fewer parentheses). Snapshot tests show formatting changes while maintaining Prettier conformance pass rates.Testing
Breaking Changes
None - this is an internal refactoring that doesn't affect public APIs.