diff --git a/formatTest/unit_tests/expected_output/fastPipe.re b/formatTest/unit_tests/expected_output/fastPipe.re index a72f7a413..4ca6de32b 100644 --- a/formatTest/unit_tests/expected_output/fastPipe.re +++ b/formatTest/unit_tests/expected_output/fastPipe.re @@ -5,7 +5,10 @@ bar->f->g->h; compilation ->Plugin.buildAssets ->Js.Json.stringify -->Node.Fs.writeFileAsUtf8Sync(_, path); +->Node.Fs.writeFileAsUtf8Sync( + _, + path, +); foo->bar->baz >>= monadicFunction |> bind; @@ -53,12 +56,12 @@ event->(target##value[0]); event->target(foo); -event->target(foo); - -(event->target)(foo); +event->(target(foo)); event->target(foo); +event->(target(foo)); + foo->bar := baz; foo->bar === baz; diff --git a/src/reason-parser/reason_parser.mly b/src/reason-parser/reason_parser.mly index 45aa54dee..7d956605b 100644 --- a/src/reason-parser/reason_parser.mly +++ b/src/reason-parser/reason_parser.mly @@ -3105,7 +3105,7 @@ parenthesized_expr: | E as_loc(SHARPEQUAL) simple_expr { let op = { $2 with txt = "#=" } in mkinfixop $1 (mkoperator op) $3 } - | E as_loc(MINUSGREATER) simple_expr + | E as_loc(MINUSGREATER) simple_expr_no_call { mkinfixop $1 (mkoperator {$2 with txt = "|."}) $3 } | as_loc(mod_longident) DOT LPAREN MODULE module_expr COLON package_type RPAREN { let loc = mklocation $symbolstartpos $endpos in diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 3341600a1..c4279ea9b 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -3542,10 +3542,8 @@ let printer = object(self:'self) let funApplExpr = formatAttachmentApplication applicationFinalWrapping None (itms, Some reducesAfterRight.pexp_loc) in (* Little hack: need to print parens for the `bar` application in e.g. - `foo->other##(bar(baz))`. The exception to this is the fast pipe - operator, which binds tighter to function application. *) - if higherPrecedenceThan withPrecedence (Custom "prec_functionAppl") && - withPrecedence <> (Token fastPipeToken) + `foo->other##(bar(baz))` or `foo->other->(bar(baz))`. *) + if higherPrecedenceThan withPrecedence (Custom "prec_functionAppl") then LayoutNode (formatPrecedence ~loc:reducesAfterRight.pexp_loc funApplExpr) else LayoutNode funApplExpr | PotentiallyLowPrecedence itm -> LayoutNode (formatPrecedence ~loc:reducesAfterRight.pexp_loc itm) @@ -7195,6 +7193,7 @@ let printer = object(self:'self) makeTup ~uncurried (List.map self#label_x_expression_param params) method formatFunAppl ~jsxAttrs ~args ~funExpr ~applicationExpr ?(uncurried=false) () = + let funExpr = Reason_ast.processFastPipe funExpr in let uncurriedApplication = uncurried in (* If there was a JSX attribute BUT JSX component wasn't detected, that JSX attribute needs to be pretty printed so it doesn't get @@ -7213,7 +7212,7 @@ let printer = object(self:'self) let formattedFunExpr = match funExpr.pexp_desc with (* fast pipe chain or sharpop chain as funExpr, no parens needed, we know how to parse *) | Pexp_apply ({pexp_desc = Pexp_ident {txt = Lident s}}, _) - when requireNoSpaceFor s && s <> fastPipeToken -> + when requireNoSpaceFor s -> self#unparseExpr funExpr | _ -> self#simplifyUnparseExpr funExpr in