@@ -160,7 +160,7 @@ let raw_snippet_exp_simple_enough (s : string) =
160
160
161
161
(* e = function(x){...}(x); is good
162
162
*)
163
- let exp_need_paren (e : J.expression ) =
163
+ let rec exp_need_paren ?( arrow = false ) (e : J.expression ) =
164
164
match e.expression_desc with
165
165
(* | Caml_uninitialized_obj _ * )
166
166
| Call ({ expression_desc = Raw_js_code _ } , _ , _ ) -> true
@@ -178,11 +178,13 @@ let exp_need_paren (e : J.expression) =
178
178
| Length _ | Call _ | Caml_block_tag _ | Seq _ | Static_index _ | Cond _
179
179
| Bin _ | Is_null_or_undefined _ | String_index _ | Array_index _
180
180
| String_append _ | Var _ | Undefined _ | Null | Str _ | Array _
181
- | Optional_block _ | Caml_block _ | FlatCall _ | Typeof _ | Number _
181
+ | Caml_block _ | FlatCall _ | Typeof _ | Number _
182
182
| Js_not _ | Bool _ | New _ ->
183
183
false
184
184
| Await _ -> false
185
185
| Tagged_template _ -> false
186
+ | Optional_block (e , true ) when arrow -> exp_need_paren ~arrow e
187
+ | Optional_block _ -> false
186
188
187
189
(* * Print as underscore for unused vars, may not be
188
190
needed in the future *)
@@ -411,7 +413,7 @@ and pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t) ~fn_stat
411
413
412
414
| [ { statement_desc = Return e } ] | [ { statement_desc = Exp e } ]
413
415
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 )
415
417
(fun _ -> ignore (expression ~level: 0 cxt f e))
416
418
417
419
| _ ->
0 commit comments