diff --git a/crates/core/src/hast_to_swc_ast/mappings.rs b/crates/core/src/hast_to_swc_ast/mappings.rs index 8359d32..814bee6 100644 --- a/crates/core/src/hast_to_swc_ast/mappings.rs +++ b/crates/core/src/hast_to_swc_ast/mappings.rs @@ -1,7 +1,9 @@ use std::collections::HashMap; +use lazy_static::lazy_static; // From https://raw.githubusercontent.com/facebook/react/master/packages/react-dom/src/shared/possibleStandardNames.js -pub fn create_attr_mappings() -> HashMap<&'static str, &'static str> { +lazy_static! { + pub static ref ATTR_MAPPINGS: HashMap<&'static str, &'static str> = HashMap::from([ // HTML ("accept", "accept"), @@ -488,5 +490,5 @@ pub fn create_attr_mappings() -> HashMap<&'static str, &'static str> { ("ychannelselector", "yChannelSelector"), ("z", "z"), ("zoomandpan", "zoomAndPan"), - ]) + ]); } diff --git a/crates/core/src/hast_to_swc_ast/mod.rs b/crates/core/src/hast_to_swc_ast/mod.rs index 0b27afd..d1f96e6 100644 --- a/crates/core/src/hast_to_swc_ast/mod.rs +++ b/crates/core/src/hast_to_swc_ast/mod.rs @@ -15,7 +15,7 @@ mod string_to_object_style; mod util; use self::decode_xml::*; -use self::mappings::*; +use self::mappings::ATTR_MAPPINGS; use self::string_to_object_style::*; use self::util::*; @@ -92,14 +92,14 @@ fn text(n: &swc_xml::ast::Text) -> Option { pub struct HastVisitor { jsx: Option, - attr_mappings: HashMap<&'static str, &'static str>, + attr_mappings: &'static HashMap<&'static str, &'static str>, } impl HastVisitor { fn new() -> Self { Self { jsx: None, - attr_mappings: create_attr_mappings(), + attr_mappings: &ATTR_MAPPINGS, } } @@ -139,7 +139,7 @@ impl HastVisitor { let opening = JSXOpeningElement { span: DUMMY_SP, - name: name, + name, attrs, self_closing: children.is_empty(), type_args: None, @@ -283,7 +283,7 @@ mod tests { }))) .unwrap(); - String::from_utf8_lossy(&buf).to_string() + unsafe { String::from_utf8_unchecked(buf) } } fn document_test(input: PathBuf) {