From e06bb4b9a2243633ac0cdea180f1e5b5ff9179ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Donny/=EA=B0=95=EB=8F=99=EC=9C=A4?= Date: Sat, 30 Nov 2024 08:51:41 +0900 Subject: [PATCH] refactor(turbopack): Use `ResolvedVc` for struct fields in `turbopack-ecmascript` (#73302) --- .../server_component_module.rs | 18 ++++++++++-------- .../turbopack-core/src/source_map/mod.rs | 7 ++++++- .../crates/turbopack-ecmascript/src/lib.rs | 2 +- .../src/references/async_module.rs | 4 ++-- .../src/references/external_module.rs | 2 +- .../turbopack-ecmascript/src/references/mod.rs | 4 ++-- .../side_effect_optimization/facade/module.rs | 4 ++-- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/crates/next-core/src/next_server_component/server_component_module.rs b/crates/next-core/src/next_server_component/server_component_module.rs index 1c352ef595367..0de53b10d5ece 100644 --- a/crates/next-core/src/next_server_component/server_component_module.rs +++ b/crates/next-core/src/next_server_component/server_component_module.rs @@ -111,25 +111,27 @@ impl ChunkableModule for NextServerComponentModule { #[turbo_tasks::value_impl] impl EcmascriptChunkPlaceable for NextServerComponentModule { #[turbo_tasks::function] - fn get_exports(&self) -> Vc { - let module_reference = Vc::upcast(NextServerComponentModuleReference::new(Vc::upcast( - *self.module, - ))); + async fn get_exports(&self) -> Result> { + let module_reference = ResolvedVc::upcast( + NextServerComponentModuleReference::new(Vc::upcast(*self.module)) + .to_resolved() + .await?, + ); let mut exports = BTreeMap::new(); exports.insert( "default".into(), - EsmExport::ImportedBinding(module_reference, "default".into(), false), + EsmExport::ImportedBinding(*module_reference, "default".into(), false), ); - EcmascriptExports::EsmExports( + Ok(EcmascriptExports::EsmExports( EsmExports { exports, - star_exports: vec![module_reference], + star_exports: vec![*module_reference], } .resolved_cell(), ) - .cell() + .cell()) } } diff --git a/turbopack/crates/turbopack-core/src/source_map/mod.rs b/turbopack/crates/turbopack-core/src/source_map/mod.rs index d77973d8a6003..a8c6312b1c332 100644 --- a/turbopack/crates/turbopack-core/src/source_map/mod.rs +++ b/turbopack/crates/turbopack-core/src/source_map/mod.rs @@ -8,7 +8,7 @@ use regex::Regex; use serde::{Deserialize, Deserializer, Serialize, Serializer}; use sourcemap::{DecodedMap, SourceMap as RegularMap, SourceMapBuilder, SourceMapIndex}; use turbo_rcstr::RcStr; -use turbo_tasks::{TryJoinIterExt, ValueToString, Vc}; +use turbo_tasks::{ResolvedVc, TryJoinIterExt, ValueToString, Vc}; use turbo_tasks_fs::{ rope::{Rope, RopeBuilder}, File, FileContent, FileSystem, FileSystemPath, VirtualFileSystem, @@ -68,6 +68,11 @@ impl OptionSourceMap { } } +impl OptionSourceMap { + pub fn none_resolved() -> ResolvedVc { + ResolvedVc::cell(None) + } +} #[turbo_tasks::value(transparent)] #[derive(Clone, Debug)] pub struct Tokens(Vec); diff --git a/turbopack/crates/turbopack-ecmascript/src/lib.rs b/turbopack/crates/turbopack-ecmascript/src/lib.rs index 551bc19fbf258..f74b1246e07f1 100644 --- a/turbopack/crates/turbopack-ecmascript/src/lib.rs +++ b/turbopack/crates/turbopack-ecmascript/src/lib.rs @@ -721,7 +721,7 @@ impl EcmascriptModuleContent { references: Vc, code_generation: Vc, async_module: Vc, - source_map: Vc, + source_map: ResolvedVc, exports: Vc, async_module_info: Option>, ) -> Result> { diff --git a/turbopack/crates/turbopack-ecmascript/src/references/async_module.rs b/turbopack/crates/turbopack-ecmascript/src/references/async_module.rs index 67520294e2a6a..dceb9d4ddba8e 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/async_module.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/async_module.rs @@ -6,7 +6,7 @@ use swc_core::{ quote, }; use turbo_tasks::{ - trace::TraceRawVcs, FxIndexSet, ReadRef, TryFlatJoinIterExt, TryJoinIterExt, Vc, + trace::TraceRawVcs, FxIndexSet, ReadRef, ResolvedVc, TryFlatJoinIterExt, TryJoinIterExt, Vc, }; use turbopack_core::{ chunk::{ @@ -51,7 +51,7 @@ pub struct AsyncModule { /// Option<[AsyncModule]>. #[turbo_tasks::value(transparent)] -pub struct OptionAsyncModule(Option>); +pub struct OptionAsyncModule(Option>); #[turbo_tasks::value_impl] impl OptionAsyncModule { diff --git a/turbopack/crates/turbopack-ecmascript/src/references/external_module.rs b/turbopack/crates/turbopack-ecmascript/src/references/external_module.rs index bdb6d4304ed1a..3549fdbf8a9f3 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/external_module.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/external_module.rs @@ -164,7 +164,7 @@ impl EcmascriptChunkPlaceable for CachedExternalModule { has_top_level_await: true, import_externals: true, } - .cell(), + .resolved_cell(), ) } else { None diff --git a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs index 3c5b8057e9748..083ac382e5e88 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs @@ -265,7 +265,7 @@ impl AnalyzeEcmascriptModuleResultBuilder { } /// Sets the analysis result ES export. - pub fn set_async_module(&mut self, async_module: Vc) { + pub fn set_async_module(&mut self, async_module: ResolvedVc) { self.async_module = ResolvedVc::cell(Some(async_module)); } @@ -857,7 +857,7 @@ pub(crate) async fn analyse_ecmascript_module_internal( has_top_level_await, import_externals, } - .cell(); + .resolved_cell(); analysis.set_async_module(async_module); } else if let Some(span) = top_level_await_span { AnalyzeIssue { diff --git a/turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs b/turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs index 5118a8f08f5d2..b58a8c4375e6b 100644 --- a/turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs +++ b/turbopack/crates/turbopack-ecmascript/src/side_effect_optimization/facade/module.rs @@ -278,8 +278,8 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule { } #[turbo_tasks::function] - fn get_async_module(self: Vc) -> Vc { - Vc::cell(Some(self.async_module())) + async fn get_async_module(self: Vc) -> Result> { + Ok(Vc::cell(Some(self.async_module().to_resolved().await?))) } }