diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index cd790eeb20..1a700c70f7 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -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 = diff --git a/jscomp/syntax/tests/printer/other/attributes.res b/jscomp/syntax/tests/printer/other/attributes.res index 1df3f38b6c..35161c6ebd 100644 --- a/jscomp/syntax/tests/printer/other/attributes.res +++ b/jscomp/syntax/tests/printer/other/attributes.res @@ -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)) diff --git a/jscomp/syntax/tests/printer/other/expected/attributes.res.txt b/jscomp/syntax/tests/printer/other/expected/attributes.res.txt index 5f353627ef..195e7be57a 100644 --- a/jscomp/syntax/tests/printer/other/expected/attributes.res.txt +++ b/jscomp/syntax/tests/printer/other/expected/attributes.res.txt @@ -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)