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