Fixes extra parens around yield downleveled from await

This commit is contained in:
Ron Buckton
2016-04-06 15:49:53 -07:00
parent 39c877a7f9
commit 4da09b73bc
4 changed files with 17 additions and 9 deletions

View File

@@ -1272,10 +1272,19 @@ namespace ts {
// If `a ** d` is on the left of operator `**`, we need to parenthesize to preserve
// the intended order of operations: `(a ** b) ** c`
const binaryOperatorPrecedence = getOperatorPrecedence(SyntaxKind.BinaryExpression, binaryOperator);
const binaryOperatorAssociativity = getOperatorAssociativity(SyntaxKind.BinaryExpression, binaryOperator);
const emittedOperand = skipPartiallyEmittedExpressions(operand);
const operandPrecedence = getExpressionPrecedence(emittedOperand);
switch (compareValues(operandPrecedence, binaryOperatorPrecedence)) {
case Comparison.LessThan:
// If the operand is the right side of a right-associative binary operation
// and is a yield expression, then we do not need parentheses.
if (!isLeftSideOfBinary
&& binaryOperatorAssociativity === Associativity.Right
&& operand.kind === SyntaxKind.YieldExpression) {
return false;
}
return true;
case Comparison.GreaterThan:
@@ -1287,12 +1296,11 @@ namespace ts {
// left associative:
// (a*b)/x -> a*b/x
// (a**b)/x -> a**b/x
//
// Parentheses are needed for the left operand when the binary operator is
// right associative:
// (a/b)**x -> (a/b)**x
// (a**b)**x -> (a**b)**x
const binaryOperatorAssociativity = getOperatorAssociativity(SyntaxKind.BinaryExpression, binaryOperator);
return binaryOperatorAssociativity === Associativity.Right;
}
else {
@@ -1326,7 +1334,7 @@ namespace ts {
// associative:
// x/(a**b) -> x/a**b
// x**(a**b) -> x**a**b
//
// Parentheses are needed for the right operand when the operand is left
// associative:
// x/(a*b) -> x/(a*b)

View File

@@ -748,7 +748,7 @@ namespace ts {
function transformConstructorParameters(constructor: ConstructorDeclaration, hasExtendsClause: boolean) {
return constructor
? visitNodes(constructor.parameters, visitor, isParameter)
: hasExtendsClause ? [createRestParameter(createUniqueName("args"))] : [];
: hasExtendsClause ? [createRestParameter("args")] : [];
}
/**