Download next.js/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 5.55 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs
-
curl -L -o chunk.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-browser/src/ecmascript/chunk.rs
5.55 kB
| use anyhow::Result; | |
| use turbo_rcstr::{RcStr, rcstr}; | |
| use turbo_tasks::{FxIndexSet, ResolvedVc, ValueToString, Vc}; | |
| use turbo_tasks_fs::FileSystemPath; | |
| use turbopack_core::{ | |
| asset::{Asset, AssetContent}, | |
| chunk::{Chunk, ChunkingContext, OutputChunk, OutputChunkRuntimeInfo}, | |
| ident::AssetIdent, | |
| introspect::{Introspectable, IntrospectableChildren}, | |
| output::{OutputAsset, OutputAssets}, | |
| source_map::{GenerateSourceMap, OptionStringifiedSourceMap, SourceMapAsset}, | |
| version::VersionedContent, | |
| }; | |
| use turbopack_ecmascript::chunk::EcmascriptChunk; | |
| use crate::{BrowserChunkingContext, ecmascript::content::EcmascriptBrowserChunkContent}; | |
| /// Development Ecmascript chunk. | |
| pub struct EcmascriptBrowserChunk { | |
| chunking_context: ResolvedVc<BrowserChunkingContext>, | |
| chunk: ResolvedVc<EcmascriptChunk>, | |
| } | |
| impl EcmascriptBrowserChunk { | |
| /// Creates a new [`Vc<EcmascriptDevChunk>`]. | |
| pub fn new( | |
| chunking_context: ResolvedVc<BrowserChunkingContext>, | |
| chunk: ResolvedVc<EcmascriptChunk>, | |
| ) -> Vc<Self> { | |
| EcmascriptBrowserChunk { | |
| chunking_context, | |
| chunk, | |
| } | |
| .cell() | |
| } | |
| async fn source_map(self: Vc<Self>) -> Result<Vc<SourceMapAsset>> { | |
| let this = self.await?; | |
| Ok(SourceMapAsset::new( | |
| Vc::upcast(*this.chunking_context), | |
| this.ident_for_path(), | |
| Vc::upcast(self), | |
| )) | |
| } | |
| } | |
| impl EcmascriptBrowserChunk { | |
| fn ident_for_path(&self) -> Vc<AssetIdent> { | |
| self.chunk | |
| .ident() | |
| .with_modifier(rcstr!("ecmascript dev chunk")) | |
| } | |
| } | |
| impl ValueToString for EcmascriptBrowserChunk { | |
| fn to_string(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("Ecmascript Dev Chunk")) | |
| } | |
| } | |
| impl OutputChunk for EcmascriptBrowserChunk { | |
| async fn runtime_info(&self) -> Result<Vc<OutputChunkRuntimeInfo>> { | |
| Ok(OutputChunkRuntimeInfo { | |
| included_ids: Some(self.chunk.entry_ids().to_resolved().await?), | |
| ..Default::default() | |
| } | |
| .cell()) | |
| } | |
| } | |
| impl EcmascriptBrowserChunk { | |
| async fn own_content(self: Vc<Self>) -> Result<Vc<EcmascriptBrowserChunkContent>> { | |
| let this = self.await?; | |
| Ok(EcmascriptBrowserChunkContent::new( | |
| *this.chunking_context, | |
| self, | |
| this.chunk.chunk_content(), | |
| self.source_map(), | |
| )) | |
| } | |
| pub fn chunk(&self) -> Result<Vc<Box<dyn Chunk>>> { | |
| Ok(Vc::upcast(*self.chunk)) | |
| } | |
| } | |
| impl OutputAsset for EcmascriptBrowserChunk { | |
| async fn path(self: Vc<Self>) -> Result<Vc<FileSystemPath>> { | |
| let this = self.await?; | |
| let ident = this.ident_for_path(); | |
| Ok(this | |
| .chunking_context | |
| .chunk_path(Some(Vc::upcast(self)), ident, None, rcstr!(".js"))) | |
| } | |
| fn size_bytes(self: Vc<Self>) -> Vc<Option<u64>> { | |
| self.own_content().content().len() | |
| } | |
| async fn references(self: Vc<Self>) -> Result<Vc<OutputAssets>> { | |
| let this = self.await?; | |
| let chunk_references = this.chunk.references().await?; | |
| let include_source_map = *this | |
| .chunking_context | |
| .reference_chunk_source_maps(Vc::upcast(self)) | |
| .await?; | |
| let mut references = | |
| Vec::with_capacity(chunk_references.len() + if include_source_map { 1 } else { 0 }); | |
| references.extend(chunk_references.iter().copied()); | |
| if include_source_map { | |
| references.push(ResolvedVc::upcast(self.source_map().to_resolved().await?)); | |
| } | |
| Ok(Vc::cell(references)) | |
| } | |
| } | |
| impl Asset for EcmascriptBrowserChunk { | |
| fn content(self: Vc<Self>) -> Vc<AssetContent> { | |
| self.own_content().content() | |
| } | |
| fn versioned_content(self: Vc<Self>) -> Vc<Box<dyn VersionedContent>> { | |
| Vc::upcast(self.own_content()) | |
| } | |
| } | |
| impl GenerateSourceMap for EcmascriptBrowserChunk { | |
| fn generate_source_map(self: Vc<Self>) -> Vc<OptionStringifiedSourceMap> { | |
| self.own_content().generate_source_map() | |
| } | |
| fn by_section(self: Vc<Self>, section: RcStr) -> Vc<OptionStringifiedSourceMap> { | |
| self.own_content().by_section(section) | |
| } | |
| } | |
| impl Introspectable for EcmascriptBrowserChunk { | |
| fn ty(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("dev ecmascript chunk")) | |
| } | |
| fn title(self: Vc<Self>) -> Vc<RcStr> { | |
| self.path().to_string() | |
| } | |
| fn details(&self) -> Vc<RcStr> { | |
| Vc::cell(rcstr!("generates a development ecmascript chunk")) | |
| } | |
| fn children(&self) -> Result<Vc<IntrospectableChildren>> { | |
| let mut children = FxIndexSet::default(); | |
| let chunk = ResolvedVc::upcast::<Box<dyn Introspectable>>(self.chunk); | |
| children.insert((rcstr!("chunk"), chunk)); | |
| Ok(Vc::cell(children)) | |
| } | |
| } | |