Skip to content

Remove pipe last (|>) syntax #7512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 24, 2025
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
- Allow oneliner formatting when including module with single type alias. https://github.com/rescript-lang/rescript/pull/7502
- Improve error messages for JSX type mismatches, passing objects where record is expected, passing array literal where tuple is expected, and more. https://github.com/rescript-lang/rescript/pull/7500
- Show in error messages when coercion can be used to fix a type mismatch. https://github.com/rescript-lang/rescript/pull/7505
- Remove deprecated pipe last (|>) syntax. https://github.com/rescript-lang/rescript/pull/7512

# 12.0.0-alpha.13

Expand Down
11 changes: 0 additions & 11 deletions analysis/reanalyze/src/Exception.ml
Original file line number Diff line number Diff line change
Expand Up @@ -304,17 +304,6 @@ let traverseAst () =
let exceptions = [arg] |> raiseArgs in
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
arg |> snd |> iterExprOpt self
| Texp_apply
{
funct = {exp_desc = Texp_ident (atat, _, _)};
args = [arg; (_lbl1, Some {exp_desc = Texp_ident (callee, _, _)})];
}
when (* Exn(...) |> raise *)
atat |> Path.name = "Pervasives.|>" && callee |> Path.name |> isRaise
->
let exceptions = [arg] |> raiseArgs in
currentEvents := {Event.exceptions; loc; kind = Raises} :: !currentEvents;
arg |> snd |> iterExprOpt self
| Texp_apply {funct = {exp_desc = Texp_ident (callee, _, _)} as e; args} ->
let calleeName = Path.name callee in
if calleeName |> isRaise then
Expand Down
5 changes: 2 additions & 3 deletions compiler/syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1483,9 +1483,8 @@ and walk_expression expr t comments =
txt =
Longident.Lident
( ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!="
| "!==" | "<=" | ">=" | "|>" | "+" | "+." | "-" | "-."
| "++" | "^" | "*" | "*." | "/" | "/." | "**" | "->"
| "<>" );
| "!==" | "<=" | ">=" | "+" | "+." | "-" | "-." | "++"
| "^" | "*" | "*." | "/" | "/." | "**" | "->" | "<>" );
};
};
args = [(Nolabel, operand1); (Nolabel, operand2)];
Expand Down
22 changes: 3 additions & 19 deletions compiler/syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2186,25 +2186,9 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =
let b = parse_binary_expr ~context p token_prec in
let loc = mk_loc a.Parsetree.pexp_loc.loc_start b.pexp_loc.loc_end in
let expr =
match (token, b.pexp_desc) with
| ( BarGreater,
Pexp_apply {funct = fun_expr; args; partial; transformed_jsx} ) ->
{
b with
pexp_desc =
Pexp_apply
{
funct = fun_expr;
args = args @ [(Nolabel, a)];
partial;
transformed_jsx;
};
}
| BarGreater, _ -> Ast_helper.Exp.apply ~loc b [(Nolabel, a)]
| _ ->
Ast_helper.Exp.apply ~loc
(make_infix_operator p token start_pos end_pos)
[(Nolabel, a); (Nolabel, b)]
Ast_helper.Exp.apply ~loc
(make_infix_operator p token start_pos end_pos)
[(Nolabel, a); (Nolabel, b)]
in
Parser.eat_breadcrumb p;
loop expr)
Expand Down
10 changes: 5 additions & 5 deletions compiler/syntax/src/res_parsetree_viewer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ let operator_precedence operator =
| "&&" -> 3
| "^" -> 4
| "&" -> 5
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" | "|>" -> 6
| "==" | "===" | "<" | ">" | "!=" | "<>" | "!==" | "<=" | ">=" -> 6
| "<<" | ">>" | ">>>" -> 7
| "+" | "+." | "-" | "-." | "++" -> 8
| "*" | "*." | "/" | "/." | "%" -> 9
Expand Down Expand Up @@ -317,8 +317,8 @@ let is_unary_bitnot_expression expr =
let is_binary_operator operator =
match operator with
| ":=" | "||" | "&&" | "==" | "===" | "<" | ">" | "!=" | "!==" | "<=" | ">="
| "|>" | "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**"
| "->" | "<>" | "%" | "&" | "^" | "<<" | ">>" | ">>>" ->
| "+" | "+." | "-" | "-." | "++" | "*" | "*." | "/" | "/." | "**" | "->"
| "<>" | "%" | "&" | "^" | "<<" | ">>" | ">>>" ->
true
| _ -> false

