File tree Expand file tree Collapse file tree 2 files changed +4
-8
lines changed Expand file tree Collapse file tree 2 files changed +4
-8
lines changed Original file line number Diff line number Diff line change @@ -3492,7 +3492,8 @@ namespace ts {
3492
3492
3493
3493
export function parenthesizeConciseBody ( body : ConciseBody ) : ConciseBody {
3494
3494
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 ) {
3496
3497
return setTextRange ( createParen ( < Expression > body ) , body ) ;
3497
3498
}
3498
3499
Original file line number Diff line number Diff line change @@ -2326,17 +2326,12 @@ namespace ts {
2326
2326
//
2327
2327
// To preserve comments, we return a "PartiallyEmittedExpression" here which will
2328
2328
// preserve the position information of the original expression.
2329
- const partialExpression = createPartiallyEmittedExpression ( expression , node ) ;
2330
-
2329
+ //
2331
2330
// Due to the auto-parenthesization rules used by the visitor and factory functions
2332
2331
// we can safely elide the parentheses here, as a new synthetic
2333
2332
// ParenthesizedExpression will be inserted if we remove parentheses too
2334
2333
// 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 ) ;
2340
2335
}
2341
2336
2342
2337
return visitEachChild ( node , visitor , context ) ;
You can’t perform that action at this time.
0 commit comments