From 1f70b27b7770392e207ff4591010f1d869a658ed Mon Sep 17 00:00:00 2001 From: Iwan Date: Sat, 10 Apr 2021 12:26:05 +0200 Subject: [PATCH] Fix printing of JSX in binary expressions. The following snippet: ``` + + ``` would print in the non-sugared JSX form. Nested binary expressions should print JSX correctly. Fixes https://github.com/rescript-lang/syntax/issues/373 --- src/res_parsetree_viewer.ml | 4 ++-- tests/printer/expr/binary.res | 12 ++++++++++++ tests/printer/expr/expected/binary.res.txt | 5 +++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/res_parsetree_viewer.ml b/src/res_parsetree_viewer.ml index 788bf6c9..30639fea 100644 --- a/src/res_parsetree_viewer.ml +++ b/src/res_parsetree_viewer.ml @@ -453,13 +453,13 @@ let shouldInlineRhsBinaryExpr rhs = match rhs.pexp_desc with let filterPrinteableAttributes attrs = List.filter (fun attr -> match attr with - | ({Location.txt="bs" | "ns.ternary" | "ns.iflet"}, _) -> false + | ({Location.txt="bs" | "ns.ternary" | "ns.iflet" | "JSX"}, _) -> false | _ -> true ) attrs let partitionPrinteableAttributes attrs = List.partition (fun attr -> match attr with - | ({Location.txt="bs" | "ns.ternary" | "ns.iflet"}, _) -> false + | ({Location.txt="bs" | "ns.ternary" | "ns.iflet" | "JSX"}, _) -> false | _ -> true ) attrs diff --git a/tests/printer/expr/binary.res b/tests/printer/expr/binary.res index 163428f0..87c1b938 100644 --- a/tests/printer/expr/binary.res +++ b/tests/printer/expr/binary.res @@ -388,3 +388,15 @@ React.useEffect4( }, (context.library, context.account, context.chainId, dispatch), ) + +@react.component +let make = (~keycap) => + + + + + + + + + + + + + + diff --git a/tests/printer/expr/expected/binary.res.txt b/tests/printer/expr/expected/binary.res.txt index 291657a7..55a1f787 100644 --- a/tests/printer/expr/expected/binary.res.txt +++ b/tests/printer/expr/expected/binary.res.txt @@ -511,3 +511,8 @@ React.useEffect4(() => { | _ => None } }, (context.library, context.account, context.chainId, dispatch)) + +@react.component +let make = (~keycap) => + + + + + + +