react-code-dataset / next.js /turbopack /crates /turbopack-ecmascript-plugins /src /transform /directives /client.rs
Download next.js/turbopack/crates/turbopack-ecmascript-plugins/src/transform/directives/client.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript-plugins/src/transform/directives/client.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/turbopack/crates/turbopack-ecmascript-plugins/src/transform/directives/client.rs
-
curl -L -o client.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/turbopack/crates/turbopack-ecmascript-plugins/src/transform/directives/client.rs
1.17 kB
| use anyhow::Result; | |
| use async_trait::async_trait; | |
| use swc_core::ecma::{ast::Program, transforms::base::resolver, visit::VisitMutWith}; | |
| use turbo_rcstr::RcStr; | |
| use turbopack_ecmascript::{CustomTransformer, TransformContext}; | |
| use super::{is_client_module, server_to_client_proxy::create_proxy_module}; | |
| pub struct ClientDirectiveTransformer { | |
| transition_name: RcStr, | |
| } | |
| impl ClientDirectiveTransformer { | |
| pub fn new(transition_name: RcStr) -> Self { | |
| Self { transition_name } | |
| } | |
| } | |
| impl CustomTransformer for ClientDirectiveTransformer { | |
| async fn transform(&self, program: &mut Program, ctx: &TransformContext<'_>) -> Result<()> { | |
| if is_client_module(program) { | |
| *program = create_proxy_module( | |
| self.transition_name.as_str(), | |
| &format!("./{}", ctx.file_name_str), | |
| ); | |
| program.visit_mut_with(&mut resolver( | |
| ctx.unresolved_mark, | |
| ctx.top_level_mark, | |
| false, | |
| )); | |
| } | |
| Ok(()) | |
| } | |
| } | |