Add missing parts for setting up AST transformation examples#1081
Open
kant2002 wants to merge 2 commits intooxc-project:mainfrom
Open
Add missing parts for setting up AST transformation examples#1081kant2002 wants to merge 2 commits intooxc-project:mainfrom
kant2002 wants to merge 2 commits intooxc-project:mainfrom
Conversation
Added examples for using AstBuilder in MyTransformer. Signed-off-by: Andrii Kurdiumov <kant2002@gmail.com>
✅ Deploy Preview for oxc-project ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
kant2002
commented
May 3, 2026
Author
kant2002
left a comment
There was a problem hiding this comment.
Make recursive simplification, since that's usually what you want initially.
camc314
reviewed
May 5, 2026
| use oxc_ast::visit::{VisitMut, walk_mut}; | ||
| use oxc_ast::AstBuilder; | ||
|
|
||
| struct MyTransformer<'a> { |
Contributor
There was a problem hiding this comment.
lets add some rust doc comments explaining what this transformation is doing?
inline comments like
`x + y` -> `"''"`
explaining the before/after of what's being changed can also be helpful.
camc314
reviewed
May 5, 2026
Comment on lines
+116
to
+126
| fn visit_expression(&mut self, expr: &mut BinaryExpression<'a>) { | ||
| // Detect the expression type which you want to modify | ||
| match it { | ||
| Expression::BinaryExpression(expr) | ||
| if expr.operator == BinaryOperator::Addition => { | ||
| let new_expr = self.builder.expression_string_literal(SPAN, "", Some(Str::new_const("''"))); | ||
| *it = new_expr; | ||
| }, | ||
| _ => walk_mut::walk_expression(self, it), | ||
| } | ||
| } |
Contributor
There was a problem hiding this comment.
I would say "When changing from one enum varient to another. in this example a BinaryExpression, it is necessary to match on the enum variant rather than on the expression or..."
or sometihig like that
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Added examples for using AstBuilder in MyTransformer.