mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-10 15:25:54 -06:00
Fix property access bug instead by wrapping entire access in brackets
Modify parenthesizeExpressionForExpressionStatement to add brackets around an expression statement in which the left-most expression is an object literal.
This commit is contained in:
parent
76ef97449c
commit
54edde8892
@ -3875,18 +3875,14 @@ 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. There are two known exceptions:
|
||||
// to parenthesize the expression before a dot. The known exception is:
|
||||
//
|
||||
// NewExpression:
|
||||
// new C.x -> not the same as (new C).x
|
||||
//
|
||||
// ObjectLiteral:
|
||||
// {a:1}.toString() -> is incorrect syntax, should be ({a:1}).toString()
|
||||
//
|
||||
const emittedExpression = skipPartiallyEmittedExpressions(expression);
|
||||
if (isLeftHandSideExpression(emittedExpression)
|
||||
&& (!isNewExpression(emittedExpression) || (<NewExpression>emittedExpression).arguments)
|
||||
&& !isObjectLiteralExpression(emittedExpression)) {
|
||||
&& (emittedExpression.kind !== SyntaxKind.NewExpression || (<NewExpression>emittedExpression).arguments)) {
|
||||
return <LeftHandSideExpression>expression;
|
||||
}
|
||||
|
||||
@ -3945,11 +3941,10 @@ namespace ts {
|
||||
return recreateOuterExpressions(expression, mutableCall, OuterExpressionKinds.PartiallyEmittedExpressions);
|
||||
}
|
||||
}
|
||||
else {
|
||||
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
|
||||
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
|
||||
return setTextRange(createParen(expression), expression);
|
||||
}
|
||||
|
||||
const leftmostExpressionKind = getLeftmostExpression(emittedExpression).kind;
|
||||
if (leftmostExpressionKind === SyntaxKind.ObjectLiteralExpression || leftmostExpressionKind === SyntaxKind.FunctionExpression) {
|
||||
return setTextRange(createParen(expression), expression);
|
||||
}
|
||||
|
||||
return expression;
|
||||
|
||||
@ -14,7 +14,7 @@ var A = /** @class */ (function () {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
({}).toString();
|
||||
({}.toString());
|
||||
(function () {
|
||||
({}).toString();
|
||||
({}.toString());
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user