mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Emit parens for tag of tagged template if necessary
This commit is contained in:
parent
8e16e1d010
commit
f77bedd6f6
@ -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 {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user