Skip to content

Commit

Permalink
add constructor name for concatenated module
Browse files Browse the repository at this point in the history
  • Loading branch information
ahabhgk committed Jan 4, 2025
1 parent 0de9320 commit 7cfe00c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions crates/node_binding/binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export declare class JsExportsInfo {
}

export declare class JsModule {
get constructorName(): string
get context(): string | undefined
get originalSource(): JsCompatSource | undefined
get resource(): string | undefined
Expand Down
7 changes: 7 additions & 0 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ impl JsModule {

#[napi]
impl JsModule {
#[napi(getter)]
pub fn constructor_name(&mut self) -> napi::Result<String> {
let module = self.as_ref()?;

Ok(module.constructor_name().to_string())
}

#[napi(getter)]
pub fn context(&mut self) -> napi::Result<Either<String, ()>> {
let module = self.as_ref()?;
Expand Down
4 changes: 4 additions & 0 deletions crates/rspack_core/src/concatenated_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ impl DependenciesBlock for ConcatenatedModule {
#[cacheable_dyn]
#[async_trait::async_trait]
impl Module for ConcatenatedModule {
fn constructor_name(&self) -> &'static str {
"ConcatenatedModule"
}

fn module_type(&self) -> &ModuleType {
// https://github.com/webpack/webpack/blob/1f99ad6367f2b8a6ef17cce0e058f7a67fb7db18/lib/optimize/ConcatenatedModule.js#L688
&ModuleType::JsEsm
Expand Down
4 changes: 4 additions & 0 deletions crates/rspack_core/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ pub trait Module:
+ Diagnosable
+ ModuleSourceMapConfig
{
fn constructor_name(&self) -> &'static str {
"Module"
}

/// Defines what kind of module this is.
fn module_type(&self) -> &ModuleType;

Expand Down
6 changes: 6 additions & 0 deletions packages/rspack/src/Module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ export class Module {
}

Object.defineProperties(this, {
constructorName: {
enumerable: true,
get(): string {
return module.constructorName;
}
},
type: {
enumerable: true,
get(): string | null {
Expand Down

0 comments on commit 7cfe00c

Please sign in to comment.