mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Fix empty object literal property access
This commit is contained in:
@@ -3811,14 +3811,18 @@ namespace ts {
|
||||
*/
|
||||
export function parenthesizeForAccess(expression: Expression): LeftHandSideExpression {
|
||||
// isLeftHandSideExpression is almost the correct criterion for when it is not necessary
|
||||
// to parenthesize the expression before a dot. The known exception is:
|
||||
// to parenthesize the expression before a dot. There are two known exceptions:
|
||||
//
|
||||
// NewExpression:
|
||||
// new C.x -> not the same as (new C).x
|
||||
//
|
||||
// EmptyObjectLiteral:
|
||||
// {}.toString() -> is incorrect syntax, should be ({}).x
|
||||
//
|
||||
const emittedExpression = skipPartiallyEmittedExpressions(expression);
|
||||
if (isLeftHandSideExpression(emittedExpression)
|
||||
&& (emittedExpression.kind !== SyntaxKind.NewExpression || (<NewExpression>emittedExpression).arguments)) {
|
||||
&& (emittedExpression.kind !== SyntaxKind.NewExpression || (<NewExpression>emittedExpression).arguments)
|
||||
&& !isEmptyObjectLiteral(emittedExpression)) {
|
||||
return <LeftHandSideExpression>expression;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user