Merge pull request #7904 from Microsoft/transforms-fixAwaitAsYieldParens

Fixes extra parens around yield downleveled from await
This commit is contained in:
Ron Buckton 2016-04-06 16:26:13 -07:00
commit f0839e6fc2
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")] : [];
}
/**

View File

@ -4,7 +4,7 @@ function * foo(a = yield => yield) {
//// [FunctionDeclaration10_es6.js]
function* foo(a) {
if (a === void 0) { a = (yield); }
if (a === void 0) { a = yield; }
}
yield;
{

View File

@ -12,13 +12,13 @@ let C = class extends class extends class {
this.a = 1;
}
} {
constructor(...args_1) {
super(...args_1);
constructor(...args) {
super(...args);
this.b = 2;
}
} {
constructor(...args_2) {
super(...args_2);
constructor(...args) {
super(...args);
this.c = 3;
}
};