Skip to content

Commit

Permalink
fix: ts type for ModuleDTOWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Aug 7, 2024
1 parent 9142885 commit 2b0a045
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use napi::bindgen_prelude::Either3;
use napi::bindgen_prelude::{Either3, FromNapiValue};
use napi_derive::napi;
use rspack_binding_values::ModuleDTOWrapper;
use rspack_napi::regexp::{JsRegExp, JsRegExpExt};
Expand All @@ -11,11 +11,21 @@ use tokio::runtime::Handle;
pub(super) type RawCacheGroupTest =
Either3<String, JsRegExp, ThreadsafeFunction<JsCacheGroupTestCtx, Option<bool>>>;

#[napi(object)]
#[napi(object, object_from_js = false)]
pub struct JsCacheGroupTestCtx {
#[napi(ts_type = "ModuleDTO")]
pub module: ModuleDTOWrapper,
}

impl FromNapiValue for JsCacheGroupTestCtx {
unsafe fn from_napi_value(
_env: napi::sys::napi_env,
_napi_val: napi::sys::napi_value,
) -> napi::Result<Self> {
unreachable!()
}
}

impl<'a> From<CacheGroupTestFnCtx<'a>> for JsCacheGroupTestCtx {
fn from(value: CacheGroupTestFnCtx<'a>) -> Self {
JsCacheGroupTestCtx {
Expand Down
2 changes: 1 addition & 1 deletion crates/rspack_binding_values/src/compilation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl JsCompilation {
.transpose()
}

#[napi(getter)]
#[napi(getter, ts_return_type = "ModuleDTO")]
pub fn modules(&'static self) -> Vec<ModuleDTOWrapper> {
self
.0
Expand Down
10 changes: 0 additions & 10 deletions crates/rspack_binding_values/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,6 @@ impl ToNapiValue for ModuleDTOWrapper {
}
}

impl FromNapiValue for ModuleDTOWrapper {
unsafe fn from_napi_value(env: sys::napi_env, napi_val: sys::napi_value) -> Result<Self> {
let instance: ClassInstance<ModuleDTO> = FromNapiValue::from_napi_value(env, napi_val)?;
Ok(ModuleDTOWrapper {
module_id: instance.module_id,
compilation: instance.compilation,
})
}
}

#[derive(Default)]
#[napi(object)]
pub struct JsModule {
Expand Down

0 comments on commit 2b0a045

Please sign in to comment.