Merge pull request #15006 from Microsoft/master-14895

[Master] Emit parenthesis around propert/element access expression of casted object literal expression
This commit is contained in:
Yui
2017-04-05 13:03:24 -07:00
committed by GitHub
10 changed files with 96 additions and 5 deletions

View File

@@ -3489,8 +3489,7 @@ namespace ts {
}
export function parenthesizeConciseBody(body: ConciseBody): ConciseBody {
const emittedBody = skipPartiallyEmittedExpressions(body);
if (emittedBody.kind === SyntaxKind.ObjectLiteralExpression) {
if (!isBlock(body) && getLeftmostExpression(body).kind === SyntaxKind.ObjectLiteralExpression) {
return setTextRange(createParen(<Expression>body), body);
}

View File

@@ -2324,13 +2324,13 @@ namespace ts {
// code if the casted expression has a lower precedence than the rest of the
// expression.
//
// To preserve comments, we return a "PartiallyEmittedExpression" here which will
// preserve the position information of the original expression.
//
// Due to the auto-parenthesization rules used by the visitor and factory functions
// we can safely elide the parentheses here, as a new synthetic
// ParenthesizedExpression will be inserted if we remove parentheses too
// aggressively.
//
// To preserve comments, we return a "PartiallyEmittedExpression" here which will
// preserve the position information of the original expression.
return createPartiallyEmittedExpression(expression, node);
}