Skip to content

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented Aug 9, 2025

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.

@github-actions github-actions bot added the A-ast-tools Area - AST tools label Aug 9, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@github-actions github-actions bot added the C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior label Aug 9, 2025
@overlookmotel overlookmotel marked this pull request as ready for review August 9, 2025 10:21
Copilot AI review requested due to automatic review settings August 9, 2025 10:21
Copy link
Contributor

Copilot AI left a 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_name and EnumDef::all_variants
  • Improved handling of enum inheritance chains
  • Reduced code complexity while maintaining equivalent functionality

@overlookmotel overlookmotel requested a review from Dunqing August 9, 2025 10:46
@graphite-app graphite-app bot added the 0-merge Merge with Graphite Merge Queue label Aug 9, 2025
@graphite-app
Copy link
Contributor

graphite-app bot commented Aug 9, 2025

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.
@graphite-app graphite-app bot force-pushed the 08-09-refactor_ast_tools_formatter_shorten_code branch from 5149178 to bdaf569 Compare August 9, 2025 14:03
@graphite-app graphite-app bot merged commit bdaf569 into main Aug 9, 2025
21 checks passed
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label Aug 9, 2025
@graphite-app graphite-app bot deleted the 08-09-refactor_ast_tools_formatter_shorten_code branch August 9, 2025 14:09
taearls pushed a commit to taearls/oxc that referenced this pull request Aug 12, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast-tools Area - AST tools C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants