Skip to content

Commit 82f3775

Browse files
author
Kanchalai Tanglertsampan
committed
Address PR: move the adding paren into factory function
1 parent 0a194f9 commit 82f3775

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

src/compiler/factory.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,8 @@ namespace ts {
34923492

34933493
export function parenthesizeConciseBody(body: ConciseBody): ConciseBody {
34943494
const emittedBody = skipPartiallyEmittedExpressions(body);
3495-
if (emittedBody.kind === SyntaxKind.ObjectLiteralExpression) {
3495+
const leftMostExpression = isExpression(emittedBody) ? getLeftmostExpression(emittedBody) : undefined;
3496+
if (leftMostExpression && leftMostExpression.kind === SyntaxKind.ObjectLiteralExpression) {
34963497
return setTextRange(createParen(<Expression>body), body);
34973498
}
34983499

src/compiler/transformers/ts.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2326,17 +2326,12 @@ namespace ts {
23262326
//
23272327
// To preserve comments, we return a "PartiallyEmittedExpression" here which will
23282328
// preserve the position information of the original expression.
2329-
const partialExpression = createPartiallyEmittedExpression(expression, node);
2330-
2329+
//
23312330
// Due to the auto-parenthesization rules used by the visitor and factory functions
23322331
// we can safely elide the parentheses here, as a new synthetic
23332332
// ParenthesizedExpression will be inserted if we remove parentheses too
23342333
// aggressively.
2335-
// However, auto-parenthesization will not preserve parenthesis for the following case: ({ "1": "one", "2": "two" } as { [key: string]: string })[x].
2336-
// so we have to manually preserve it here.
2337-
const shouldPreserveParen = (isPropertyAccessExpression(node.parent) || isElementAccessExpression(node.parent)) &&
2338-
isObjectLiteralExpression((expression as PartiallyEmittedExpression).expression);
2339-
return shouldPreserveParen ? createParen(partialExpression) : partialExpression;
2334+
return createPartiallyEmittedExpression(expression, node);
23402335
}
23412336

23422337
return visitEachChild(node, visitor, context);

0 commit comments

Comments
 (0)