Skip to content

feat: add rspack 1.7 plugin compatibility#6

Merged
scttcper merged 2 commits into
mainfrom
feat-rspack-1-7-compat
Jan 2, 2026
Merged

feat: add rspack 1.7 plugin compatibility#6
scttcper merged 2 commits into
mainfrom
feat-rspack-1-7-compat

Conversation

@scttcper
Copy link
Copy Markdown
Owner

@scttcper scttcper commented Jan 2, 2026

Update swc_core to v54 to align with Rspack 1.7 requirements, enable
swc_ast_unknown for wasm builds, and add Unknown enum handling to keep
plugin behavior stable across newer AST versions.

Refs:

Update swc_core to v54 to align with Rspack 1.7 requirements, enable
swc_ast_unknown for wasm builds, and add Unknown enum handling to keep
plugin behavior stable across newer AST versions.

Refs:
- https://swc.rs/docs/plugin/ecmascript/compatibility#make-your-plugin-compatible
- https://rspack.rs/blog/announcing-1-7
Comment thread src/lib.rs
Comment on lines +363 to +367
Some(ModuleExportName::Ident(ident)) => Some(ident.sym.as_ref()),
Some(ModuleExportName::Str(str)) => str.value.as_str(),
None => Some(named_import.local.sym.as_ref()),
#[cfg(swc_ast_unknown)]
Some(_) => panic!("unknown module export name"),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The match expression for named_import.imported has inconsistent return types. One arm returns &str while others return Option<&str>, which will cause a compilation failure.
Severity: CRITICAL | Confidence: High

🔍 Detailed Analysis

In the visit_mut_import_decl method, a match expression on named_import.imported has arms with inconsistent return types. The arm handling Some(ModuleExportName::Str(str)) returns a bare &str via str.value.as_str(), while other arms correctly return an Option<&str>. This type mismatch between &str and Option<&str> is a violation of Rust's type system rules and will cause the compiler to fail the build with a type error.

💡 Suggested Fix

To ensure type consistency across all match arms, the arm for Some(ModuleExportName::Str(str)) should wrap its return value in Some(). The line should be changed to Some(ModuleExportName::Str(str)) => Some(str.value.as_str()).

🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: src/lib.rs#L363-L367

Potential issue: In the `visit_mut_import_decl` method, a `match` expression on
`named_import.imported` has arms with inconsistent return types. The arm handling
`Some(ModuleExportName::Str(str))` returns a bare `&str` via `str.value.as_str()`, while
other arms correctly return an `Option<&str>`. This type mismatch between `&str` and
`Option<&str>` is a violation of Rust's type system rules and will cause the compiler to
fail the build with a type error.

Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 8117132

@scttcper scttcper merged commit 8d94c1d into main Jan 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant