diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 342ea067c0e..951f3bd8fd4 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -230,9 +230,16 @@ namespace ts { : node; } + function parenthesizeForComputedName(expression: Expression): Expression { + return (isBinaryExpression(expression) && expression.operatorToken.kind === SyntaxKind.CommaToken) || + expression.kind === SyntaxKind.CommaListExpression ? + createParen(expression) : + expression; + } + export function createComputedPropertyName(expression: Expression) { const node = createSynthesizedNode(SyntaxKind.ComputedPropertyName); - node.expression = expression; + node.expression = parenthesizeForComputedName(expression); return node; } diff --git a/tests/baselines/reference/decoratorsOnComputedProperties.js b/tests/baselines/reference/decoratorsOnComputedProperties.js index 0083bc8b9a1..ee7db88503f 100644 --- a/tests/baselines/reference/decoratorsOnComputedProperties.js +++ b/tests/baselines/reference/decoratorsOnComputedProperties.js @@ -262,7 +262,7 @@ class C { this[_k] = null; this[_l] = null; } - [foo(), _m = foo(), _k = foo(), _o = fieldNameB, _l = fieldNameC, "some" + "method"]() { } + [(foo(), _m = foo(), _k = foo(), _o = fieldNameB, _l = fieldNameC, "some" + "method")]() { } } __decorate([ x @@ -297,7 +297,7 @@ void class D { this[_p] = null; this[_q] = null; } - [foo(), _r = foo(), _p = foo(), _s = fieldNameB, _q = fieldNameC, "some" + "method"]() { } + [(foo(), _r = foo(), _p = foo(), _s = fieldNameB, _q = fieldNameC, "some" + "method")]() { } }; class E { constructor() { @@ -308,7 +308,7 @@ class E { this[_t] = null; this[_u] = null; } - [foo(), _v = foo(), _t = foo(), "some" + "method"]() { } + [(foo(), _v = foo(), _t = foo(), "some" + "method")]() { } } _w = fieldNameB, _u = fieldNameC; __decorate([ @@ -344,7 +344,7 @@ void (_x = class F { this[_y] = null; this[_z] = null; } - [foo(), _0 = foo(), _y = foo(), "some" + "method"]() { } + [(foo(), _0 = foo(), _y = foo(), "some" + "method")]() { } }, _1 = fieldNameB, _z = fieldNameC, @@ -358,8 +358,8 @@ class G { this[_2] = null; this[_3] = null; } - [foo(), _4 = foo(), _2 = foo(), "some" + "method"]() { } - [_5 = fieldNameB, "some" + "method2"]() { } + [(foo(), _4 = foo(), _2 = foo(), "some" + "method")]() { } + [(_5 = fieldNameB, "some" + "method2")]() { } } _3 = fieldNameC; __decorate([ @@ -395,8 +395,8 @@ void (_6 = class H { this[_7] = null; this[_8] = null; } - [foo(), _9 = foo(), _7 = foo(), "some" + "method"]() { } - [_10 = fieldNameB, "some" + "method2"]() { } + [(foo(), _9 = foo(), _7 = foo(), "some" + "method")]() { } + [(_10 = fieldNameB, "some" + "method2")]() { } }, _8 = fieldNameC, _6); @@ -409,8 +409,8 @@ class I { this[_11] = null; this[_12] = null; } - [foo(), _13 = foo(), _11 = foo(), _14 = "some" + "method"]() { } - [_15 = fieldNameB, "some" + "method2"]() { } + [(foo(), _13 = foo(), _11 = foo(), _14 = "some" + "method")]() { } + [(_15 = fieldNameB, "some" + "method2")]() { } } _12 = fieldNameC; __decorate([ @@ -449,8 +449,8 @@ void (_16 = class J { this[_17] = null; this[_18] = null; } - [foo(), _19 = foo(), _17 = foo(), _20 = "some" + "method"]() { } - [_21 = fieldNameB, "some" + "method2"]() { } + [(foo(), _19 = foo(), _17 = foo(), _20 = "some" + "method")]() { } + [(_21 = fieldNameB, "some" + "method2")]() { } }, _18 = fieldNameC, _16); diff --git a/tests/baselines/reference/symbolProperty7.js b/tests/baselines/reference/symbolProperty7.js index 9dbe5a1abb1..bebc929e95d 100644 --- a/tests/baselines/reference/symbolProperty7.js +++ b/tests/baselines/reference/symbolProperty7.js @@ -13,7 +13,7 @@ class C { constructor() { this[_a] = 0; } - [_a = Symbol(), Symbol(), Symbol()]() { } + [(_a = Symbol(), Symbol(), Symbol())]() { } get [Symbol()]() { return 0; }