Download next.js/turbopack/crates/turbopack-ecmascript/src/chunk/batch.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.42 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/chunk/batch.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript/src/chunk/batch.rs
-
curl -L -o batch.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/chunk/batch.rs
3.42 kB
| use anyhow::Result; | |
| use serde::{Deserialize, Serialize}; | |
| use turbo_tasks::{NonLocalValue, ResolvedVc, TaskInput, TryJoinIterExt, Vc, trace::TraceRawVcs}; | |
| use turbopack_core::{ | |
| chunk::{ | |
| ChunkItem, ChunkItemBatchGroup, ChunkItemBatchWithAsyncModuleInfo, | |
| ChunkItemOrBatchWithAsyncModuleInfo, | |
| }, | |
| output::OutputAssets, | |
| }; | |
| use crate::chunk::EcmascriptChunkItemWithAsyncInfo; | |
| pub enum EcmascriptChunkItemOrBatchWithAsyncInfo { | |
| ChunkItem(EcmascriptChunkItemWithAsyncInfo), | |
| Batch(ResolvedVc<EcmascriptChunkBatchWithAsyncInfo>), | |
| } | |
| impl EcmascriptChunkItemOrBatchWithAsyncInfo { | |
| pub async fn from_chunk_item_or_batch( | |
| item: &ChunkItemOrBatchWithAsyncModuleInfo, | |
| ) -> Result<Self> { | |
| Ok(match item { | |
| ChunkItemOrBatchWithAsyncModuleInfo::ChunkItem(chunk_item) => { | |
| EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem( | |
| EcmascriptChunkItemWithAsyncInfo::from_chunk_item(chunk_item)?, | |
| ) | |
| } | |
| &ChunkItemOrBatchWithAsyncModuleInfo::Batch(batch) => { | |
| EcmascriptChunkItemOrBatchWithAsyncInfo::Batch( | |
| EcmascriptChunkBatchWithAsyncInfo::from_batch(*batch) | |
| .to_resolved() | |
| .await?, | |
| ) | |
| } | |
| }) | |
| } | |
| pub fn references(&self) -> Vc<OutputAssets> { | |
| match self { | |
| EcmascriptChunkItemOrBatchWithAsyncInfo::ChunkItem(item) => { | |
| item.chunk_item.references() | |
| } | |
| EcmascriptChunkItemOrBatchWithAsyncInfo::Batch(batch) => batch.references(), | |
| } | |
| } | |
| } | |
| pub struct EcmascriptChunkBatchWithAsyncInfo { | |
| pub chunk_items: Vec<EcmascriptChunkItemWithAsyncInfo>, | |
| } | |
| impl EcmascriptChunkBatchWithAsyncInfo { | |
| pub async fn from_batch(batch: Vc<ChunkItemBatchWithAsyncModuleInfo>) -> Result<Vc<Self>> { | |
| Ok(Self { | |
| chunk_items: batch | |
| .await? | |
| .chunk_items | |
| .iter() | |
| .map(EcmascriptChunkItemWithAsyncInfo::from_chunk_item) | |
| .collect::<Result<Vec<_>>>()?, | |
| } | |
| .cell()) | |
| } | |
| pub async fn references(&self) -> Result<Vc<OutputAssets>> { | |
| let mut references = Vec::new(); | |
| // We expect most references to be empty, and avoiding try_join to avoid allocating the Vec | |
| for item in &self.chunk_items { | |
| references.extend(item.chunk_item.references().await?.into_iter().copied()); | |
| } | |
| Ok(Vc::cell(references)) | |
| } | |
| } | |
| pub struct EcmascriptChunkItemBatchGroup { | |
| pub items: Vec<EcmascriptChunkItemOrBatchWithAsyncInfo>, | |
| } | |
| impl EcmascriptChunkItemBatchGroup { | |
| pub async fn from_chunk_item_batch_group( | |
| batch_group: Vc<ChunkItemBatchGroup>, | |
| ) -> Result<Vc<Self>> { | |
| Ok(Self { | |
| items: batch_group | |
| .await? | |
| .items | |
| .iter() | |
| .map(EcmascriptChunkItemOrBatchWithAsyncInfo::from_chunk_item_or_batch) | |
| .try_join() | |
| .await?, | |
| } | |
| .cell()) | |
| } | |
| } | |