-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
424 additions
and
441 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
module.exports = { | ||
arrowParens: 'always', | ||
singleQuote: true, | ||
tabWidth: 2, | ||
semi: false, | ||
} |
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.