Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
cargo clippy
and cargo fmt
to CI
- Loading branch information
1 parent
5a16b1a
commit a0bd835
Showing
24 changed files
with
334 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
use swc_atoms::JsWord; | ||
use swc_ecmascript::ast::{ | ||
Ident, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement, | ||
Ident, JSXAttr, JSXAttrName, JSXAttrOrSpread, JSXElementName, JSXOpeningElement, | ||
}; | ||
use swc_ecmascript::visit::Fold; | ||
|
||
pub fn amp_attributes() -> impl Fold { | ||
AmpAttributePatcher::default() | ||
AmpAttributePatcher::default() | ||
} | ||
|
||
#[derive(Debug, 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 0..attrs.len() { | ||
if let JSXAttrOrSpread::JSXAttr(JSXAttr { | ||
name: | ||
JSXAttrName::Ident(Ident { | ||
sym, | ||
span: s, | ||
optional: o, | ||
}), | ||
fn fold_jsx_opening_element(&mut self, node: JSXOpeningElement) -> JSXOpeningElement { | ||
let JSXOpeningElement { | ||
name, | ||
mut attrs, | ||
span, | ||
value, | ||
}) = &attrs[i] | ||
{ | ||
if sym as &str == "className" { | ||
attrs[i] = JSXAttrOrSpread::JSXAttr(JSXAttr { | ||
name: JSXAttrName::Ident(Ident { | ||
sym: JsWord::from("class"), | ||
span: s.clone(), | ||
optional: o.clone(), | ||
}), | ||
span: span.clone(), | ||
value: value.clone(), | ||
}) | ||
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(Ident { | ||
sym, | ||
span: s, | ||
optional: o, | ||
}), | ||
span, | ||
value, | ||
}) = &i | ||
{ | ||
if sym as &str == "className" { | ||
*i = JSXAttrOrSpread::JSXAttr(JSXAttr { | ||
name: JSXAttrName::Ident(Ident { | ||
sym: JsWord::from("class"), | ||
span: *s, | ||
optional: *o, | ||
}), | ||
span: *span, | ||
value: value.clone(), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
JSXOpeningElement { | ||
name: n, | ||
attrs, | ||
span, | ||
self_closing, | ||
type_args, | ||
JSXOpeningElement { | ||
name: n, | ||
attrs, | ||
span, | ||
self_closing, | ||
type_args, | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.