Download next.js/turbopack/crates/turbopack-ecmascript/src/static_code.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.16 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/static_code.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript/src/static_code.rs
-
curl -L -o static_code.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript/src/static_code.rs
2.16 kB
| use anyhow::{Result, bail}; | |
| use turbo_tasks::{ResolvedVc, Vc}; | |
| use turbo_tasks_fs::FileSystemPath; | |
| use turbopack_core::{ | |
| code_builder::{Code, CodeBuilder}, | |
| context::AssetContext, | |
| file_source::FileSource, | |
| reference_type::ReferenceType, | |
| }; | |
| use crate::EcmascriptAnalyzable; | |
| /// Static ECMAScript file code, to be used as part of some code. | |
| /// | |
| /// Useful to transform partial runtime code files, which get concatenated into | |
| /// the final runtime code, while keeping source map information. | |
| pub struct StaticEcmascriptCode { | |
| asset_context: ResolvedVc<Box<dyn AssetContext>>, | |
| asset: ResolvedVc<Box<dyn EcmascriptAnalyzable>>, | |
| generate_source_map: bool, | |
| } | |
| impl StaticEcmascriptCode { | |
| /// Creates a new [`Vc<StaticEcmascriptCode>`]. | |
| pub async fn new( | |
| asset_context: ResolvedVc<Box<dyn AssetContext>>, | |
| asset_path: FileSystemPath, | |
| generate_source_map: bool, | |
| ) -> Result<Vc<Self>> { | |
| let module = asset_context | |
| .process( | |
| Vc::upcast(FileSource::new(asset_path.clone())), | |
| ReferenceType::Runtime, | |
| ) | |
| .module() | |
| .to_resolved() | |
| .await?; | |
| let Some(asset) = ResolvedVc::try_sidecast::<Box<dyn EcmascriptAnalyzable>>(module) else { | |
| bail!("asset is not an Ecmascript module") | |
| }; | |
| Ok(Self::cell(StaticEcmascriptCode { | |
| asset_context, | |
| asset, | |
| generate_source_map, | |
| })) | |
| } | |
| /// Computes the contents of the asset and pushes it to | |
| /// the code builder, including the source map if available. | |
| pub async fn code(&self) -> Result<Vc<Code>> { | |
| let runtime_base_content = self | |
| .asset | |
| .module_content_without_analysis(self.generate_source_map) | |
| .await?; | |
| let mut code = CodeBuilder::default(); | |
| code.push_source( | |
| &runtime_base_content.inner_code, | |
| runtime_base_content.source_map.clone(), | |
| ); | |
| Ok(Code::cell(code.build())) | |
| } | |
| } | |