Expand Down Expand Up @@ -715,7 +715,7 @@ let is_single_pipe_expr expr =
match expr.pexp_desc with
| Pexp_apply
{
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "->"}};
args = [(Nolabel, _operand1); (Nolabel, _operand2)];
} ->
true
Expand All @@ -724,7 +724,7 @@ let is_single_pipe_expr expr =
match expr.pexp_desc with
| Pexp_apply
{
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" | "|>")}};
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident "->"}};
args = [(Nolabel, operand1); (Nolabel, _operand2)];
}
when not (is_pipe_expr operand1) ->
Expand Down
12 changes: 2 additions & 10 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3753,13 +3753,10 @@ and print_unary_expression ~state expr cmt_tbl =
and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
let print_binary_operator ~inline_rhs operator =
let spacing_before_operator =
if operator = "->" then Doc.soft_line
else if operator = "|>" then Doc.line
else Doc.space
if operator = "->" then Doc.soft_line else Doc.space
in
let spacing_after_operator =
if operator = "->" then Doc.nil
else if operator = "|>" then Doc.space
else if inline_rhs then Doc.space
else Doc.line
in
Expand Down Expand Up @@ -3930,10 +3927,7 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
match expr.pexp_desc with
| Pexp_apply
{
funct =
{
pexp_desc = Pexp_ident {txt = Longident.Lident (("->" | "|>") as op)};
};
funct = {pexp_desc = Pexp_ident {txt = Longident.Lident ("->" as op)}};
args = [(Nolabel, lhs); (Nolabel, rhs)];
}
when not
Expand All @@ -3952,8 +3946,6 @@ and print_binary_expression ~state (expr : Parsetree.expression) cmt_tbl =
(match (lhs_has_comment_below, op) with
| true, "->" -> Doc.concat [Doc.soft_line; Doc.text "->"]
| false, "->" -> Doc.text "->"
| true, "|>" -> Doc.concat [Doc.line; Doc.text "|> "]
| false, "|>" -> Doc.text " |> "
| _ -> Doc.nil);
rhs_doc;
])
Expand Down
3 changes: 0 additions & 3 deletions compiler/syntax/src/res_scanner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -820,9 +820,6 @@ let rec scan scanner =
| '|' ->
next2 scanner;
Token.Lor
| '>' ->
next2 scanner;
Token.BarGreater
| _ ->
next scanner;
Token.Bar)
Expand Down
4 changes: 1 addition & 3 deletions compiler/syntax/src/res_token.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ type t =
| TemplateTail of string * Lexing.position
| TemplatePart of string * Lexing.position
| Backtick
| BarGreater
| Try
| DocComment of Location.t * string
| ModuleComment of Location.t * string
Expand All @@ -109,7 +108,7 @@ let precedence = function
| Caret -> 4
| Band -> 5
| Equal | EqualEqual | EqualEqualEqual | LessThan | GreaterThan | BangEqual
| BangEqualEqual | LessEqual | GreaterEqual | BarGreater ->
| BangEqualEqual | LessEqual | GreaterEqual ->
6
| LeftShift | RightShift | RightShiftUnsigned -> 7
| Plus | PlusDot | Minus | MinusDot | PlusPlus -> 8
Expand Down Expand Up @@ -213,7 +212,6 @@ let to_string = function
| TemplatePart (text, _) -> text ^ "${"
| TemplateTail (text, _) -> "TemplateTail(" ^ text ^ ")"
| Backtick -> "`"
| BarGreater -> "|>"
| Try -> "try"
| DocComment (_loc, s) -> "DocComment " ^ s
| ModuleComment (_loc, s) -> "ModuleComment " ^ s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@
addValueReference OptArg.res:14:4 --> OptArg.res:14:21
addValueReference OptArg.res:14:4 --> OptArg.res:14:27
DeadOptionalArgs.addReferences twoArgs called with optional argNames: argNamesMaybe: OptArg.res:16:7
addValueReference OptArg.res:16:12 --> OptArg.res:14:4
addValueReference OptArg.res:16:10 --> OptArg.res:14:4
addValueReference OptArg.res:18:4 --> OptArg.res:18:17
addValueReference OptArg.res:18:4 --> OptArg.res:18:14
addValueReference OptArg.res:18:4 --> OptArg.res:18:24
Expand Down Expand Up @@ -2510,7 +2510,7 @@ File References
Live Value +OptArg.+fourArgs: 1 references (OptArg.res:26:4) [0]
Live Value +OptArg.+wrapOneArg: 1 references (OptArg.res:22:7) [0]
Live Value +OptArg.+oneArg: 1 references (OptArg.res:20:4) [0]
Live Value +OptArg.+twoArgs: 1 references (OptArg.res:16:12) [0]
Live Value +OptArg.+twoArgs: 1 references (OptArg.res:16:10) [0]
Live Value +OptArg.+threeArgs: 2 references (OptArg.res:11:7, OptArg.res:12:7) [0]
Live Value +OptArg.+bar: 2 references (OptArg.res:7:7, OptArg.resi:2:0) [0]
Live Value +OptArg.+foo: 1 references (OptArg.res:5:7) [0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Js.log(threeArgs(~a=4, 1))

let twoArgs = (~a=1, ~b=2, c) => a + b + c

Js.log(1 |> twoArgs)
Js.log(1->twoArgs)

let oneArg = (~a=1, ~z, b) => a + b

Expand Down
10 changes: 5 additions & 5 deletions tests/analysis_tests/tests-reanalyze/deadcode/src/Uncurried.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ type u3 = (. int, string, int) => string
let uncurried0 = (. ()) => ""

@genType
let uncurried1 = (. x) => x |> string_of_int
let uncurried1 = (. x) => x -> string_of_int

@genType
let uncurried2 = (. x, y) => (x |> string_of_int) ++ y
let uncurried2 = (. x, y) => (x -> string_of_int) ++ y

@genType
let uncurried3 = (. x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int))
let uncurried3 = (. x, y, z) => (x -> string_of_int) ++ (y ++ (z -> string_of_int))

