Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3985,7 +3985,49 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
->
let lhs_has_comment_below = has_comment_below cmt_tbl lhs.pexp_loc in
let lhs_doc = print_operand ~is_lhs:true ~is_multiline:false lhs op in
let rhs_doc = print_operand ~is_lhs:false ~is_multiline:false rhs op in
let rhs_doc =
(* For pipe operator, if RHS is (__x) => f(__x, ...), remove the first __x arg
so it prints as a->f(...) instead of a->f(_, ...) *)
let rhs_to_print =
match rhs.pexp_desc with
| Pexp_fun
{
arg_label = Nolabel;
default = None;
lhs = {ppat_desc = Ppat_var {txt = "__x"}} as pat;
rhs =
{pexp_desc = Pexp_apply {funct; args; partial; transformed_jsx}}
as body;
arity;
async;
} -> (
match args with
| (Nolabel, {pexp_desc = Pexp_ident {txt = Longident.Lident "__x"}})
:: rest_args ->
{
rhs with
pexp_desc =
Pexp_fun
{
arg_label = Nolabel;
default = None;
lhs = pat;
rhs =
{
body with
pexp_desc =
Pexp_apply
{funct; args = rest_args; partial; transformed_jsx};
};
arity;
async;
};
}
| _ -> rhs)
| _ -> rhs
in
print_operand ~is_lhs:false ~is_multiline:false rhs_to_print op
in
Doc.group
(Doc.concat
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let nested2 = (x, y, z) => List.length(_)

let l = [1, 2, 3]->List.map(i => i + 1, _)->List.filter(i => i > 0, _)

let l = (i => i + 1)->List.map(_, [1, 2, 3])
let l = (i => i + 1)->List.map([1, 2, 3])

let x = List.length(_)

Expand Down Expand Up @@ -52,8 +52,8 @@ f(a, b, _)[ix] = 2

getDirector(a, b, _).name = "Steve"

filterNone->Array.get(_, 0)
filterNone->Array.get(_, 0)
filterNone->Array.get(0)
filterNone->Array.get(0)
Array.get(_, 0)
1 + Array.get(_, 0)
Array.get(_, 1) + Array.get(_, 0)
Expand Down
Loading