Skip to content
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)!: name AstBuilder enum builders after variant name not type name #8890

Conversation

overlookmotel
Copy link
Contributor

@overlookmotel overlookmotel commented Feb 4, 2025

Correct what I think is a mistake in the naming of AstBuilder methods for enums. Name the builder methods after the enum variant, not the type of the variant. i.e. AstBuilder::expression_identifier not AstBuilder::expression_identifier_reference, following the variant's name:

/// See [`IdentifierReference`] for AST node details.
Identifier(Box<'a, IdentifierReference<'a>>) = 7,

An enum can have 2 variants with the same type (ExportDefaultDeclarationKind does - Function and Class appear twice to represent function/class declarations and expressions), so naming conflicts are possible, and it's confusing.

Mostly this reduces the length of the methods (jsx_child_jsx_text -> jsx_child_text), but a small minority get longer (export_default_declaration_kind_function -> export_default_declaration_kind_function_declaration).

This was referenced Feb 4, 2025
Copy link
Contributor Author

overlookmotel commented Feb 4, 2025


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 A-parser Area - Parser A-minifier Area - Minifier A-ast Area - AST A-transformer Area - Transformer / Transpiler A-isolated-declarations Isolated Declarations labels Feb 4, 2025
@github-actions github-actions bot added A-ast-tools Area - AST tools C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels Feb 4, 2025
Copy link

codspeed-hq bot commented Feb 4, 2025

CodSpeed Performance Report

Merging #8890 will not alter performance

Comparing 02-04-refactor_ast_name_astbuilder_enum_builders_after_variant_name_not_type_name (bbb075d) with 02-04-refactor_ast_record_plural_names_in_plural_attr (893339d)

Summary

✅ 33 untouched benchmarks

Copy link

graphite-app bot commented Feb 4, 2025

Merge activity

@graphite-app graphite-app bot added 0-merge Merge with Graphite Merge Queue and removed 0-merge Merge with Graphite Merge Queue labels Feb 4, 2025
…t type name (#8890)

Correct what I think is a mistake in the naming of `AstBuilder` methods for enums. Name the builder methods after the enum *variant*, not the *type* of the variant. i.e. `AstBuilder::expression_identifier` not `AstBuilder::expression_identifier_reference`, following the variant's name:

https://github.com/oxc-project/oxc/blob/a302e321d5fb67b0619220b9af9bb179e31833d8/crates/oxc_ast/src/ast/js.rs#L71-L72

An enum can have 2 variants with the same type (`ExportDefaultDeclarationKind` does - `Function` and `Class` appear twice to represent function/class declarations and expressions), so naming conflicts are possible, and it's confusing.

Mostly this reduces the length of the methods (`jsx_child_jsx_text` -> `jsx_child_text`), but a small minority get longer (`export_default_declaration_kind_function` -> `export_default_declaration_kind_function_declaration`).
@graphite-app graphite-app bot force-pushed the 02-04-refactor_ast_record_plural_names_in_plural_attr branch from 90ab249 to 893339d Compare February 4, 2025 22:33
@graphite-app graphite-app bot force-pushed the 02-04-refactor_ast_name_astbuilder_enum_builders_after_variant_name_not_type_name branch from c46048a to bbb075d Compare February 4, 2025 22:34
Base automatically changed from 02-04-refactor_ast_record_plural_names_in_plural_attr to main February 4, 2025 22:56
@graphite-app graphite-app bot merged commit bbb075d into main Feb 4, 2025
29 checks passed
@graphite-app graphite-app bot deleted the 02-04-refactor_ast_name_astbuilder_enum_builders_after_variant_name_not_type_name branch February 4, 2025 22:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0-merge Merge with Graphite Merge Queue A-ast Area - AST A-ast-tools Area - AST tools A-isolated-declarations Isolated Declarations A-minifier Area - Minifier A-parser Area - Parser A-transformer Area - Transformer / Transpiler 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.

1 participant