Merge pull request #21216 from Microsoft/fix19103

Fix incorrect parenthesization logic for conditional expression branches
This commit is contained in:
Ron Buckton
2018-01-16 17:00:55 -08:00
committed by GitHub
5 changed files with 61 additions and 1 deletions

View File

@@ -3960,7 +3960,9 @@ namespace ts {
// per ES grammar both 'whenTrue' and 'whenFalse' parts of conditional expression are assignment expressions
// so in case when comma expression is introduced as a part of previous transformations
// if should be wrapped in parens since comma operator has the lowest precedence
return e.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>e).operatorToken.kind === SyntaxKind.CommaToken
const emittedExpression = skipPartiallyEmittedExpressions(e);
return emittedExpression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>emittedExpression).operatorToken.kind === SyntaxKind.CommaToken ||
emittedExpression.kind === SyntaxKind.CommaListExpression
? createParen(e)
: e;
}