turbopack_ecmascript/side_effect_optimization/locals/
chunk_item.rs1use anyhow::Result;
2use turbo_tasks::{ResolvedVc, Vc};
3use turbopack_core::{
4 chunk::{AsyncModuleInfo, ChunkItem, ChunkType, ChunkingContext},
5 ident::AssetIdent,
6 module::Module,
7 output::OutputAssetsReference,
8};
9
10use crate::{
11 EcmascriptAnalyzableExt,
12 chunk::{EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkType},
13 side_effect_optimization::locals::module::EcmascriptModuleLocalsModule,
14};
15
16#[turbo_tasks::value(shared)]
18pub struct EcmascriptModuleLocalsChunkItem {
19 pub(super) module: ResolvedVc<EcmascriptModuleLocalsModule>,
20 pub(super) chunking_context: ResolvedVc<Box<dyn ChunkingContext>>,
21}
22
23#[turbo_tasks::value_impl]
24impl EcmascriptChunkItem for EcmascriptModuleLocalsChunkItem {
25 #[turbo_tasks::function]
26 fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> {
27 panic!("content() should never be called");
28 }
29
30 #[turbo_tasks::function]
31 async fn content_with_async_module_info(
32 &self,
33 async_module_info: Option<Vc<AsyncModuleInfo>>,
34 _estimated: bool,
35 ) -> Result<Vc<EcmascriptChunkItemContent>> {
36 let module = self.module.await?;
37 let chunking_context = self.chunking_context;
38 let original_module = module.module;
39
40 let analyze = original_module.analyze();
41 let analyze_result = analyze.await?;
42 let async_module_options = analyze_result
43 .async_module
44 .module_options(async_module_info);
45
46 let content = self
47 .module
48 .module_content(*chunking_context, async_module_info);
49
50 Ok(EcmascriptChunkItemContent::new(
51 content,
52 *chunking_context,
53 async_module_options,
54 ))
55 }
56}
57
58#[turbo_tasks::value_impl]
59impl OutputAssetsReference for EcmascriptModuleLocalsChunkItem {}
60
61#[turbo_tasks::value_impl]
62impl ChunkItem for EcmascriptModuleLocalsChunkItem {
63 #[turbo_tasks::function]
64 fn asset_ident(&self) -> Vc<AssetIdent> {
65 self.module.ident()
66 }
67
68 #[turbo_tasks::function]
69 fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
70 *self.chunking_context
71 }
72
73 #[turbo_tasks::function]
74 async fn ty(&self) -> Result<Vc<Box<dyn ChunkType>>> {
75 Ok(Vc::upcast(
76 Vc::<EcmascriptChunkType>::default().resolve().await?,
77 ))
78 }
79
80 #[turbo_tasks::function]
81 fn module(&self) -> Vc<Box<dyn Module>> {
82 *ResolvedVc::upcast(self.module)
83 }
84}