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

🦋 Changeset detected

Latest commit: da866fd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another 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 (da866fd) with main (9353763)1

Summary

✅ 140 untouched

Footnotes

  1. No successful run was found on main (dfe9670) during the generation of this report, so 9353763 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@quininer quininer force-pushed the r/ast-non-exhaustive branch 2 times, most recently 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
Added@​types/​react-dom@​16.9.251001007595100
Added@​types/​react@​16.14.671001007896100
Addedcopyfiles@​2.4.110010010078100
Addedwebpack-cli@​3.3.129710010083100
Added@​actions/​core@​1.11.19910010084100
Addedwebpack-dev-server@​3.11.3968810084100
Addedreact-dom@​16.14.01001009097100
Added@​antfu/​ni@​0.21.129710010091100
Addedwebpack@​4.47.09710010097100

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 2 times, most recently 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
@kdy1
Copy link
Member

kdy1 commented Oct 10, 2025

I updated your branch to use patch commands

@quininer quininer force-pushed the r/ast-non-exhaustive branch from d8eb351 to 909addf Compare October 10, 2025 05:10
@Copilot Copilot AI review requested due to automatic review settings October 11, 2025 09:55
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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@@ -0,0 +1,5 @@
---
ast_node: major
Copy link
Member

@kdy1 kdy1 Oct 11, 2025

Choose a reason for hiding this comment

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

I added ast_node: major because I don't want to see complains about breaking changes published wrongly

Copy link
Member

@kdy1 kdy1 left a comment

Choose a reason for hiding this comment

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

Thank you! Nice work!

@kdy1 kdy1 changed the title refactor(ast): Make ast enum non_exhaustive refactor(ast_node): Make AST enums non_exhaustive Oct 12, 2025
@kdy1 kdy1 added this to the Planned milestone Oct 12, 2025
@kdy1 kdy1 merged commit f328e4a into swc-project:main Oct 12, 2025
176 checks passed
@quininer quininer deleted the r/ast-non-exhaustive branch October 12, 2025 15:13
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