diff --git a/jscomp/syntax/src/res_printer.ml b/jscomp/syntax/src/res_printer.ml index 0bdfaa1b4e..c9331961b0 100644 --- a/jscomp/syntax/src/res_printer.ml +++ b/jscomp/syntax/src/res_printer.ml @@ -1452,7 +1452,8 @@ and printConstructorDeclaration2 ~state i printComments doc cmtTbl cd.pcd_name.loc in let constrArgs = - printConstructorArguments ~isDotDotDot ~state ~indent:true cd.pcd_args cmtTbl + printConstructorArguments ~isDotDotDot ~state ~indent:true cd.pcd_args + cmtTbl in let gadt = match cd.pcd_res with @@ -3453,6 +3454,12 @@ and printTemplateLiteral ~state expr cmtTbl = printStringContents txt | _ -> let doc = printExpressionWithComments ~state expr cmtTbl in + let doc = + match Parens.expr expr with + | Parens.Parenthesized -> addParens doc + | Braced braces -> printBraces doc expr braces + | Nothing -> doc + in Doc.group (Doc.concat [Doc.text "${"; Doc.indent doc; Doc.rbrace]) in let content = walkExpr expr in diff --git a/jscomp/syntax/tests/printer/expr/expected/templateLiteral.res.txt b/jscomp/syntax/tests/printer/expr/expected/templateLiteral.res.txt index 10e925c174..f0085b2d1d 100644 --- a/jscomp/syntax/tests/printer/expr/expected/templateLiteral.res.txt +++ b/jscomp/syntax/tests/printer/expr/expected/templateLiteral.res.txt @@ -49,6 +49,8 @@ let s = ` let s = `$dollar without $braces $interpolation` +let s = `${(s: string)}` + // don't sugar to one single template literal, keep the concatenation `the sky` ++ `is blue` diff --git a/jscomp/syntax/tests/printer/expr/templateLiteral.res b/jscomp/syntax/tests/printer/expr/templateLiteral.res index ba0546a71d..5829bee872 100644 --- a/jscomp/syntax/tests/printer/expr/templateLiteral.res +++ b/jscomp/syntax/tests/printer/expr/templateLiteral.res @@ -49,6 +49,8 @@ let s = ` let s = `$dollar without $braces $interpolation` +let s = `${(s: string)}` + // don't sugar to one single template literal, keep the concatenation `the sky` ++ `is blue`