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

Commit c2b5750

Browse files
committed
Fix parsing of expressions with underscore _ and comments.
Fixes #661
1 parent c32aafe commit c2b5750

File tree

6 files changed

+32
-3
lines changed

6 files changed

+32
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- Fix printing of comments inside empty blocks https://github.com/rescript-lang/syntax/pull/647
3131
- Fix location issue in error messages with JSX V4 where the multiple props types are defined https://github.com/rescript-lang/syntax/pull/655
3232
- Fix location issue in make function in JSX V4 that breaks dead code elimination https://github.com/rescript-lang/syntax/pull/660
33+
- Fix parsing (hence pretty printing) of expressions with underscore `_` and comments.
3334

3435
## ReScript 10.0
3536

src/res_core.ml

+4-2
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,13 @@ let processUnderscoreApplication args =
510510
| _ -> arg
511511
in
512512
let args = List.map check_arg args in
513-
let wrap exp_apply =
513+
let wrap (exp_apply : Parsetree.expression) =
514514
match !exp_question with
515515
| Some {pexp_loc = loc} ->
516516
let pattern =
517-
Ast_helper.Pat.mk (Ppat_var (Location.mkloc hidden_var loc)) ~loc
517+
Ast_helper.Pat.mk
518+
(Ppat_var (Location.mkloc hidden_var loc))
519+
~loc:Location.none
518520
in
519521
Ast_helper.Exp.mk (Pexp_fun (Nolabel, None, pattern, exp_apply)) ~loc
520522
| None -> exp_apply

tests/parsing/grammar/expressions/expected/underscoreApply.res.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ let l1 =
1414
List.length
1515
let l2 =
1616
([Some 1; None; Some 2] |> (List.map (fun __x -> optParam ?v:__x ()))) |>
17-
List.length
17+
List.length
18+
;;fun __x ->
19+
underscoreWithComments (fun x -> ((something ())[@ns.braces ])) __x

tests/parsing/grammar/expressions/underscoreApply.res

+9
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ let l1 =
1919

2020
let l2 =
2121
list{Some(1), None, Some(2)} |> List.map(optParam(~v=?_, ())) |> List.length
22+
23+
underscoreWithComments(
24+
// Comment 1
25+
x => {
26+
// Comment 2
27+
something()
28+
},
29+
_,
30+
)

tests/printer/expr/expected/underscoreApply.res.txt

+6
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ Array.get(_, 1) + Array.get(_, 0)
6161
let f = Array.get(_, 0)
6262

6363
let photo = pricedRoom["room"]["photos"] |> filterNone |> Array.get(_, 0)
64+
65+
underscoreWithComments(// Comment 1
66+
x => {
67+
// Comment 2
68+
something()
69+
}, _)

tests/printer/expr/underscoreApply.res

+9
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@ Array.get(_, 1) + Array.get(_, 0)
6363
let f = Array.get(_, 0)
6464

6565
let photo = pricedRoom["room"]["photos"] |> filterNone |> Array.get(_, 0)
66+
67+
underscoreWithComments(
68+
// Comment 1
69+
x => {
70+
// Comment 2
71+
something()
72+
},
73+
_,
74+
)

0 commit comments

Comments
 (0)