Skip to content

Fix formatter removed parens in uncurried function when used with this-callback #6773

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

Closed
wants to merge 6 commits into from
Closed
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
12 changes: 9 additions & 3 deletions jscomp/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2635,10 +2635,16 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
Doc.concat [Doc.text ": "; typDoc]
| _ -> Doc.nil
in
let hasThisAttr =
List.exists (fun ({Asttypes.txt}, _) -> txt = "this") attrs
in
let attrs = printAttributes ~state attrs cmtTbl in
Doc.group
(Doc.concat
[attrs; parametersDoc; typConstraintDoc; Doc.text " =>"; returnExprDoc])
let doc =
Doc.concat
[parametersDoc; typConstraintDoc; Doc.text " =>"; returnExprDoc]
in
if hasThisAttr then Doc.group (Doc.concat [attrs; addParens doc])
else Doc.group (Doc.concat [attrs; doc])
in
let uncurried = Ast_uncurried.exprIsUncurriedFun e in
let e_fun =
Expand Down
5 changes: 5 additions & 0 deletions jscomp/syntax/tests/printer/other/attributes.res
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ let x = 1
)
let x = 1

#b(@this (t => unit), @this ((x,t) => unit))

#b(@this (t => unit))

#b((t => unit))
6 changes: 6 additions & 0 deletions jscomp/syntax/tests/printer/other/expected/attributes.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ let x = 1

@inlinePrivate(@module("./logo.svg") external logo: string = "default")
let x = 1

#b(@this (t => unit), @this ((x,t) => unit))

#b(@this (t => unit))

#b(t => unit)
Loading