feat: add rspack 1.7 plugin compatibility#6
Conversation
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
| 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"), |
There was a problem hiding this comment.
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
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: