Selaa lähdekoodia

This fixes issue (#2724)

opensource-inemar-net 11 kuukautta sitten
vanhempi
commit
e73484795a

+ 8 - 1
packages/autofmt/src/lib.rs

@@ -69,7 +69,14 @@ pub fn fmt_file(contents: &str, indent: IndentOptions) -> Vec<FormattedBlock> {
             continue;
         }
 
-        let body = item.parse_body_with(CallBody::parse_strict).unwrap();
+        let body = match item.parse_body_with(CallBody::parse_strict) {
+            Ok(v) => v,
+            //there is aparsing error, we give up and don't format the rsx
+            Err(e) => {
+                eprintln!("Error while parsing rsx {:?} ", e);
+                return formatted_blocks;
+            }
+        };
 
         let rsx_start = macro_path.span().start();
 

+ 1 - 0
packages/autofmt/tests/wrong.rs

@@ -30,3 +30,4 @@ twoway!("multiexpr-many" => multiexpr_many (IndentOptions::new(IndentType::Space
 twoway!("simple-combo-expr" => simple_combo_expr (IndentOptions::new(IndentType::Spaces, 4, false)));
 twoway!("oneline-expand" => online_expand (IndentOptions::new(IndentType::Spaces, 4, false)));
 twoway!("shortened" => shortened (IndentOptions::new(IndentType::Spaces, 4, false)));
+twoway!("syntax_error" => syntax_error (IndentOptions::new(IndentType::Spaces, 4, false)));

+ 6 - 0
packages/autofmt/tests/wrong/syntax_error.rsx

@@ -0,0 +1,6 @@
+fn app() -> Element {
+    rsx! {
+        let x="hello world";
+        div { "hello world" }
+    }
+}

+ 6 - 0
packages/autofmt/tests/wrong/syntax_error.wrong.rsx

@@ -0,0 +1,6 @@
+fn app() -> Element {
+    rsx! {
+        let x="hello world";
+        div { "hello world" }
+    }
+}