mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Don't try to strip parentheses when emitting synthesized parenthesized expressions
This commit is contained in:
parent
1bb46e3f33
commit
4ccf088734
@ -1644,6 +1644,13 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
}
|
||||
|
||||
function parenthesizeForAccess(expr: Expression): LeftHandSideExpression {
|
||||
// When diagnosing whether the expression needs parentheses, the decision should be based
|
||||
// on the innermost expression in a chain of nested type assertions.
|
||||
let innerExpression = expr;
|
||||
while (innerExpression.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
innerExpression = (<TypeAssertion>innerExpression).expression;
|
||||
}
|
||||
|
||||
// isLeftHandSideExpression is almost the correct criterion for when it is not necessary
|
||||
// to parenthesize the expression before a dot. The known exceptions are:
|
||||
//
|
||||
@ -1652,7 +1659,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
// NumberLiteral
|
||||
// 1.x -> not the same as (1).x
|
||||
//
|
||||
if (isLeftHandSideExpression(expr) && expr.kind !== SyntaxKind.NewExpression && expr.kind !== SyntaxKind.NumericLiteral) {
|
||||
if (isLeftHandSideExpression(innerExpression) &&
|
||||
innerExpression.kind !== SyntaxKind.NewExpression &&
|
||||
innerExpression.kind !== SyntaxKind.NumericLiteral) {
|
||||
|
||||
return <LeftHandSideExpression>expr;
|
||||
}
|
||||
let node = <ParenthesizedExpression>createSynthesizedNode(SyntaxKind.ParenthesizedExpression);
|
||||
@ -1906,7 +1916,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
||||
}
|
||||
|
||||
function emitParenExpression(node: ParenthesizedExpression) {
|
||||
if (!node.parent || node.parent.kind !== SyntaxKind.ArrowFunction) {
|
||||
// If the node is synthesized, it means the emitter put the parentheses there,
|
||||
// not the user. If we didn't want them, the emitter would not have put them
|
||||
// there.
|
||||
if (!nodeIsSynthesized(node) && node.parent.kind !== SyntaxKind.ArrowFunction) {
|
||||
if (node.expression.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
let operand = (<TypeAssertion>node.expression).expression;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user