File tree Expand file tree Collapse file tree 2 files changed +9
-7
lines changed
crates/core/src/hast_to_swc_ast Expand file tree Collapse file tree 2 files changed +9
-7
lines changed Original file line number Diff line number Diff line change 11use std:: collections:: HashMap ;
2+ use lazy_static:: lazy_static;
23
34// From https://raw.githubusercontent.com/facebook/react/master/packages/react-dom/src/shared/possibleStandardNames.js
4- pub fn create_attr_mappings ( ) -> HashMap < & ' static str , & ' static str > {
5+ lazy_static ! {
6+ pub static ref ATTR_MAPPINGS : HashMap <& ' static str , & ' static str > =
57 HashMap :: from( [
68 // HTML
79 ( "accept" , "accept" ) ,
@@ -488,5 +490,5 @@ pub fn create_attr_mappings() -> HashMap<&'static str, &'static str> {
488490 ( "ychannelselector" , "yChannelSelector" ) ,
489491 ( "z" , "z" ) ,
490492 ( "zoomandpan" , "zoomAndPan" ) ,
491- ] )
493+ ] ) ;
492494}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ mod string_to_object_style;
1515mod util;
1616
1717use self :: decode_xml:: * ;
18- use self :: mappings:: * ;
18+ use self :: mappings:: ATTR_MAPPINGS ;
1919use self :: string_to_object_style:: * ;
2020use self :: util:: * ;
2121
@@ -92,14 +92,14 @@ fn text(n: &swc_xml::ast::Text) -> Option<JSXElementChild> {
9292
9393pub struct HastVisitor {
9494 jsx : Option < JSXElement > ,
95- attr_mappings : HashMap < & ' static str , & ' static str > ,
95+ attr_mappings : & ' static HashMap < & ' static str , & ' static str > ,
9696}
9797
9898impl HastVisitor {
9999 fn new ( ) -> Self {
100100 Self {
101101 jsx : None ,
102- attr_mappings : create_attr_mappings ( ) ,
102+ attr_mappings : & ATTR_MAPPINGS ,
103103 }
104104 }
105105
@@ -139,7 +139,7 @@ impl HastVisitor {
139139
140140 let opening = JSXOpeningElement {
141141 span : DUMMY_SP ,
142- name : name ,
142+ name,
143143 attrs,
144144 self_closing : children. is_empty ( ) ,
145145 type_args : None ,
@@ -283,7 +283,7 @@ mod tests {
283283 } ) ) )
284284 . unwrap ( ) ;
285285
286- String :: from_utf8_lossy ( & buf) . to_string ( )
286+ unsafe { String :: from_utf8_unchecked ( buf) }
287287 }
288288
289289 fn document_test ( input : PathBuf ) {
You can’t perform that action at this time.
0 commit comments