Skip to content

Commit

Permalink
Make sure exponent op feature is recorded in IRFactory.java
Browse files Browse the repository at this point in the history
Fixes #2821

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=187221401
  • Loading branch information
brad4d authored and Tyler Breisacher committed Feb 28, 2018
1 parent 947a994 commit 45c4b0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/com/google/javascript/jscomp/parsing/IRFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions test/com/google/javascript/jscomp/Es7ToEs6ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
2 changes: 2 additions & 0 deletions test/com/google/javascript/jscomp/parsing/ParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ public void testExponentOperator() {
parse("x**-y");
parse("x/y**z");

parse("2 ** 3 > 3");

mode = LanguageMode.ECMASCRIPT6;
strictMode = SLOPPY;
parseWarning(
Expand Down

0 comments on commit 45c4b0b

Please sign in to comment.