Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve the inconsistent type issue in JsModule #8939

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export declare class JsModule {
get nameForCondition(): string | undefined
get request(): string | undefined
get userRequest(): string | undefined
set userRequest(val: string)
set userRequest(val: string | undefined)
get rawRequest(): string | undefined
get factoryMeta(): JsFactoryMeta | undefined
get type(): string
Expand Down
14 changes: 9 additions & 5 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,15 @@ impl JsModule {
}

#[napi(setter)]
pub fn set_user_request(&mut self, val: String) -> napi::Result<()> {
let module: &mut dyn Module = self.as_mut()?;

if let Ok(normal_module) = module.try_as_normal_module_mut() {
*normal_module.user_request_mut() = val;
pub fn set_user_request(&mut self, val: Either<String, ()>) -> napi::Result<()> {
match val {
Either::A(val) => {
let module: &mut dyn Module = self.as_mut()?;
if let Ok(normal_module) = module.try_as_normal_module_mut() {
*normal_module.user_request_mut() = val;
}
}
Either::B(_) => {}
}
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions packages/rspack/src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,10 @@ export class Module {
get(): string | undefined {
return module.userRequest;
},
set(val: string) {
module.userRequest = val;
set(val: string | undefined) {
if (val) {
SyMind marked this conversation as resolved.
Show resolved Hide resolved
module.userRequest = val;
}
}
},
rawRequest: {
Expand Down
Loading