Skip to content

Commit aabfebd

Browse files
Fixed emit for parenthesized template expressions.
1 parent 64097a3 commit aabfebd

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/compiler/emitter.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -817,8 +817,11 @@ module ts {
817817
return;
818818
}
819819

820-
var templateNeedsParens = isExpression(node.parent) &&
821-
comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan;
820+
Debug.assert(node.parent.kind !== SyntaxKind.TaggedTemplateExpression);
821+
822+
var templateNeedsParens = isExpression(node.parent)
823+
&& node.parent.kind !== SyntaxKind.ParenExpression
824+
&& comparePrecedenceToBinaryPlus(node.parent) !== Comparison.LessThan;
822825

823826
if (templateNeedsParens) {
824827
write("(");
@@ -836,7 +839,8 @@ module ts {
836839
// ("abc" + 1) << (2 + "")
837840
// rather than
838841
// "abc" + (1 << 2) + ""
839-
var needsParens = comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan;
842+
var needsParens = templateSpan.expression.kind !== SyntaxKind.ParenExpression
843+
&& comparePrecedenceToBinaryPlus(templateSpan.expression) !== Comparison.GreaterThan;
840844

841845
write(" + ");
842846

tests/baselines/reference/templateStringInParentheses.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
var x = (`abc${0}abc`);
33

44
//// [templateStringInParentheses.js]
5-
var x = (("abc" + 0 + "abc"));
5+
var x = ("abc" + 0 + "abc");

0 commit comments

Comments
 (0)