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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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) {
Copy link
Member

Choose a reason for hiding this comment

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

what if val is an empty string ''?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The userRequest property exists only when the module is a NormalModule; it does not exist in other cases. When the userRequest of a NormalModule is an empty string (''), it might overlap in meaning with cases where the userRequest is absent in non-NormalModule instances. I am uncertain whether this change is appropriate.

module.userRequest = val;
}
}
},
rawRequest: {
Expand Down
Loading