Address PR: move the adding paren into factory function

This commit is contained in:
Kanchalai Tanglertsampan
2017-04-05 10:13:10 -07:00
parent 0a194f91a0
commit 82f3775956
2 changed files with 4 additions and 8 deletions

View File

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

View File

@@ -2326,17 +2326,12 @@ namespace ts {
//
// To preserve comments, we return a "PartiallyEmittedExpression" here which will
// preserve the position information of the original expression.
const partialExpression = createPartiallyEmittedExpression(expression, node);
//
// 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.
// However, auto-parenthesization will not preserve parenthesis for the following case: ({ "1": "one", "2": "two" } as { [key: string]: string })[x].
// so we have to manually preserve it here.
const shouldPreserveParen = (isPropertyAccessExpression(node.parent) || isElementAccessExpression(node.parent)) &&
isObjectLiteralExpression((expression as PartiallyEmittedExpression).expression);
return shouldPreserveParen ? createParen(partialExpression) : partialExpression;
return createPartiallyEmittedExpression(expression, node);
}
return visitEachChild(node, visitor, context);