Download next.js/turbopack/crates/turbopack-ecmascript/src/async_chunk/module.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.63 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/async_chunk/module.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript/src/async_chunk/module.rs
-
curl -L -o module.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/async_chunk/module.rs
2.63 kB
| use anyhow::Result; | |
| use turbo_rcstr::rcstr; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{ChunkableModule, ChunkingContext, availability_info::AvailabilityInfo}, | |
| ident::AssetIdent, | |
| module::Module, | |
| module_graph::ModuleGraph, | |
| reference::{ModuleReferences, SingleModuleReference}, | |
| }; | |
| use crate::async_chunk::chunk_item::AsyncLoaderChunkItem; | |
| /// The AsyncLoaderModule is a module that loads another module async, by | |
| /// putting it into a separate chunk group. | |
| pub struct AsyncLoaderModule { | |
| pub inner: ResolvedVc<Box<dyn ChunkableModule>>, | |
| pub chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| pub availability_info: AvailabilityInfo, | |
| } | |
| impl AsyncLoaderModule { | |
| pub fn new( | |
| module: ResolvedVc<Box<dyn ChunkableModule>>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| availability_info: AvailabilityInfo, | |
| ) -> Vc<Self> { | |
| Self::cell(AsyncLoaderModule { | |
| inner: module, | |
| chunking_context, | |
| availability_info, | |
| }) | |
| } | |
| pub fn asset_ident_for(module: Vc<Box<dyn ChunkableModule>>) -> Vc<AssetIdent> { | |
| module.ident().with_modifier(rcstr!("async loader")) | |
| } | |
| } | |
| impl Module for AsyncLoaderModule { | |
| fn ident(&self) -> Vc<AssetIdent> { | |
| Self::asset_ident_for(*self.inner) | |
| } | |
| async fn references(self: Vc<Self>) -> Result<Vc<ModuleReferences>> { | |
| Ok(Vc::cell(vec![ResolvedVc::upcast( | |
| SingleModuleReference::new( | |
| *ResolvedVc::upcast(self.await?.inner), | |
| rcstr!("async module"), | |
| ) | |
| .to_resolved() | |
| .await?, | |
| )])) | |
| } | |
| } | |
| impl Asset for AsyncLoaderModule { | |
| fn content(&self) -> Vc<AssetContent> { | |
| panic!("content() should not be called"); | |
| } | |
| } | |
| impl ChunkableModule for AsyncLoaderModule { | |
| fn as_chunk_item( | |
| self: ResolvedVc<Self>, | |
| module_graph: ResolvedVc<ModuleGraph>, | |
| chunking_context: ResolvedVc<Box<dyn ChunkingContext>>, | |
| ) -> Vc<Box<dyn turbopack_core::chunk::ChunkItem>> { | |
| Vc::upcast( | |
| AsyncLoaderChunkItem { | |
| chunking_context, | |
| module_graph, | |
| module: self, | |
| } | |
| .cell(), | |
| ) | |
| } | |
| } | |