diff --git a/src/com/google/javascript/jscomp/parsing/IRFactory.java b/src/com/google/javascript/jscomp/parsing/IRFactory.java index c7adc62ab27..c55eccea433 100644 --- a/src/com/google/javascript/jscomp/parsing/IRFactory.java +++ b/src/com/google/javascript/jscomp/parsing/IRFactory.java @@ -1436,11 +1436,11 @@ Node processIfStatement(IfStatementTree statementNode) { } Node processBinaryExpression(BinaryOperatorTree exprNode) { - if (exprNode.operator.type == TokenType.STAR_STAR - || exprNode.operator.type == TokenType.STAR_STAR_EQUAL) { - maybeWarnForFeature(exprNode, Feature.EXPONENT_OP); - } if (hasPendingCommentBefore(exprNode.right)) { + if (exprNode.operator.type == TokenType.STAR_STAR + || exprNode.operator.type == TokenType.STAR_STAR_EQUAL) { + maybeWarnForFeature(exprNode, Feature.EXPONENT_OP); + } return newNode( transformBinaryTokenType(exprNode.operator.type), transform(exprNode.left), @@ -1458,6 +1458,10 @@ private Node processBinaryExpressionHelper(BinaryOperatorTree exprTree) { Node current = null; Node previous = null; while (exprTree != null) { + if (exprTree.operator.type == TokenType.STAR_STAR + || exprTree.operator.type == TokenType.STAR_STAR_EQUAL) { + maybeWarnForFeature(exprTree, Feature.EXPONENT_OP); + } previous = current; // Skip the first child but recurse normally into the right operand as typically this isn't // deep and because we have already checked that there isn't any JSDoc we can traverse diff --git a/test/com/google/javascript/jscomp/Es7ToEs6ConverterTest.java b/test/com/google/javascript/jscomp/Es7ToEs6ConverterTest.java index 03e1e683573..68e045263cc 100644 --- a/test/com/google/javascript/jscomp/Es7ToEs6ConverterTest.java +++ b/test/com/google/javascript/jscomp/Es7ToEs6ConverterTest.java @@ -53,4 +53,8 @@ public void testExponentiationOperator() { public void testExponentiationAssignmentOperator() { test("x **= 2;", "x=Math.pow(x,2)"); } + + public void testIssue2821() { + test("2 ** 3 > 0", "Math.pow(2, 3) > 0"); + } } diff --git a/test/com/google/javascript/jscomp/parsing/ParserTest.java b/test/com/google/javascript/jscomp/parsing/ParserTest.java index f6f8db41506..f63d9c6ed81 100644 --- a/test/com/google/javascript/jscomp/parsing/ParserTest.java +++ b/test/com/google/javascript/jscomp/parsing/ParserTest.java @@ -102,6 +102,8 @@ public void testExponentOperator() { parse("x**-y"); parse("x/y**z"); + parse("2 ** 3 > 3"); + mode = LanguageMode.ECMASCRIPT6; strictMode = SLOPPY; parseWarning(