Skip to content

Conversation

quininer
Copy link
Contributor

Description:

This is the split of #11100 . Since we need to add unknown variants to the ast enum, this requires a lot of code changes to handle non-exhaustive match. I'm doing this in a separate PR for review.

BREAKING CHANGE:

Related issue (if exists):

Copy link

changeset-bot bot commented Sep 22, 2025

⚠️ No Changeset found

Latest commit: 9ee1a15

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

@kdy1
Copy link
Member

kdy1 commented Sep 22, 2025

Do you think this should go into the main branch?
Can you change the target to ‘dev/rust’?

@quininer
Copy link
Contributor Author

Sure, I can change it.

@quininer quininer force-pushed the r/ast-non-exhaustive branch from 7e9b1f3 to 5c7ab17 Compare September 24, 2025 12:45
Copy link

codspeed-hq bot commented Sep 24, 2025

CodSpeed Performance Report

Merging #11115 will not alter performance

Comparing quininer:r/ast-non-exhaustive (9ee1a15) with main (66428a2)

Summary

✅ 140 untouched

@quininer quininer force-pushed the r/ast-non-exhaustive branch from 5c7ab17 to 58133f1 Compare September 25, 2025 08:02
@quininer quininer force-pushed the r/ast-non-exhaustive branch from 58133f1 to 0c129c5 Compare September 28, 2025 11:49
Copy link

socket-security bot commented Sep 29, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcopyfiles@​2.4.110010010078100
Addedwebpack-cli@​3.3.129710010083100
Addedwebpack-dev-server@​3.11.3969310084100
Addedwebpack@​4.47.09710010093100

View full report

Copy link

socket-security bot commented Sep 29, 2025

Warning

Review the following alerts detected in dependencies.

According to your organization's Security Policy, it is recommended to resolve "Warn" alerts. Learn more about Socket for GitHub.

Action Severity Alert  (click "▶" to expand/collapse)
Warn Critical
[email protected] has a Critical CVE.

CVE: GHSA-fjxv-7rqg-78g4 form-data uses unsafe random function in form-data for choosing boundary (CRITICAL)

Affected versions: < 2.5.4; >= 3.0.0 < 3.0.4; >= 4.0.0 < 4.0.4

Patched version: 2.5.4

From: ?npm/[email protected]

ℹ Read more on: This package | This alert | What is a critical CVE?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn High
[email protected] has Obfuscated code.

Confidence: 0.96

Location: Package overview

From: ?npm/[email protected]npm/[email protected]

ℹ Read more on: This package | This alert | What is obfuscated code?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at [email protected].

Suggestion: Packages should not obfuscate their code. Consider not using packages with obfuscated code.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/[email protected]. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

@quininer quininer force-pushed the r/ast-non-exhaustive branch from 1841181 to 2fb6aad Compare September 29, 2025 08:57
@quininer quininer force-pushed the r/ast-non-exhaustive branch from 69ffe4b to 9ee1a15 Compare September 29, 2025 09:53
@quininer quininer marked this pull request as ready for review September 29, 2025 10:34
@quininer quininer requested review from a team as code owners September 29, 2025 10:34
@Copilot Copilot AI review requested due to automatic review settings September 29, 2025 10:34
@quininer quininer requested review from a team as code owners September 29, 2025 10:34
Copy link

@Copilot 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 implements the first step of adding unknown variants to AST enums by making all AST enums non_exhaustive. The changes enable the introduction of unknown variants in a future PR while ensuring that match statements are properly handled.

  • Adds #[cfg(swc_ast_unknown)] conditional branches to handle future unknown variants
  • Updates the visitor code generator to conditionally generate fallback arms for swc_ecma_ast
  • Makes AST enums non-exhaustive except for specific ones (HTML, XML, regexp) that opt out

Reviewed Changes

Copilot reviewed 185 out of 186 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tools/generate-code/src/main.rs Updates visitor generator to accept string parameter and detect swc_ecma_ast
tools/generate-code/src/generators/visitor.rs Conditionally generates fallback arms for unknown variants in match statements
crates//src/.rs Adds #[cfg(swc_ast_unknown)] fallback branches to existing match statements
crates/*/Cargo.toml Adds lint configuration to recognize the swc_ast_unknown cfg
crates/swc_*_ast/src/base.rs Adds no_unknown attribute to specific AST enums that shouldn't be non-exhaustive
Comments suppressed due to low confidence (2)

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@quininer
Copy link
Contributor Author

I've switched to using a cfg flag instead of a feature to handle unknown variants, which makes it easier to ensure consistent handle.

Also, since all changes are behind the swc_ast_unknown cfg flag, it's not a breaking change. I think it can be safely merged into main branch.

@kdy1 kdy1 self-assigned this Sep 29, 2025
run: |
./scripts/github/run-cargo-hack.sh ${{ matrix.settings.crate }}
- name: Check unknown variant with transforms
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I only added transforms ci since that covers most of sublibrary and is the primary use case for plugin.

// error.
}
#[cfg(swc_ast_unknown)]
_ => (),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've ignored unknown in some places. there's no particular reason for this, maybe panick would be better.

Copy link
Member

Choose a reason for hiding this comment

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

This is a breaking chnage regardless

#[cfg_attr(feature = "rkyv-impl", derive(bytecheck::CheckBytes))]
#[cfg_attr(feature = "rkyv-impl", repr(u32))]
#[cfg_attr(feature = "serde-impl", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(swc_ast_unknown, non_exhaustive)]
Copy link
Member

Choose a reason for hiding this comment

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

Addition of this means ast_node crate has a breaking change

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