@@ -3015,11 +3015,31 @@ namespace ts {
30153015 let newPrecedence = getBinaryOperatorPrecedence ( ) ;
30163016
30173017 // Check the precedence to see if we should "take" this operator
3018- if ( token === SyntaxKind . AsteriskAsteriskToken && newPrecedence < precedence ) {
3019- // ** operator is right-assocative
3020- break ;
3021- }
3022- else if ( token !== SyntaxKind . AsteriskAsteriskToken && newPrecedence <= precedence ) {
3018+ // - For left associative operator (all operator but **), only consume the operator
3019+ // , recursively call the function below and parse binaryExpression as a rightOperand
3020+ // of the caller if the new precendence of the operator is greater then or equal to the current precendence.
3021+ // For example:
3022+ // a - b - c;
3023+ // ^token; leftOperand = b. Return b to the caller as a rightOperand
3024+ // a * b - c
3025+ // ^token; leftOperand = b. Return b to the caller as a rightOperand
3026+ // a - b * c;
3027+ // ^token; leftOperand = b. Return b * c to the caller as a rightOperand
3028+ // - For right associative operator (**), only consume the operator, recursively call the function
3029+ // and parse binaryExpression as a rightOperand of the caller if the new precendence of
3030+ // the operator is strictly grater than the current precendence
3031+ // For example:
3032+ // a ** b ** c;
3033+ // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand
3034+ // a - b ** c;
3035+ // ^^token; leftOperand = b. Return b ** c to the caller as a rightOperand
3036+ // a ** b - c
3037+ // ^token; leftOperand = b. Return b to the caller as a rightOperand
3038+ const consumeCurrentOperator = token === SyntaxKind . AsteriskAsteriskToken ?
3039+ newPrecedence >= precedence :
3040+ newPrecedence > precedence ;
3041+
3042+ if ( ! consumeCurrentOperator ) {
30233043 break ;
30243044 }
30253045
@@ -3226,6 +3246,7 @@ namespace ts {
32263246 * 3) LeftHandSideExpression[?yield] [[no LineTerminator here]]--
32273247 * 4) ++LeftHandSideExpression[?yield]
32283248 * 5) --LeftHandSideExpression[?yield]
3249+ * In TypeScript (2), (3) are parsed as PostfixUnaryExpression. (4), (5) are parsed as PrefixUnaryExpression
32293250 */
32303251 function parseIncrementExpression ( ) : IncrementExpression {
32313252 if ( token === SyntaxKind . PlusPlusToken || token === SyntaxKind . MinusMinusToken ) {
0 commit comments