Download next.js/crates/napi/src/react_compiler.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.62 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/napi/src/react_compiler.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/crates/napi/src/react_compiler.rs
-
curl -L -o react_compiler.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/napi/src/react_compiler.rs
1.62 kB
| use std::{path::PathBuf, sync::Arc}; | |
| use napi::bindgen_prelude::*; | |
| use next_custom_transforms::react_compiler; | |
| use swc_core::{ | |
| common::{GLOBALS, SourceMap}, | |
| ecma::{ | |
| ast::EsVersion, | |
| parser::{Syntax, TsSyntax, parse_file_as_program}, | |
| }, | |
| }; | |
| pub struct CheckTask { | |
| pub filename: PathBuf, | |
| } | |
| impl Task for CheckTask { | |
| type Output = bool; | |
| type JsValue = bool; | |
| fn compute(&mut self) -> napi::Result<Self::Output> { | |
| GLOBALS.set(&Default::default(), || { | |
| // | |
| let cm = Arc::new(SourceMap::default()); | |
| let Ok(fm) = cm.load_file(&self.filename.clone()) else { | |
| return Ok(false); | |
| }; | |
| let mut errors = vec![]; | |
| let Ok(program) = parse_file_as_program( | |
| &fm, | |
| Syntax::Typescript(TsSyntax { | |
| tsx: true, | |
| ..Default::default() | |
| }), | |
| EsVersion::EsNext, | |
| None, | |
| &mut errors, | |
| ) else { | |
| return Ok(false); | |
| }; | |
| if !errors.is_empty() { | |
| return Ok(false); | |
| } | |
| Ok(react_compiler::is_required(&program)) | |
| }) | |
| } | |
| fn resolve(&mut self, _env: Env, result: Self::Output) -> napi::Result<Self::JsValue> { | |
| Ok(result) | |
| } | |
| } | |
| pub fn is_react_compiler_required( | |
| filename: String, | |
| signal: Option<AbortSignal>, | |
| ) -> AsyncTask<CheckTask> { | |
| let filename = PathBuf::from(filename); | |
| AsyncTask::with_optional_signal(CheckTask { filename }, signal) | |
| } | |