Emit parens for tag of tagged template if necessary

This commit is contained in:
Ivo Gabe de Wolff 2015-02-13 18:34:32 +01:00
parent 8e16e1d010
commit f77bedd6f6
5 changed files with 8 additions and 8 deletions

View File

@ -2189,7 +2189,7 @@ module ts {
}
write("], ");
emit(node.tag);
emitParenthesizedIf(node.tag, needsParenthesisForPropertyAccessOrInvocation(node.tag));
write("(");
emit(tempVariable);
@ -2475,7 +2475,7 @@ module ts {
emit((<SpreadElementExpression>node).expression);
}
function needsParenthesisForPropertyAccess(node: Expression) {
function needsParenthesisForPropertyAccessOrInvocation(node: Expression) {
switch (node.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.ArrayLiteralExpression:
@ -2517,7 +2517,7 @@ module ts {
var e = elements[pos];
if (e.kind === SyntaxKind.SpreadElementExpression) {
e = (<SpreadElementExpression>e).expression;
emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccess(e));
emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e));
pos++;
}
else {

View File

@ -5,8 +5,8 @@ var x = {
}
//// [templateStringInObjectLiteral.js]
var x = (_a = ["b"], _a.raw = ["b"], {
var x = (_a = ["b"], _a.raw = ["b"], ({
a: "abc" + 123 + "def"
}(_a));
})(_a));
321;
var _a;

View File

@ -4,6 +4,6 @@ var x = {
}
//// [templateStringInPropertyName1.js]
var x = (_a = ["a"], _a.raw = ["a"], {}(_a));
var x = (_a = ["a"], _a.raw = ["a"], ({})(_a));
321;
var _a;

View File

@ -4,6 +4,6 @@ var x = {
}
//// [templateStringInPropertyName2.js]
var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], {}(_a, 123, 456));
var x = (_a = ["abc", "def", "ghi"], _a.raw = ["abc", "def", "ghi"], ({})(_a, 123, 456));
321;
var _a;

View File

@ -2,5 +2,5 @@
`I AM THE ${ `${ `TAG` } ` } PORTION` `I ${ "AM" } THE TEMPLATE PORTION`
//// [templateStringInTaggedTemplate.js]
(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], "I AM THE " + "TAG" + " " + " PORTION"(_a, "AM"));
(_a = ["I ", " THE TEMPLATE PORTION"], _a.raw = ["I ", " THE TEMPLATE PORTION"], ("I AM THE " + "TAG" + " " + " PORTION")(_a, "AM"));
var _a;