Skip to content

refactor(ast)!: remove TSMappedTypeModifierOperator::None variant#10749

Merged
graphite-app[bot] merged 1 commit intomainfrom
05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant
May 1, 2025
Merged

refactor(ast)!: remove TSMappedTypeModifierOperator::None variant#10749
graphite-app[bot] merged 1 commit intomainfrom
05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant

Conversation

@overlookmotel
Copy link
Member

@overlookmotel overlookmotel commented May 1, 2025

It seems odd for TSMappedTypeModifierOperator to have a None variant. It's more conventional to represent "doesn't exist" as Option::None.

Remove the TSMappedTypeModifierOperator::None variant, and use Option<TSMappedTypeModifierOperator> instead of TSMappedTypeModifierOperator.

Both are the same to the compiler due to the niche optimization on Option (Option<TSMappedTypeModifierOperator> is 1 byte), but it just seems more logical to me this way.

Also an unrelated change: Shorten code in codegen and formatter.

@github-actions github-actions bot added A-parser Area - Parser A-ast Area - AST A-codegen Area - Code Generation A-formatter Area - Formatter C-cleanup Category - technical debt or refactoring. Solution not expected to change behavior labels May 1, 2025
Copy link
Member Author

overlookmotel commented May 1, 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.

@overlookmotel overlookmotel marked this pull request as ready for review May 1, 2025 11:31
@codspeed-hq
Copy link

codspeed-hq bot commented May 1, 2025

CodSpeed Instrumentation Performance Report

Merging #10749 will not alter performance

Comparing 05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant (28ceb90) with 05-01-fix_formatter_do_not_ignore_result_of_write_ (38b8184)

Summary

✅ 36 untouched benchmarks

@coderabbitai
Copy link

coderabbitai bot commented May 1, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes revise the representation of the readonly and optional modifiers in TypeScript mapped types across several modules. In the Rust codebase, the TSMappedType struct's readonly and optional fields are updated from the enum type TSMappedTypeModifierOperator to Option<TSMappedTypeModifierOperator>, reflecting that these modifiers may be absent. The None variant is removed from the TSMappedTypeModifierOperator enum, so absence is now indicated by None in the Option type. All pattern matching and formatting logic in code generation and formatting modules is updated to handle these fields as optional values, using Some and None patterns. Parsing logic is also adjusted to assign Some or None appropriately when processing mapped type modifiers. In the TypeScript type definitions, the optional and readonly properties of TSMappedType are changed to allow null, while the modifier operator type itself no longer includes null. No public API signatures are otherwise altered.

Possibly related PRs


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9c53ba and 28ceb90.

