From ea2c6007be8f9b8e5157be8f93178f817b682968 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EB=8F=99=EC=9C=A4=20=28Donny=29?= Date: Wed, 2 Oct 2024 16:48:27 +0900 Subject: [PATCH] Simplfy `EcmascriptModulePartAsset::references` --- .../src/tree_shake/asset.rs | 61 ++----------------- 1 file changed, 4 insertions(+), 57 deletions(-) diff --git a/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs b/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs index 59e1cd9f661b09..b6cd95b87ed071 100644 --- a/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs +++ b/turbopack/crates/turbopack-ecmascript/src/tree_shake/asset.rs @@ -1,17 +1,16 @@ -use anyhow::{Context, Result}; +use anyhow::Result; use turbo_tasks::Vc; use turbopack_core::{ asset::{Asset, AssetContent}, chunk::{AsyncModuleInfo, ChunkableModule, ChunkingContext, EvaluatableAsset}, ident::AssetIdent, module::Module, - reference::{ModuleReference, ModuleReferences, SingleModuleReference}, + reference::ModuleReferences, resolve::ModulePart, }; use super::{ - chunk_item::EcmascriptModulePartChunkItem, get_part_id, part_of_module, split, split_module, - PartId, SplitResult, + chunk_item::EcmascriptModulePartChunkItem, part_of_module, split, split_module, SplitResult, }; use crate::{ chunk::{EcmascriptChunkPlaceable, EcmascriptExports}, @@ -134,60 +133,8 @@ impl Module for EcmascriptModulePartAsset { #[turbo_tasks::function] async fn references(&self) -> Result> { - let split_data = split_module(self.full_module).await?; - let analyze = analyze(self.full_module, self.part).await?; - - let deps = match &*split_data { - SplitResult::Ok { deps, .. } => deps, - SplitResult::Failed { .. } => return Ok(analyze.references), - }; - - let part_dep = |part: Vc| -> Vc> { - Vc::upcast(SingleModuleReference::new( - Vc::upcast(EcmascriptModulePartAsset::new(self.full_module, part)), - Vc::cell("ecmascript module part".into()), - )) - }; - - let mut references = analyze.references.await?.to_vec(); - - // Facade depends on evaluation and re-exports - if matches!(&*self.part.await?, ModulePart::Facade) { - references.push(part_dep(ModulePart::evaluation())); - references.push(part_dep(ModulePart::exports())); - return Ok(Vc::cell(references)); - } - - let deps = { - let part_id = get_part_id(&split_data, self.part) - .await - .with_context(|| format!("part {:?} is not found in the module", self.part))?; - - match deps.get(&part_id) { - Some(v) => &**v, - None => &[], - } - }; - - references.extend( - deps.iter() - .filter_map(|part_id| { - Some(part_dep(match part_id { - // This is an internal part that is not for evaluation, so we don't need to - // force-add it. - PartId::Internal(.., false) => return None, - PartId::Internal(part_id, true) => ModulePart::internal(*part_id), - PartId::Export(name) => ModulePart::export(name.clone()), - _ => unreachable!( - "PartId other than Internal and Export should not be used here" - ), - })) - }) - .collect::>(), - ); - - Ok(Vc::cell(references)) + Ok(analyze.references) } }