mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Parenthesize computed names if not an assignment expression (#22280)
This commit is contained in:
@@ -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 = <ComputedPropertyName>createSynthesizedNode(SyntaxKind.ComputedPropertyName);
|
||||
node.expression = expression;
|
||||
node.expression = parenthesizeForComputedName(expression);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user