Skip to content
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

Fix some comments disappearing in array sugar. #5947

Merged
merged 4 commits into from
Jan 18, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ These are only breaking changes for unformatted code.
- Fix compiler ppx issue when combining `async` and uncurried application https://github.com/rescript-lang/rescript-compiler/pull/5856
- Fix issue where the internal representation of uncurried types would leak when a non-function is applied in a curried way https://github.com/rescript-lang/rescript-compiler/pull/5892
- In GenType, check annotations also in module types to decide whether to produce the `.gen.tsx` file https://github.com/rescript-lang/rescript-compiler/pull/5903
- Fix some comments disappearing in array access expressions https://github.com/rescript-lang/rescript-compiler/pull/5947

#### :nail_care: Polish

Expand Down
11 changes: 11 additions & 0 deletions res_syntax/src/res_comments_table.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,17 @@ and walkExpression expr t comments =
walkExpression operand2 t inside;
(* (List.concat [inside; after]); *)
attach t.trailing operand2.pexp_loc after
| Pexp_apply
( {pexp_desc = Pexp_ident {txt = Longident.Ldot (Lident "Array", "get")}},
[(Nolabel, parentExpr); (Nolabel, memberExpr)] ) ->
walkList [Expression parentExpr; Expression memberExpr] t comments
| Pexp_apply
( {pexp_desc = Pexp_ident {txt = Longident.Ldot (Lident "Array", "set")}},
[(Nolabel, parentExpr); (Nolabel, memberExpr); (Nolabel, targetExpr)] )
->
walkList
[Expression parentExpr; Expression memberExpr; Expression targetExpr]
t comments
| Pexp_apply (callExpr, arguments) ->
let before, inside, after = partitionByLoc comments callExpr.pexp_loc in
let after =
Expand Down
18 changes: 18 additions & 0 deletions res_syntax/tests/printer/comments/array.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
a[ /* zz */ 0 ] = 7

let _ = (
/* zz */ a
)[0]

let _ = (
a // zz
)[0]

(
incidents
->Belt.Array.keep(({status}) => status === #OPEN)
// This comment will vanish
->Belt.SortArray.stableSortBy((a, b) =>
compare(a.createdTime, b.createdTime)
)
)[0]
12 changes: 12 additions & 0 deletions res_syntax/tests/printer/comments/expected/array.res.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
a[/* zz */ 0] = 7

let _ = /* zz */ a[0]

let _ = a[0] // zz

(
incidents
->Belt.Array.keep(({status}) => status === #OPEN)
// This comment will vanish
->Belt.SortArray.stableSortBy((a, b) => compare(a.createdTime, b.createdTime))
)[0]