Download next.js/turbopack/crates/turbopack-ecmascript/src/merged_module.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.58 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/merged_module.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript/src/merged_module.rs
-
curl -L -o merged_module.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/merged_module.rs
5.58 kB
| use anyhow::{Context, Result}; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{ | |
| AsyncModuleInfo, ChunkItem, ChunkType, ChunkableModule, ChunkingContext, | |
| MergeableModuleExposure, MergeableModules, MergeableModulesExposed, | |
| }, | |
| ident::AssetIdent, | |
| module::Module, | |
| module_graph::ModuleGraph, | |
| reference::ModuleReferences, | |
| }; | |
| use crate::{ | |
| EcmascriptAnalyzable, EcmascriptModuleContent, EcmascriptOptions, | |
| chunk::{EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkType}, | |
| }; | |
| pub(crate) struct MergedEcmascriptModule { | |
| modules: Vec<( | |
| ResolvedVc<Box<dyn EcmascriptAnalyzable>>, | |
| MergeableModuleExposure, | |
| )>, | |
| entry_points: Vec<ResolvedVc<Box<dyn EcmascriptAnalyzable>>>, | |
| options: ResolvedVc<EcmascriptOptions>, | |
| } | |
| impl MergedEcmascriptModule { | |
| pub async fn new( | |
| modules: Vc<MergeableModulesExposed>, | |
| entry_points: Vc<MergeableModules>, | |
| options: ResolvedVc<EcmascriptOptions>, | |
| ) -> Result<ResolvedVc<Self>> { | |
| Ok(MergedEcmascriptModule { | |
| modules: modules | |
| .await? | |
| .iter() | |
| .map(|(m, exposed)| { | |
| Ok(( | |
| ResolvedVc::try_sidecast::<Box<dyn EcmascriptAnalyzable>>(*m) | |
| .context("expected EcmascriptAnalyzable")?, | |
| *exposed, | |
| )) | |
| }) | |
| .collect::<Result<Vec<_>>>()?, | |
| entry_points: entry_points | |
| .await? | |
| .iter() | |
| .map(|m| { | |
| ResolvedVc::try_sidecast::<Box<dyn EcmascriptAnalyzable>>(*m) | |
| .context("expected EcmascriptAnalyzable") | |
| }) | |
| .collect::<Result<Vec<_>>>()?, | |
| options, | |
| } | |
| .resolved_cell()) | |
| } | |
| } | |
| impl Asset for MergedEcmascriptModule { | |
| fn content(&self) -> Vc<AssetContent> { | |
| panic!("content() should not be called"); | |
| } | |
| } | |
| impl Module for MergedEcmascriptModule { | |
| fn ident(&self) -> Vc<AssetIdent> { | |
| // This purposely reuses the module's ident as it has replaced the original module, thus | |
| // there can never be a collision. | |
| self.entry_points.first().unwrap().ident() | |
| } | |
| async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { | |
| panic!("references() should not be called"); | |
| } | |
| async fn is_self_async(&self) -> Result<Vc<bool>> { | |
| panic!("is_self_async() should not be called"); | |
| } | |
| } | |
| impl ChunkableModule for MergedEcmascriptModule { | |
| fn as_chunk_item( | |
| self: ResolvedVc<Self>, | |
| _module_graph: ResolvedVc<ModuleGraph>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| ) -> Vc<Box<dyn ChunkItem>> { | |
| Vc::upcast( | |
| MergedEcmascriptModuleChunkItem { | |
| module: self, | |
| chunking_context, | |
| } | |
| .cell(), | |
| ) | |
| } | |
| } | |
| struct MergedEcmascriptModuleChunkItem { | |
| module: ResolvedVc<MergedEcmascriptModule>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| } | |
| impl ChunkItem for MergedEcmascriptModuleChunkItem { | |
| fn asset_ident(&self) -> Vc<AssetIdent> { | |
| self.module.ident() | |
| } | |
| fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> { | |
| *ResolvedVc::upcast(self.chunking_context) | |
| } | |
| async fn ty(&self) -> Result<Vc<Box<dyn ChunkType>>> { | |
| Ok(Vc::upcast( | |
| Vc::<EcmascriptChunkType>::default().resolve().await?, | |
| )) | |
| } | |
| fn module(&self) -> Vc<Box<dyn Module>> { | |
| *ResolvedVc::upcast(self.module) | |
| } | |
| } | |
| impl EcmascriptChunkItem for MergedEcmascriptModuleChunkItem { | |
| fn content(self: Vc<Self>) -> Vc<EcmascriptChunkItemContent> { | |
| panic!("content() should not be called"); | |
| } | |
| async fn content_with_async_module_info( | |
| &self, | |
| async_module_info: Option<Vc<AsyncModuleInfo>>, | |
| ) -> Result<Vc<EcmascriptChunkItemContent>> { | |
| let module = self.module.await?; | |
| let modules = &module.modules; | |
| let entry_points = &module.entry_points; | |
| let options = modules | |
| .iter() | |
| .map(|(m, _)| { | |
| let Some(m) = ResolvedVc::try_downcast::<Box<dyn EcmascriptAnalyzable>>(*m) else { | |
| anyhow::bail!("Expected EcmascriptAnalyzable in scope hoisting group"); | |
| }; | |
| Ok(m.module_content_options(*self.chunking_context, async_module_info)) | |
| }) | |
| .collect::<Result<Vec<_>>>()?; | |
| let content = EcmascriptModuleContent::new_merged( | |
| modules.clone(), | |
| options, | |
| ResolvedVc::deref_vec(entry_points.clone()), | |
| ); | |
| // Currently, merged modules never include async modules. | |
| let async_module_options = Vc::cell(None); | |
| Ok(EcmascriptChunkItemContent::new( | |
| content, | |
| *self.chunking_context, | |
| async_module_options, | |
| )) | |
| } | |
| } | |