Skip to content

Commit

Permalink
fix: resolve the inconsistent type issue in JsModule
Browse files Browse the repository at this point in the history
  • Loading branch information
shulaoda committed Jan 6, 2025
1 parent f81f1c7 commit d55ceb4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
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
17 changes: 10 additions & 7 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,16 @@ 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;
}
Ok(())
pub fn set_user_request(&mut self, val: Either<String, ()>) -> napi::Result<()> {
Ok(match val {

Check failure on line 139 in crates/rspack_binding_values/src/module.rs

View workflow job for this annotation

GitHub Actions / Rust check

passing a unit value to a function
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(_) => {}
})
}

#[napi(getter)]
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) {
module.userRequest = val;
}
}
},
rawRequest: {
Expand Down

0 comments on commit d55ceb4

Please sign in to comment.