Commit f64cd092 authored by Tobias Koppers's avatar Tobias Koppers

reduce code duplication

parent cc81b3e2
...@@ -10,7 +10,7 @@ use turbopack_core::{ ...@@ -10,7 +10,7 @@ use turbopack_core::{
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
reference::{ModuleReferences, SingleChunkableModuleReference}, reference::{ModuleReference, ModuleReferences, SingleChunkableModuleReference},
resolve::ExportUsage, resolve::ExportUsage,
source::OptionSource, source::OptionSource,
}; };
...@@ -43,6 +43,20 @@ fn dynamic_ref_description() -> RcStr { ...@@ -43,6 +43,20 @@ fn dynamic_ref_description() -> RcStr {
rcstr!("next/dynamic reference") rcstr!("next/dynamic reference")
} }
impl NextDynamicEntryModule {
async fn module_reference(&self) -> Result<ResolvedVc<Box<dyn ModuleReference>>> {
Ok(ResolvedVc::upcast(
SingleChunkableModuleReference::new(
Vc::upcast(*self.module),
dynamic_ref_description(),
ExportUsage::all(),
)
.to_resolved()
.await?,
))
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Module for NextDynamicEntryModule { impl Module for NextDynamicEntryModule {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -59,15 +73,7 @@ impl Module for NextDynamicEntryModule { ...@@ -59,15 +73,7 @@ impl Module for NextDynamicEntryModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![self.module_reference().await?]))
SingleChunkableModuleReference::new(
Vc::upcast(*self.module),
dynamic_ref_description(),
ExportUsage::all(),
)
.to_resolved()
.await?,
)]))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> { fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> {
...@@ -99,15 +105,7 @@ impl ChunkableModule for NextDynamicEntryModule { ...@@ -99,15 +105,7 @@ impl ChunkableModule for NextDynamicEntryModule {
impl EcmascriptChunkPlaceable for NextDynamicEntryModule { impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> { async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let module_reference = ResolvedVc::upcast( let module_reference = self.module_reference().await?;
SingleChunkableModuleReference::new(
Vc::upcast(*self.module),
dynamic_ref_description(),
ExportUsage::all(),
)
.to_resolved()
.await?,
);
let mut exports = BTreeMap::new(); let mut exports = BTreeMap::new();
let default = rcstr!("default"); let default = rcstr!("default");
......
...@@ -11,7 +11,7 @@ use turbopack_core::{ ...@@ -11,7 +11,7 @@ use turbopack_core::{
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
reference::ModuleReferences, reference::{ModuleReference, ModuleReferences},
source::OptionSource, source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
...@@ -64,6 +64,16 @@ impl NextServerComponentModule { ...@@ -64,6 +64,16 @@ impl NextServerComponentModule {
} }
} }
impl NextServerComponentModule {
async fn module_reference(&self) -> Result<ResolvedVc<Box<dyn ModuleReference>>> {
Ok(ResolvedVc::upcast(
NextServerComponentModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
))
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Module for NextServerComponentModule { impl Module for NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -80,11 +90,7 @@ impl Module for NextServerComponentModule { ...@@ -80,11 +90,7 @@ impl Module for NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![self.module_reference().await?]))
NextServerComponentModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
)]))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> { fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> {
...@@ -116,12 +122,7 @@ impl ChunkableModule for NextServerComponentModule { ...@@ -116,12 +122,7 @@ impl ChunkableModule for NextServerComponentModule {
impl EcmascriptChunkPlaceable for NextServerComponentModule { impl EcmascriptChunkPlaceable for NextServerComponentModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> { async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let module_reference = ResolvedVc::upcast( let module_reference = self.module_reference().await?;
NextServerComponentModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
);
let mut exports = BTreeMap::new(); let mut exports = BTreeMap::new();
let default = rcstr!("default"); let default = rcstr!("default");
exports.insert( exports.insert(
......
...@@ -11,7 +11,7 @@ use turbopack_core::{ ...@@ -11,7 +11,7 @@ use turbopack_core::{
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsReference, output::OutputAssetsReference,
reference::ModuleReferences, reference::{ModuleReference, ModuleReferences},
source::OptionSource, source::OptionSource,
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
...@@ -44,6 +44,16 @@ impl NextServerUtilityModule { ...@@ -44,6 +44,16 @@ impl NextServerUtilityModule {
} }
} }
impl NextServerUtilityModule {
async fn module_reference(&self) -> Result<ResolvedVc<Box<dyn ModuleReference>>> {
Ok(ResolvedVc::upcast(
NextServerUtilityModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
))
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Module for NextServerUtilityModule { impl Module for NextServerUtilityModule {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -60,11 +70,7 @@ impl Module for NextServerUtilityModule { ...@@ -60,11 +70,7 @@ impl Module for NextServerUtilityModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(&self) -> Result<Vc<ModuleReferences>> { async fn references(&self) -> Result<Vc<ModuleReferences>> {
Ok(Vc::cell(vec![ResolvedVc::upcast( Ok(Vc::cell(vec![self.module_reference().await?]))
NextServerUtilityModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
)]))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -97,11 +103,7 @@ impl ChunkableModule for NextServerUtilityModule { ...@@ -97,11 +103,7 @@ impl ChunkableModule for NextServerUtilityModule {
impl EcmascriptChunkPlaceable for NextServerUtilityModule { impl EcmascriptChunkPlaceable for NextServerUtilityModule {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> { async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let module_reference = ResolvedVc::upcast( let module_reference = self.module_reference().await?;
NextServerUtilityModuleReference::new(Vc::upcast(*self.module))
.to_resolved()
.await?,
);
let mut exports = BTreeMap::new(); let mut exports = BTreeMap::new();
let default = rcstr!("default"); let default = rcstr!("default");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment