Skip to content

Commit 18a2f2f

Browse files
authored
Fix printing of type constraints in template literal substitutions (#6324)
1 parent df1bc3d commit 18a2f2f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

jscomp/syntax/src/res_printer.ml

+8-1
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,8 @@ and printConstructorDeclaration2 ~state i
14521452
printComments doc cmtTbl cd.pcd_name.loc
14531453
in
14541454
let constrArgs =
1455-
printConstructorArguments ~isDotDotDot ~state ~indent:true cd.pcd_args cmtTbl
1455+
printConstructorArguments ~isDotDotDot ~state ~indent:true cd.pcd_args
1456+
cmtTbl
14561457
in
14571458
let gadt =
14581459
match cd.pcd_res with
@@ -3453,6 +3454,12 @@ and printTemplateLiteral ~state expr cmtTbl =
34533454
printStringContents txt
34543455
| _ ->
34553456
let doc = printExpressionWithComments ~state expr cmtTbl in
3457+
let doc =
3458+
match Parens.expr expr with
3459+
| Parens.Parenthesized -> addParens doc
3460+
| Braced braces -> printBraces doc expr braces
3461+
| Nothing -> doc
3462+
in
34563463
Doc.group (Doc.concat [Doc.text "${"; Doc.indent doc; Doc.rbrace])
34573464
in
34583465
let content = walkExpr expr in

jscomp/syntax/tests/printer/expr/expected/templateLiteral.res.txt

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ let s = `
4949

5050
let s = `$dollar without $braces $interpolation`
5151

52+
let s = `${(s: string)}`
53+
5254
// don't sugar to one single template literal, keep the concatenation
5355
`the sky` ++ `is blue`
5456

jscomp/syntax/tests/printer/expr/templateLiteral.res

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ let s = `
4949

5050
let s = `$dollar without $braces $interpolation`
5151

52+
let s = `${(s: string)}`
53+
5254
// don't sugar to one single template literal, keep the concatenation
5355
`the sky` ++ `is blue`
5456

0 commit comments

Comments
 (0)