@genType
let curried3 = (x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int))
let curried3 = (x, y, z) => (x -> string_of_int) ++ (y ++ (z -> string_of_int))

@genType
let callback = cb => cb() |> string_of_int
let callback = cb => cb() -> string_of_int

type auth = {login: unit => string}
type authU = {loginU: (. unit) => string}
Expand Down
6 changes: 3 additions & 3 deletions tests/analysis_tests/tests-reanalyze/deadcode/src/Unison.res
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ let rec toString = (~width, stack) =>
switch stack {
| Cons({break, doc}, stack) =>
switch break {
| IfNeed => (fits(width, stack) ? "fits " : "no ") ++ (stack |> toString(~width=width - 1))
| Never => "never " ++ (doc ++ (stack |> toString(~width=width - 1)))
| Always => "always " ++ (doc ++ (stack |> toString(~width=width - 1)))
| IfNeed => (fits(width, stack) ? "fits " : "no ") ++ (stack -> toString(~width=width - 1))
| Never => "never " ++ (doc ++ (stack -> toString(~width=width - 1)))
| Always => "always " ++ (doc ++ (stack -> toString(~width=width - 1)))
}
| Empty => ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ let foo = x => Yojson.Basic.from_string(x)
let bar = (str, json) =>
switch {
open Yojson.Basic.Util
json |> member(str)
member(str, json)
} {
| j => j
| exception Yojson.Basic.Util.Type_error("a", d) when d == json => json
Expand Down
2 changes: 1 addition & 1 deletion tests/syntax_tests/data/conversion/reason/attributes.res
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ list{1, 2, 3}->map(a => a + 1)->filter(a => modulo(a, 2) == 0)->Js.log
type t
@new external make: unit => t = "DOMParser"

Js.log(make() |> parseHtmlFromString("sdsd"))
Js.log(make()->parseHtmlFromString("sdsd"))
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ list{1, 2, 3}->map(a => a + 1)->filter(a => modulo(a, 2) == 0)->Js.log
type t
@new external make: unit => t = "DOMParser"

Js.log(parseHtmlFromString("sdsd", make()))
Js.log(make()->parseHtmlFromString("sdsd"))
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let photo = Array.get(_, 0)(filterNone(pricedRoom["room"]["photos"]))
let photo = pricedRoom["room"]["photos"]->filterNone->Array.get(_, 0)
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let photo = pricedRoom["room"]["photos"] |> filterNone |> Array.get(_, 0)
let photo = pricedRoom["room"]["photos"]->filterNone->Array.get(_, 0)
Original file line number Diff line number Diff line change
Expand Up @@ -1492,7 +1492,7 @@ let gridLengthToJs = x =>
}

let string_of_dimensions = dimensions =>
dimensions |> List.map(gridLengthToJs) |> String.concat(" ")
dimensions->List.map(gridLengthToJs)->String.concat(" ")

let gridTemplateColumns = dimensions => D("gridTemplateColumns", string_of_dimensions(dimensions))

Expand Down Expand Up @@ -1699,13 +1699,13 @@ let fontFace = (~fontFamily, ~src, ~fontStyle=?, ~fontWeight=?, ~fontDisplay=?,
let fontStyle = Js.Option.map((. value) => FontStyle.toString(value), fontStyle)
let src =
src
|> List.map(x =>
->List.map(x =>
switch x {
| #localUrl(value) => `local("$(value)")`
| #url(value) => `url("$(value)")`
}
)
|> String.concat(", ")
->String.concat(", ")

let fontStyle = Belt.Option.mapWithDefault(fontStyle, "", s => "font-style: " ++ (s ++ ";"))
let fontWeight = Belt.Option.mapWithDefault(fontWeight, "", w =>
Expand Down
Loading