-
-
Notifications
You must be signed in to change notification settings - Fork 721
refactor(ast_tools/formatter): shorten code #12929
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_tools/formatter): shorten code #12929
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
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.
Pull Request Overview
This PR refactors the formatter code to make it more concise and robust by utilizing existing schema utility methods. The refactoring replaces manual iteration and inheritance handling with built-in methods that properly handle multi-level enum inheritance.
Key changes:
- Simplified statement variant collection using
Schema::type_by_nameandEnumDef::all_variants - Improved handling of enum inheritance chains
- Reduced code complexity while maintaining equivalent functionality
Merge activity
|
Follow-on after #12864. Pure refactor, does not alter generated code. Shorten code by using `Schema::type_by_name` and `EnumDef::all_variants` methods. `EnumDef::all_variants` iterates over all variants of an enum, including inherited variants. As well as being shorter, it also correctly handles multiple layers of inheritance e.g. if `X` inherits variants from `Y`, and `Y` inherits variants from `Z`. In the case of `Statement`, inheritance is only 1 level deep, so it makes no difference - but it might if we change the AST later on.
5149178 to
bdaf569
Compare
Follow-on after oxc-project#12864. Pure refactor, does not alter generated code. Shorten code by using `Schema::type_by_name` and `EnumDef::all_variants` methods. `EnumDef::all_variants` iterates over all variants of an enum, including inherited variants. As well as being shorter, it also correctly handles multiple layers of inheritance e.g. if `X` inherits variants from `Y`, and `Y` inherits variants from `Z`. In the case of `Statement`, inheritance is only 1 level deep, so it makes no difference - but it might if we change the AST later on.

Follow-on after #12864. Pure refactor, does not alter generated code.
Shorten code by using
Schema::type_by_nameandEnumDef::all_variantsmethods.EnumDef::all_variantsiterates over all variants of an enum, including inherited variants. As well as being shorter, it also correctly handles multiple layers of inheritance e.g. ifXinherits variants fromY, andYinherits variants fromZ.In the case of
Statement, inheritance is only 1 level deep, so it makes no difference - but it might if we change the AST later on.