⛔ Files ignored due to path filters (5)
  • crates/oxc_ast/src/generated/ast_builder.rs is excluded by !**/generated/**
  • crates/oxc_ast/src/generated/derive_estree.rs is excluded by !**/generated/**
  • crates/oxc_traverse/src/generated/ancestor.rs is excluded by !**/generated/**
  • napi/parser/generated/deserialize/js.js is excluded by !**/generated/**
  • napi/parser/generated/deserialize/ts.js is excluded by !**/generated/**
📒 Files selected for processing (5)
  • crates/oxc_ast/src/ast/ts.rs (1 hunks)
  • crates/oxc_codegen/src/gen.rs (2 hunks)
  • crates/oxc_formatter/src/write/mod.rs (2 hunks)
  • crates/oxc_parser/src/ts/types.rs (2 hunks)
  • npm/oxc-types/types.d.ts (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 050ecd9 and e9c53ba.

⛔ Files ignored due to path filters (5)
  • crates/oxc_ast/src/generated/ast_builder.rs is excluded by !**/generated/**
  • crates/oxc_ast/src/generated/derive_estree.rs is excluded by !**/generated/**
  • crates/oxc_traverse/src/generated/ancestor.rs is excluded by !**/generated/**
  • napi/parser/generated/deserialize/js.js is excluded by !**/generated/**
  • napi/parser/generated/deserialize/ts.js is excluded by !**/generated/**
📒 Files selected for processing (5)
  • crates/oxc_ast/src/ast/ts.rs (1 hunks)
  • crates/oxc_codegen/src/gen.rs (2 hunks)
  • crates/oxc_formatter/src/write/mod.rs (2 hunks)
  • crates/oxc_parser/src/ts/types.rs (2 hunks)
  • npm/oxc-types/types.d.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
crates/oxc_formatter/src/write/mod.rs (2)
npm/oxc-types/types.d.ts (1)
  • TSMappedTypeModifierOperator (1384-1384)
crates/oxc_formatter/src/formatter/builders.rs (1)
  • space (592-594)
crates/oxc_ast/src/ast/ts.rs (1)
npm/oxc-types/types.d.ts (1)
  • TSMappedTypeModifierOperator (1384-1384)
crates/oxc_codegen/src/gen.rs (2)
npm/oxc-types/types.d.ts (1)
  • TSMappedTypeModifierOperator (1384-1384)
crates/oxc_transformer/src/es2018/object_rest_spread.rs (1)
  • p (937-941)
🪛 GitHub Actions: CI
crates/oxc_formatter/src/write/mod.rs

[error] 2908-2913: Rust compiler error E0308: mismatched types in match arms returning write! macro calls which return Result<(), FormatError>, but the surrounding code expects (). Suggested fixes include returning the Result or unwrapping it with expect().


[error] 2909-2911: Repeated Rust compiler error E0308: mismatched types in match arms with write! macro calls returning Result<(), FormatError> instead of (). Suggested fixes include returning the Result or unwrapping it with expect().


[error] 2911-2911: Repeated Rust compiler error E0308: mismatched types in match arm with write! macro call returning Result<(), FormatError> instead of (). Suggested fixes include returning the Result or unwrapping it with expect().

🔇 Additional comments (9)
crates/oxc_ast/src/ast/ts.rs (2)

1448-1448: Improved type representation for optional fields.

The change from TSMappedTypeModifierOperator to Option<TSMappedTypeModifierOperator> for optional and readonly fields is a good refactoring. This follows Rust's idiomatic pattern of using Option::None to represent absence rather than having a special None variant in an enum.

Also applies to: 1458-1458


1462-1475: Streamlined enum by removing redundant None variant.

Removing the None variant from TSMappedTypeModifierOperator and using Option::None instead is a cleaner approach. This change doesn't affect the memory footprint since Rust's niche optimization ensures Option<TSMappedTypeModifierOperator> remains a 1-byte type.

crates/oxc_formatter/src/write/mod.rs (1)

2931-2935: ⚠️ Potential issue

Fix the same type mismatch in optional match arms.

The match arms for optional have the same issue - they're returning Result<(), FormatError> but the code expects ().

Apply this fix to properly handle the return types:

            match self.optional {
-                Some(TSMappedTypeModifierOperator::True) => write!(f, "?")?,
-                Some(TSMappedTypeModifierOperator::Plus) => write!(f, "+?")?,
-                Some(TSMappedTypeModifierOperator::Minus) => write!(f, "-?")?,
-                None => {}
+                Some(TSMappedTypeModifierOperator::True) => write!(f, "?")?,
+                Some(TSMappedTypeModifierOperator::Plus) => write!(f, "+?")?,
+                Some(TSMappedTypeModifierOperator::Minus) => write!(f, "-?")?,
+                None => {}
            }

Note that while the diff appears identical (the ? operators were already present), the context is that these need to be fixed together with the changes to the readonly match arms above.

Likely an incorrect or invalid review comment.

npm/oxc-types/types.d.ts (2)

1378-1379: Proper implementation of the Option pattern

The change to allow null values for the optional and readonly properties aligns with the Rust-side change from using a None enum variant to using Option<TSMappedTypeModifierOperator>. This is a more idiomatic approach in Rust for representing optional values.


1384-1384: Correctly updated type definition

The TSMappedTypeModifierOperator type has been properly updated to exclude null, as the absence of a value is now represented by null at the property level rather than as a variant within the enum itself.

crates/oxc_codegen/src/gen.rs (2)

3170-3174: Correctly updated pattern matching for the readonly field.

The code now properly matches on Option<TSMappedTypeModifierOperator> instead of directly on TSMappedTypeModifierOperator, aligning with the removal of the None variant from the enum. This follows Rust's convention of using Option::None to represent absence of a value.


3191-3195: Correctly updated pattern matching for the optional field.

The code now properly matches on Option<TSMappedTypeModifierOperator> instead of directly on TSMappedTypeModifierOperator, consistent with the change made for the readonly field. This ensures both fields use the same pattern for handling the absence of modifiers.

crates/oxc_parser/src/ts/types.rs (2)

559-566: Approve the refactoring of the readonly field

The code changes correctly initialize readonly as None and set appropriate Some(...) variants based on the token presence, aligning with Rust's idiomatic use of Option to represent absence of a value.


592-605: Approve the refactoring of the optional field

Similar to the readonly field refactoring, the optional field is now properly handled as an Option<TSMappedTypeModifierOperator> instead of using a dedicated None variant in the enum. This change is consistent with the PR's objective and follows Rust conventions.

@overlookmotel overlookmotel changed the base branch from main to graphite-base/10749 May 1, 2025 11:39
@overlookmotel overlookmotel force-pushed the 05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant branch from e9c53ba to 4e64155 Compare May 1, 2025 11:39
@overlookmotel overlookmotel changed the base branch from graphite-base/10749 to 05-01-fix_formatter_do_not_ignore_result_of_write_ May 1, 2025 11:39
@overlookmotel overlookmotel requested a review from Boshen May 1, 2025 11:44
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 1, 2025
Copy link
Member

Boshen commented May 1, 2025

Merge activity

  • May 1, 9:42 AM EDT: The merge label '0-merge' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.

@graphite-app
Copy link
Contributor

graphite-app bot commented May 1, 2025

Merge activity

@graphite-app graphite-app bot force-pushed the 05-01-fix_formatter_do_not_ignore_result_of_write_ branch from c7c4b79 to e5a24c6 Compare May 1, 2025 13:57
graphite-app bot pushed a commit that referenced this pull request May 1, 2025
…10749)

It seems odd for `TSMappedTypeModifierOperator` to have a `None` variant. It's more conventional to represent "doesn't exist" as `Option::None`.

Remove the `TSMappedTypeModifierOperator::None` variant, and use `Option<TSMappedTypeModifierOperator>` instead of `TSMappedTypeModifierOperator`.

Both are the same to the compiler due to the niche optimization on `Option` (`Option<TSMappedTypeModifierOperator>` is 1 byte), but it just seems more logical to me this way.

Also an unrelated change: Shorten code in codegen and formatter.
@graphite-app graphite-app bot force-pushed the 05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant branch from 4e64155 to fe3fc85 Compare May 1, 2025 13:58
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 1, 2025
@Boshen Boshen added the 0-merge Merge with Graphite Merge Queue label May 1, 2025
…10749)

It seems odd for `TSMappedTypeModifierOperator` to have a `None` variant. It's more conventional to represent "doesn't exist" as `Option::None`.

Remove the `TSMappedTypeModifierOperator::None` variant, and use `Option<TSMappedTypeModifierOperator>` instead of `TSMappedTypeModifierOperator`.

Both are the same to the compiler due to the niche optimization on `Option` (`Option<TSMappedTypeModifierOperator>` is 1 byte), but it just seems more logical to me this way.

Also an unrelated change: Shorten code in codegen and formatter.
@graphite-app graphite-app bot force-pushed the 05-01-fix_formatter_do_not_ignore_result_of_write_ branch from e5a24c6 to 38b8184 Compare May 1, 2025 14:50
@graphite-app graphite-app bot force-pushed the 05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant branch from fe3fc85 to 28ceb90 Compare May 1, 2025 14:50
Base automatically changed from 05-01-fix_formatter_do_not_ignore_result_of_write_ to main May 1, 2025 15:02
@graphite-app graphite-app bot removed the 0-merge Merge with Graphite Merge Queue label May 1, 2025
@graphite-app graphite-app bot merged commit 28ceb90 into main May 1, 2025
28 checks passed
@graphite-app graphite-app bot deleted the 05-01-refactor_ast_remove_tsmappedtypemodifieroperator_none_variant branch May 1, 2025 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ast Area - AST A-codegen Area - Code Generation A-formatter Area - Formatter A-parser Area - Parser 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.

2 participants