@@ -160,7 +160,7 @@ let raw_snippet_exp_simple_enough (s : string) =
160160
161161(* e = function(x){...}(x); is good
162162*)
163- let exp_need_paren (e : J.expression ) =
163+ let rec exp_need_paren ?( arrow = false ) (e : J.expression ) =
164164 match e.expression_desc with
165165 (* | Caml_uninitialized_obj _ * )
166166 | Call ({ expression_desc = Raw_js_code _ } , _ , _ ) -> true
@@ -178,11 +178,13 @@ let exp_need_paren (e : J.expression) =
178178 | Length _ | Call _ | Caml_block_tag _ | Seq _ | Static_index _ | Cond _
179179 | Bin _ | Is_null_or_undefined _ | String_index _ | Array_index _
180180 | String_append _ | Var _ | Undefined _ | Null | Str _ | Array _
181- | Optional_block _ | Caml_block _ | FlatCall _ | Typeof _ | Number _
181+ | Caml_block _ | FlatCall _ | Typeof _ | Number _
182182 | Js_not _ | Bool _ | New _ ->
183183 false
184184 | Await _ -> false
185185 | Tagged_template _ -> false
186+ | Optional_block (e , true ) when arrow -> exp_need_paren ~arrow e
187+ | Optional_block _ -> false
186188
187189(* * Print as underscore for unused vars, may not be
188190 needed in the future *)
@@ -411,7 +413,7 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat
411413
412414 | [ { statement_desc = Return e } ] | [ { statement_desc = Exp e } ]
413415 when arrow && directive == None
414- -> (if exp_need_paren e then P. paren_group f 0 else P. group f 0 )
416+ -> (if exp_need_paren ~arrow e then P. paren_group f 0 else P. group f 0 )
415417 (fun _ -> ignore (expression ~level: 0 cxt f e))
416418
417419 | _ ->
0 commit comments