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

Commit 3d5f2da

Browse files
Convert Reason fast pipe with uncurried functions in the lhs to ReScript correct (#219)
* Convert Reason fast pipe with uncurried functions to ReScript correct * Add extra tests with Pexp_field lhs fast pipe
1 parent e52a0c8 commit 3d5f2da

File tree

7 files changed

+87
-2
lines changed

7 files changed

+87
-2
lines changed

src/res_ast_conversion.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ let rec rewriteReasonFastPipe expr =
7474
let rhsLoc = {rhs.pexp_loc with loc_end = expr.pexp_loc.loc_end} in
7575
let newLhs =
7676
let expr = rewriteReasonFastPipe lhs in
77-
{expr with pexp_attributes = subAttrs}
77+
{expr with pexp_attributes = List.concat [lhs.pexp_attributes; subAttrs]}
7878
in
7979
let newRhs = {
8080
pexp_loc = rhsLoc;

tests/conversion/reason/__snapshots__/render.spec.js.snap

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1392,6 +1392,23 @@ let () = {
13921392
// ok
13931393
dontDoThisAhome(. a, b)(. c, d)(. e, f)
13941394
}
1395+
1396+
let _ =
1397+
library.getBalance(. account)->Promise.Js.catch(_ => Promise.resolved(None))
1398+
1399+
let _ =
1400+
library.getBalance(. account)
1401+
->Promise.Js.catch(_ => Promise.resolved(None))
1402+
->Promise.get(newBalance =>
1403+
dispatch(
1404+
LoadAddress(
1405+
account,
1406+
newBalance->Belt.Option.flatMap(balance =>
1407+
Eth.make(balance.toString(.))
1408+
),
1409+
),
1410+
)
1411+
)
13951412
"
13961413
`;
13971414

tests/conversion/reason/uncurrried.re

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,22 @@ let () = {
5656
// ok
5757
dontDoThisAhome(. a, b)(. c, d)(. e, f)
5858
}
59+
60+
61+
let _ =
62+
library.getBalance(. account)
63+
->Promise.Js.catch(_ => Promise.resolved(None))
64+
65+
let _ =
66+
library.getBalance(. account)
67+
->Promise.Js.catch(_ => {Promise.resolved(None)})
68+
->Promise.get(newBalance => {
69+
dispatch(
70+
LoadAddress(
71+
account,
72+
newBalance->Belt.Option.flatMap(balance =>
73+
Eth.make(balance.toString(.))
74+
),
75+
),
76+
)
77+
});

tests/parsing/grammar/expressions/__snapshots__/parse.spec.js.snap

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,9 @@ let x = a - b
135135
let x = a -. b
136136
;;Constructor (a, b)
137137
;;\`Constructor (a, b)
138-
let _ = ((Constructor (a, b); \`Constructor (a, b))[@ns.braces ])"
138+
let _ = ((Constructor (a, b); \`Constructor (a, b))[@ns.braces ])
139+
;;((library.getBalance account)[@bs ]) |.
140+
(Promise.Js.catch (fun _ -> ((Promise.resolved None)[@ns.braces ])))"
139141
`;
140142

141143
exports[`binaryNoEs6Arrow.js 1`] = `

tests/parsing/grammar/expressions/binary.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ let _ = {
4343
#Constructor(a, b)
4444
}
4545

46+
library.getBalance(. account)
47+
->Promise.Js.catch(_ => {Promise.resolved(None)})

tests/printer/expr/__snapshots__/render.spec.js.snap

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,27 @@ let aggregateTotal = (forecast, ~audienceType) =>
748748
views: item[\\"reach\\"][\\"views\\"],
749749
sample: item[\\"reach\\"][\\"sample\\"],
750750
})
751+
752+
React.useEffect4(() => {
753+
switch (context.library, context.account) {
754+
| (Some(library), Some(account)) =>
755+
library.getBalance(. account)
756+
->Promise.Js.catch(_ => {Promise.resolved(None)})
757+
->Promise.get(newBalance => {
758+
dispatch(
759+
LoadAddress(
760+
account,
761+
newBalance->Belt.Option.flatMap(balance =>
762+
Eth.make(balance.toString(.))
763+
),
764+
),
765+
)
766+
})
767+
768+
None
769+
| _ => None
770+
}
771+
}, (context.library, context.account, context.chainId, dispatch))
751772
"
752773
`;
753774

tests/printer/expr/binary.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,27 @@ let aggregateTotal = (forecast, ~audienceType) =>
364364
views: item["reach"]["views"],
365365
sample: item["reach"]["sample"],
366366
})
367+
368+
React.useEffect4(
369+
() => {
370+
switch (context.library, context.account) {
371+
| (Some(library), Some(account)) =>
372+
library.getBalance(. account)
373+
->Promise.Js.catch(_ => {Promise.resolved(None)})
374+
->Promise.get(newBalance => {
375+
dispatch(
376+
LoadAddress(
377+
account,
378+
newBalance->Belt.Option.flatMap(balance =>
379+
Eth.make(balance.toString(.))
380+
),
381+
),
382+
)
383+
})
384+
385+
None
386+
| _ => None
387+
}
388+
},
389+
(context.library, context.account, context.chainId, dispatch),
390+
)

0 commit comments

Comments
 (0)