Download next.js/crates/next-custom-transforms/src/transforms/amp_attributes.rs from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.77 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/next-custom-transforms/src/transforms/amp_attributes.rs
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/crates/next-custom-transforms/src/transforms/amp_attributes.rs
-
curl -L -o amp_attributes.rs https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/crates/next-custom-transforms/src/transforms/amp_attributes.rs
1.77 kB
| use swc_core::ecma::{ | |
| ast::{ | |
| Ident, IdentName, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement, | |
| Pass, | |
| }, | |
| atoms::Atom, | |
| visit::{fold_pass, Fold}, | |
| }; | |
| pub fn amp_attributes() -> impl Pass { | |
| fold_pass(AmpAttributePatcher::default()) | |
| } | |
| struct AmpAttributePatcher {} | |
| impl Fold for AmpAttributePatcher { | |
| fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement { | |
| let JSXOpeningElement { | |
| name, | |
| mut attrs, | |
| span, | |
| self_closing, | |
| type_args, | |
| } = node; | |
| let n = name.clone(); | |
| if let JSXElementName::Ident(Ident { sym, .. }) = name { | |
| if sym.starts_with("amp-") { | |
| for i in &mut attrs { | |
| if let JSXAttrOrSpread::JSXAttr(JSXAttr { | |
| name: JSXAttrName::Ident(IdentName { sym, span: s }), | |
| span, | |
| value, | |
| }) = &i | |
| { | |
| if sym as &str == "className" { | |
| *i = JSXAttrOrSpread::JSXAttr(JSXAttr { | |
| name: JSXAttrName::Ident(IdentName { | |
| sym: Atom::from("class"), | |
| span: *s, | |
| }), | |
| span: *span, | |
| value: value.clone(), | |
| }) | |
| } | |
| } | |
| } | |
| } | |
| } | |
| JSXOpeningElement { | |
| name: n, | |
| attrs, | |
| span, | |
| self_closing, | |
| type_args, | |
| } | |
| } | |
| } | |