Skip to content

Conversation

@kdy1
Copy link
Member

@kdy1 kdy1 commented Nov 19, 2025

No description provided.

@kdy1 kdy1 added this to the Planned milestone Nov 19, 2025
Copilot AI review requested due to automatic review settings November 19, 2025 16:40
@kdy1 kdy1 requested a review from a team as a code owner November 19, 2025 16:40
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

⚠️ No Changeset found

Latest commit: c25f88d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@claude
Copy link
Contributor

claude bot commented Nov 19, 2025

Code Review for PR #11308

Summary

This PR adds #[non_exhaustive] attributes to various transformer option structs to prevent breaking changes when adding fields in the future. This is a good API design decision for a public library.


🔴 Critical Issue: Formatting

The cargo fmt check is failing. Most files have incorrect formatting where #[non_exhaustive] is placed on the same line as #[derive(Debug, Default)]:

// ❌ Incorrect (current code)
#[derive(Debug, Default)]#[non_exhaustive]
pub struct DecoratorOptions {}

Required fix:

// ✅ Correct
#[derive(Debug, Default)]
#[non_exhaustive]
pub struct DecoratorOptions {}

Affected files:

  • crates/swc_ecma_transformer/src/decorators/mod.rs:5
  • crates/swc_ecma_transformer/src/es2015/mod.rs:5
  • crates/swc_ecma_transformer/src/es2016/mod.rs:5
  • crates/swc_ecma_transformer/src/es2017/mod.rs:5
  • crates/swc_ecma_transformer/src/es2018/mod.rs:5
  • crates/swc_ecma_transformer/src/es2019/mod.rs:5
  • crates/swc_ecma_transformer/src/es2020/mod.rs:5
  • crates/swc_ecma_transformer/src/es2021/mod.rs:5
  • crates/swc_ecma_transformer/src/es2022/mod.rs:5
  • crates/swc_ecma_transformer/src/es2026/mod.rs:5
  • crates/swc_ecma_transformer/src/jsx/mod.rs:5
  • crates/swc_ecma_transformer/src/typescript/mod.rs:5
  • crates/swc_ecma_transformer/src/options/mod.rs:8
  • crates/swc_ecma_transformer/src/options/mod.rs:17

Only these files are correctly formatted:

  • crates/swc_ecma_transformer/src/bugfix/mod.rs:6
  • crates/swc_ecma_transformer/src/regexp.rs:7

Action required: Run cargo fmt --all as specified in CLAUDE.md point 8 before committing.


✅ Code Quality

Positive aspects:

  1. API Design: Using #[non_exhaustive] on these option structs is the correct approach for forward compatibility
  2. Consistency: Applied uniformly across all transformer option types
  3. Purpose: Prevents breaking changes when adding new configuration fields in future versions
  4. Semantic Correctness: These are all configuration structs that should be non-exhaustive

📋 Additional Observations

  1. Empty Structs: All modified structs are currently empty ({}), which makes #[non_exhaustive] especially valuable as fields will likely be added later

  2. Pattern Consistency: The PR correctly applies the attribute to:

    • Individual transformer options (ES2015-ES2026, JSX, TypeScript, etc.)
    • Composite option structs (Options, EnvOptions)
    • Special options (RegExpOptions, which already has fields)
  3. No Breaking Changes: This is a non-breaking change for downstream consumers as it only restricts struct literal construction, which wasn't possible anyway due to these being in the option modules


🔍 Security & Performance

  • No security concerns identified
  • No performance impact (compile-time only attribute)

🧪 Test Coverage

No tests need to be added for this change as:

  • It's a compile-time API compatibility feature
  • Existing tests will continue to work unchanged
  • The attribute prevents direct struct instantiation (which already requires Default::default() or the constructor pattern used here)

✅ Recommendation

Approve after formatting fix. Once you run cargo fmt --all and push the changes, this PR will be good to merge.

Command to fix:

cargo fmt --all

This aligns with repository guideline #8 from CLAUDE.md.

Copilot finished reviewing on behalf of kdy1 November 19, 2025 16:42
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 adds the #[non_exhaustive] attribute to various option structs throughout the transformer codebase to prevent breaking changes when new fields are added in the future. This allows the library to evolve without breaking downstream users who construct these structs.

Key Changes:

  • Added #[non_exhaustive] attribute to 16 option structs across the transformer modules
  • Applied to various ES version options (ES2015-ES2026), TypeScript, JSX, RegExp, Decorator, Bugfix, and top-level Options structs

