diff --git a/crates/turbopack-ecmascript/src/references/async_module.rs b/crates/turbopack-ecmascript/src/references/async_module.rs index 9e737b67df913..a549caa76fdba 100644 --- a/crates/turbopack-ecmascript/src/references/async_module.rs +++ b/crates/turbopack-ecmascript/src/references/async_module.rs @@ -9,6 +9,7 @@ use swc_core::{ use turbo_tasks::{primitives::Bools, trace::TraceRawVcs, TryFlatJoinIterExt, Value, Vc}; use turbopack_core::chunk::availability_info::AvailabilityInfo; +use super::esm::base::ReferencedAsset; use crate::{ chunk::{ esm_scope::{EsmScope, EsmScopeScc}, @@ -156,12 +157,24 @@ impl AsyncModule { .iter() .map(|r| async { let referenced_asset = r.get_referenced_asset().await?; - let ident = if *r.is_async(availability_info).await? { - referenced_asset.get_ident().await? - } else { - None - }; - anyhow::Ok(ident) + Ok(match &*referenced_asset { + ReferencedAsset::OriginalReferenceTypeExternal(_) => { + // TODO(WEB-1259): we need to detect if external modules are esm + None + } + ReferencedAsset::Some(placeable) => { + if *placeable + .get_async_module() + .is_async(availability_info) + .await? + { + referenced_asset.get_ident().await? + } else { + None + } + } + ReferencedAsset::None => None, + }) }) .try_flat_join() .await?; @@ -170,26 +183,8 @@ impl AsyncModule { } #[turbo_tasks::function] - async fn has_top_level_await(self: Vc) -> Result> { - Ok(Vc::cell(self.await?.has_top_level_await)) - } - - #[turbo_tasks::function] - async fn is_self_async(self: Vc) -> Result> { - let this = self.await?; - - if this.has_top_level_await { - return Ok(Vc::cell(true)); - } - - let bools = Vc::::cell( - this.references - .iter() - .map(|r| r.is_external_esm()) - .collect(), - ); - - Ok(bools.any()) + pub(crate) fn is_self_async(&self) -> Vc { + Vc::cell(self.has_top_level_await) } #[turbo_tasks::function] diff --git a/crates/turbopack-ecmascript/src/references/esm/base.rs b/crates/turbopack-ecmascript/src/references/esm/base.rs index 9782d02b77003..be8c022ef1910 100644 --- a/crates/turbopack-ecmascript/src/references/esm/base.rs +++ b/crates/turbopack-ecmascript/src/references/esm/base.rs @@ -8,8 +8,7 @@ use swc_core::{ use turbo_tasks::{Value, ValueToString, Vc}; use turbopack_core::{ chunk::{ - availability_info::AvailabilityInfo, ChunkableModuleReference, ChunkingContext, - ChunkingType, ChunkingTypeOption, ModuleId, + ChunkableModuleReference, ChunkingContext, ChunkingType, ChunkingTypeOption, ModuleId, }, issue::{IssueSeverity, OptionIssueSource}, module::Module, @@ -147,35 +146,6 @@ impl EsmAssetReference { this.request, )) } - - #[turbo_tasks::function] - pub(crate) async fn is_external_esm(self: Vc) -> Result> { - let asset = self.get_referenced_asset().await?; - - let ReferencedAsset::OriginalReferenceTypeExternal(_) = &*asset else { - return Ok(Vc::cell(false)); - }; - - // TODO(WEB-1259): we need to detect if external modules are esm - Ok(Vc::cell(false)) - } - - #[turbo_tasks::function] - pub(crate) async fn is_async( - self: Vc, - availability_info: Value, - ) -> Result> { - if *self.is_external_esm().await? { - return Ok(Vc::cell(true)); - } - - let asset = self.get_referenced_asset().await?; - let ReferencedAsset::Some(placeable) = &*asset else { - return Ok(Vc::cell(false)); - }; - - Ok(placeable.get_async_module().is_async(availability_info)) - } } #[turbo_tasks::value_impl]