Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Convert Reason fast pipe with uncurried functions in the lhs to ReScript correct #219

Merged
merged 2 commits into from
Dec 31, 2020
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/res_ast_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ let rec rewriteReasonFastPipe expr =
let rhsLoc = {rhs.pexp_loc with loc_end = expr.pexp_loc.loc_end} in
let newLhs =
let expr = rewriteReasonFastPipe lhs in
{expr with pexp_attributes = subAttrs}
{expr with pexp_attributes = List.concat [lhs.pexp_attributes; subAttrs]}
in
let newRhs = {
pexp_loc = rhsLoc;
Expand Down
17 changes: 17 additions & 0 deletions tests/conversion/reason/__snapshots__/render.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,23 @@ let () = {
// ok
dontDoThisAhome(. a, b)(. c, d)(. e, f)
}

let _ =
library.getBalance(. account)->Promise.Js.catch(_ => Promise.resolved(None))

let _ =
library.getBalance(. account)
->Promise.Js.catch(_ => Promise.resolved(None))
->Promise.get(newBalance =>
dispatch(
LoadAddress(
account,
newBalance->Belt.Option.flatMap(balance =>
Eth.make(balance.toString(.))
),
),
)
)
"
`;

Expand Down
19 changes: 19 additions & 0 deletions tests/conversion/reason/uncurrried.re
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,22 @@ let () = {
// ok
dontDoThisAhome(. a, b)(. c, d)(. e, f)
}


let _ =
library.getBalance(. account)
->Promise.Js.catch(_ => Promise.resolved(None))

let _ =
library.getBalance(. account)
->Promise.Js.catch(_ => {Promise.resolved(None)})
->Promise.get(newBalance => {
dispatch(
LoadAddress(
account,
newBalance->Belt.Option.flatMap(balance =>
Eth.make(balance.toString(.))
),
),
)
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ let x = a - b
let x = a -. b
;;Constructor (a, b)
;;\`Constructor (a, b)
let _ = ((Constructor (a, b); \`Constructor (a, b))[@ns.braces ])"
let _ = ((Constructor (a, b); \`Constructor (a, b))[@ns.braces ])
;;((library.getBalance account)[@bs ]) |.
(Promise.Js.catch (fun _ -> ((Promise.resolved None)[@ns.braces ])))"
`;

exports[`binaryNoEs6Arrow.js 1`] = `
Expand Down
2 changes: 2 additions & 0 deletions tests/parsing/grammar/expressions/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ let _ = {
#Constructor(a, b)
}

library.getBalance(. account)
->Promise.Js.catch(_ => {Promise.resolved(None)})
21 changes: 21 additions & 0 deletions tests/printer/expr/__snapshots__/render.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,27 @@ let aggregateTotal = (forecast, ~audienceType) =>
views: item[\\"reach\\"][\\"views\\"],
sample: item[\\"reach\\"][\\"sample\\"],
})

React.useEffect4(() => {
switch (context.library, context.account) {
| (Some(library), Some(account)) =>
library.getBalance(. account)
->Promise.Js.catch(_ => {Promise.resolved(None)})
->Promise.get(newBalance => {
dispatch(
LoadAddress(
account,
newBalance->Belt.Option.flatMap(balance =>
Eth.make(balance.toString(.))
),
),
)
})

None
| _ => None
}
}, (context.library, context.account, context.chainId, dispatch))
"
`;

Expand Down
24 changes: 24 additions & 0 deletions tests/printer/expr/binary.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,27 @@ let aggregateTotal = (forecast, ~audienceType) =>
views: item["reach"]["views"],
sample: item["reach"]["sample"],
})

React.useEffect4(
() => {
switch (context.library, context.account) {
| (Some(library), Some(account)) =>
library.getBalance(. account)
->Promise.Js.catch(_ => {Promise.resolved(None)})
->Promise.get(newBalance => {
dispatch(
LoadAddress(
account,
newBalance->Belt.Option.flatMap(balance =>
Eth.make(balance.toString(.))
),
),
)
})

None
| _ => None
}
},
(context.library, context.account, context.chainId, dispatch),
)