Reviewed Changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
crates/swc_ecma_transformer/src/typescript/mod.rs Added #[non_exhaustive] to TypescriptOptions struct
crates/swc_ecma_transformer/src/regexp.rs Added #[non_exhaustive] to RegExpOptions struct
crates/swc_ecma_transformer/src/options/mod.rs Added #[non_exhaustive] to Options and EnvOptions structs
crates/swc_ecma_transformer/src/jsx/mod.rs Added #[non_exhaustive] to JsxOptions struct
crates/swc_ecma_transformer/src/es2026/mod.rs Added #[non_exhaustive] to Es2026Options struct
crates/swc_ecma_transformer/src/es2022/mod.rs Added #[non_exhaustive] to Es2022Options struct
crates/swc_ecma_transformer/src/es2021/mod.rs Added #[non_exhaustive] to Es2021Options struct
crates/swc_ecma_transformer/src/es2020/mod.rs Added #[non_exhaustive] to Es2020Options struct
crates/swc_ecma_transformer/src/es2019/mod.rs Added #[non_exhaustive] to Es2019Options struct
crates/swc_ecma_transformer/src/es2018/mod.rs Added #[non_exhaustive] to Es2018Options struct
crates/swc_ecma_transformer/src/es2017/mod.rs Added #[non_exhaustive] to Es2017Options struct
crates/swc_ecma_transformer/src/es2016/mod.rs Added #[non_exhaustive] to Es2016Options struct
crates/swc_ecma_transformer/src/es2015/mod.rs Added #[non_exhaustive] to Es2015Options struct
crates/swc_ecma_transformer/src/decorators/mod.rs Added #[non_exhaustive] to DecoratorOptions struct
crates/swc_ecma_transformer/src/bugfix/mod.rs Added #[non_exhaustive] to BugfixOptions struct

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct TypescriptOptions {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2026Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2022Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2020Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2019Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct JsxOptions {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2021Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2017Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct Es2015Options {}

Copilot uses AI. Check for mistakes.

use crate::TraverseCtx;

#[derive(Debug, Default)]
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

The #[non_exhaustive] attribute should be placed on a separate line from #[derive(Debug, Default)] for better readability and consistency with Rust formatting conventions. It should be:

#[derive(Debug, Default)]
#[non_exhaustive]
pub struct DecoratorOptions {}

Copilot uses AI. Check for mistakes.
@claude
Copy link
Contributor

claude bot commented Nov 19, 2025

Code Review

Summary

This PR adds the attribute to all public option structs in the transformer crate to prevent breaking changes when new fields are added in the future. This is a defensive API design practice that's well-suited for public library code.

Positive Aspects ✓

  1. API Stability: The attribute is the correct Rust idiom for preventing breaking changes when adding fields to public structs. This allows the library to evolve without breaking downstream code.

  2. Consistent Application: The attribute has been applied consistently across all option structs:

    • Empty structs (e.g., Es2015Options, TypescriptOptions)
    • Structs with fields (e.g., RegExpOptions)
    • Container structs (e.g., Options, EnvOptions)
  3. Minimal Change: The PR is focused and surgical - only adding the necessary attribute without any unnecessary refactoring.

  4. Good Timing: Adding this before these structs accumulate more fields is better than retrofitting later, as it prevents any user code from relying on exhaustive pattern matching.

Code Quality ✓

  • Formatting: Changes appear properly formatted
  • Documentation: No documentation changes needed as the attribute is self-explanatory
  • No Breaking Change: This change itself is not breaking since Default is already implemented

Considerations

  1. Empty Structs: While applying #[non_exhaustive] to empty structs like Es2015Options {} is defensive, consider whether these will actually gain fields in the future. However, keeping them consistent is reasonable for API uniformity.

  2. Constructor Pattern: With #[non_exhaustive], users cannot use struct literal syntax to construct these types outside the crate. Since all structs have #[derive(Default)], this is fine - users should use Default::default() or potentially provide explicit constructors if needed in the future.

  3. Pattern Matching: Users can no longer exhaustively destructure these structs in match expressions outside the crate, but since these are configuration structs, this is unlikely to be a concern.

Test Coverage

No new tests are needed as this is a compile-time API change that doesn't affect runtime behavior. The existing tests should continue to pass.

Performance

No performance impact - this is a compile-time-only attribute.

Security

No security implications.

Recommendation

Approve

This is a well-reasoned change that improves the library's API stability story. The consistent application across all option structs is good practice and aligns with Rust API guidelines for public library crates.

@kdy1 kdy1 disabled auto-merge November 19, 2025 16:47
@kdy1 kdy1 merged commit 45827fa into main Nov 19, 2025
184 checks passed
@kdy1 kdy1 deleted the kdy1/tr-bc branch November 19, 2025 16:47
@github-actions
Copy link
Contributor

Binary Sizes

File Size
swc.linux-x64-gnu.node 31M (31931976 bytes)

Commit: 202ac73

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #11308 will not alter performance

Comparing kdy1/tr-bc (c25f88d) with main (58f2602)

Summary

✅ 138 untouched

@kdy1 kdy1 modified the milestones: Planned, 1.15.3 Nov 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants