File tree Expand file tree Collapse file tree 8 files changed +31
-16
lines changed
Expand file tree Collapse file tree 8 files changed +31
-16
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ profile. This started with version 0.26.0.
5858 The attribute is moved from ` begin .. end [@attr] ` to ` begin [@attr] .. end ` .
5959- Fix missing parentheses around ` let .. in [@attr] ` (#2564 , @Julow )
6060- Display ` a##b ` instead of ` a ## b ` and similarly for operators that start with # (#2580 , @v-gb )
61+ - Fix formatting of short ` fun ` expressions with the janestreet profile (#2593 , @Julow )
6162
6263### Changes
6364- The location of attributes for structure items is now tracked and preserved. (#2247 , @EmileTrotignon )
Original file line number Diff line number Diff line change @@ -1509,7 +1509,7 @@ and fmt_function ?(last_arg = false) ?force_closing_paren ~ctx ~ctx0
15091509 let head = fmt_fun_args_typ args typ in
15101510 let body ~pro = pro $ fmt_expression c (sub_exp ~ctx body) in
15111511 let box, closing_paren_offset =
1512- Params.Exp. box_fun_expr c.conf ~source: c.source ~ctx0 ~ctx ~parens
1512+ Params.Exp. box_fun_expr c.conf ~source: c.source ~ctx0 ~ctx
15131513 in
15141514 let closing_paren_offset =
15151515 if should_box then closing_paren_offset else ~- 2
Original file line number Diff line number Diff line change @@ -213,7 +213,7 @@ module Exp = struct
213213 ( kw_in_box
214214 $ hvbox_if should_box_args 0 (args $ fmt_opt annot $ fmt_opt epi) )
215215
216- let box_fun_expr (c : Conf.t ) ~source ~ctx0 ~ctx ~ parens =
216+ let box_fun_expr (c : Conf.t ) ~source ~ctx0 ~ctx =
217217 let indent =
218218 if ctx_is_rhs_of_infix ~ctx0 ~ctx then 0
219219 else if Poly. equal c.fmt_opts.function_indent_nested.v `Always then
@@ -244,14 +244,7 @@ module Exp = struct
244244 else 2
245245 in
246246 let name = " Params.box_fun_expr" in
247- let mkbox =
248- match ctx0 with
249- | Str _ | Lb _ -> hvbox
250- | _ ->
251- (* JS: The body of a [fun] must break if the intro is too large,
252- except if the [fun] is small and parenthesed. *)
253- if ocp c && not parens then hvbox else hovbox
254- in
247+ let mkbox = if ctx_is_let_or_fun ~ctx ctx0 then hvbox else hovbox in
255248 (mkbox ~name indent, ~- indent)
256249
257250 (* if the function is the last argument of an apply and no other arguments
Original file line number Diff line number Diff line change @@ -58,7 +58,6 @@ module Exp : sig
5858 -> source :Source .t
5959 -> ctx0 :Ast .t
6060 -> ctx :Ast .t
61- -> parens :bool
6261 -> (Fmt .t -> Fmt .t ) * int
6362 (* * return a box with an indent and minus the value of the indent to be used for a closing parenthesis *)
6463
Original file line number Diff line number Diff line change @@ -8241,3 +8241,11 @@ let _ =
82418241 (* foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo *)
82428242 else f
82438243;;
8244+
8245+ let _ =
8246+ match ids_queue with
8247+ | Some q ->
8248+ (* this is more efficient than a linear scan of [ids] *)
8249+ fun id -> not (Ident.HashQueue. mem q id)
8250+ | None -> fun id -> not (List. mem ~equal: Ident. equal ids id)
8251+ ;;
Original file line number Diff line number Diff line change @@ -3,4 +3,4 @@ Warning: tests/js_source.ml:9564 exceeds the margin
33Warning: tests/js_source.ml:9668 exceeds the margin
44Warning: tests/js_source.ml:9727 exceeds the margin
55Warning: tests/js_source.ml:9810 exceeds the margin
6- Warning: tests/js_source.ml:10309 exceeds the margin
6+ Warning: tests/js_source.ml:10308 exceeds the margin
Original file line number Diff line number Diff line change @@ -10235,8 +10235,7 @@ let _ =
1023510235 foooooooooooooooooo
1023610236 foooooooooooooooooo
1023710237 foooooooooooooooooo
10238- foooooooooooooooooo ->
10239- ()
10238+ foooooooooooooooooo -> ()
1024010239;;
1024110240
1024210241module type For_let_syntax_local =
@@ -10530,3 +10529,11 @@ let _ =
1053010529 (* foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo *)
1053110530 else f
1053210531;;
10532+
10533+ let _ =
10534+ match ids_queue with
10535+ | Some q ->
10536+ (* this is more efficient than a linear scan of [ids] *)
10537+ fun id -> not (Ident.HashQueue.mem q id)
10538+ | None -> fun id -> not (List.mem ~equal:Ident.equal ids id)
10539+ ;;
Original file line number Diff line number Diff line change @@ -10235,8 +10235,7 @@ let _ =
1023510235 foooooooooooooooooo
1023610236 foooooooooooooooooo
1023710237 foooooooooooooooooo
10238- foooooooooooooooooo ->
10239- ()
10238+ foooooooooooooooooo -> ()
1024010239;;
1024110240
1024210241module type For_let_syntax_local =
@@ -10530,3 +10529,11 @@ let _ =
1053010529 (* foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo *)
1053110530 else f
1053210531;;
10532+
10533+ let _ =
10534+ match ids_queue with
10535+ | Some q ->
10536+ (* this is more efficient than a linear scan of [ids] *)
10537+ fun id -> not (Ident.HashQueue.mem q id)
10538+ | None -> fun id -> not (List.mem ~equal:Ident.equal ids id)
10539+ ;;
You can’t perform that action at this time.
0 commit comments