-
-
Notifications
You must be signed in to change notification settings - Fork 721
feat(formatter): correct ast_nodes generator #12864
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
Merged
graphite-app
merged 1 commit into
main
from
08-07-feat_formatter_correct_ast_nodes_generator
Aug 7, 2025
Merged
feat(formatter): correct ast_nodes generator #12864
graphite-app
merged 1 commit into
main
from
08-07-feat_formatter_correct_ast_nodes_generator
Aug 7, 2025
Conversation
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
This was referenced Aug 7, 2025
Merged
Member
Author
CodSpeed Instrumentation Performance ReportMerging #12864 will not alter performanceComparing Summary
|
a5bd6b4 to
dd5283c
Compare
30dcb9e to
de8558f
Compare
Member
Merge activity
|
dd5283c to
76de684
Compare
de8558f to
40affe9
Compare
76de684 to
56ecd0a
Compare
40affe9 to
00f736a
Compare
56ecd0a to
ce27298
Compare
00f736a to
8316ceb
Compare
ce27298 to
248fd94
Compare
8316ceb to
bfacd66
Compare
Base automatically changed from
08-07-feat_formatter_correct_formatting_for_trystatement
to
main
August 7, 2025 15:17
This was referenced Aug 9, 2025
graphite-app bot
pushed a commit
that referenced
this pull request
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.
graphite-app bot
pushed a commit
that referenced
this pull request
Aug 9, 2025
…`TypeId`s (#12930) Follow-on after #12864. Pure refactor - does not alter generated code. There's a couple of things going on in this PR. Firstly, perf: * Prefer comparing `TypeId`s over string comparison, because it's cheaper. * Compile a single `Vec` of all types which have no following node at the start (including those listed in `AST_NODE_WITHOUT_FOLLOWING_NODE_LIST`), rather than checking 2 `Vec`s each time in `generate_struct_impls`. Secondly, the code previously was relying on the fact that almost all of `Statement`s variants have the same name as the types those variants contain e.g.: ```rs pub enum Statement<'a> { BlockStatement(Box<'a, BlockStatement<'a>>), // ... } ``` But that the names match is a bit of a co-incidence. This PR makes it so we don't rely on that co-incidence, and instead makes the "no following node" list from the actual *types* of the variants. This change reveals a side-effect of the previous behavior which may or may not be intentional. The only variants of `Statement` where the name of the variant and name of the *type* of the variant don't match are `Function` and `Class`. To maintain the same output as before, I've added an exclude list `AST_NODE_WITH_FOLLOWING_NODE_LIST` containing these 2 types. Presumably the reason why these 2 need an exclusion is because `Function` and `Class` can be either a `Statement` or an `Expression`. I don't know if this may be problematic and might need logic elsewhere to handle them differently, depending on the context? Note: `TypeDef::innermost_type` is to get the `TypeId` of the inner type of a variant (e.g. `BlockStatement`), rather than the type which is the actual enum variant (e.g. `Box<BlockStatement>`). @Dunqing I don't know the formatter at all, so these changes may be unhelpful. Feel free to close or modify this PR if so.
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
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.
taearls
pushed a commit
to taearls/oxc
that referenced
this pull request
Aug 12, 2025
…`TypeId`s (oxc-project#12930) Follow-on after oxc-project#12864. Pure refactor - does not alter generated code. There's a couple of things going on in this PR. Firstly, perf: * Prefer comparing `TypeId`s over string comparison, because it's cheaper. * Compile a single `Vec` of all types which have no following node at the start (including those listed in `AST_NODE_WITHOUT_FOLLOWING_NODE_LIST`), rather than checking 2 `Vec`s each time in `generate_struct_impls`. Secondly, the code previously was relying on the fact that almost all of `Statement`s variants have the same name as the types those variants contain e.g.: ```rs pub enum Statement<'a> { BlockStatement(Box<'a, BlockStatement<'a>>), // ... } ``` But that the names match is a bit of a co-incidence. This PR makes it so we don't rely on that co-incidence, and instead makes the "no following node" list from the actual *types* of the variants. This change reveals a side-effect of the previous behavior which may or may not be intentional. The only variants of `Statement` where the name of the variant and name of the *type* of the variant don't match are `Function` and `Class`. To maintain the same output as before, I've added an exclude list `AST_NODE_WITH_FOLLOWING_NODE_LIST` containing these 2 types. Presumably the reason why these 2 need an exclusion is because `Function` and `Class` can be either a `Statement` or an `Expression`. I don't know if this may be problematic and might need logic elsewhere to handle them differently, depending on the context? Note: `TypeDef::innermost_type` is to get the `TypeId` of the inner type of a variant (e.g. `BlockStatement`), rather than the type which is the actual enum variant (e.g. `Box<BlockStatement>`). @Dunqing I don't know the formatter at all, so these changes may be unhelpful. Feel free to close or modify this PR if so.
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
A-formatter
Area - Formatter
C-enhancement
Category - New feature or request
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.

No description provided.