Skip to content

Commit

Permalink
Allow cast nodes as valid operands for prefix and postfix operators.
Browse files Browse the repository at this point in the history
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162797421
  • Loading branch information
EatingW authored and brad4d committed Jul 25, 2017
1 parent c0b1733 commit b102fff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/com/google/javascript/jscomp/parsing/IRFactory.java
Expand Up @@ -1952,7 +1952,8 @@ Node processUpdateExpression(UpdateExpressionTree updateExpr) {
}

private Node createUpdateNode(Token type, boolean postfix, Node operand) {
if (!operand.isValidAssignmentTarget()) {
Node assignTarget = operand.isCast() ? operand.getFirstChild() : operand;
if (!assignTarget.isValidAssignmentTarget()) {
errorReporter.error(
SimpleFormat.format("Invalid %s %s operand.",
(postfix ? "postfix" : "prefix"),
Expand Down
2 changes: 2 additions & 0 deletions test/com/google/javascript/jscomp/parsing/ParserTest.java
Expand Up @@ -1052,6 +1052,7 @@ public void testPostfixExpression() {
parse("a++");
parse("a.b--");
parse("a[0]++");
parse("/** @type {number} */ (a)++;");

parseError("a()++", "Invalid postfix increment operand.");
parseError("(new C)--", "Invalid postfix decrement operand.");
Expand All @@ -1060,6 +1061,7 @@ public void testPostfixExpression() {
parseError("(+a)++", "Invalid postfix increment operand.");
parseError("[1,2]++", "Invalid postfix increment operand.");
parseError("'literal'++", "Invalid postfix increment operand.");
parseError("/** @type {number} */ (a())++;", "Invalid postfix increment operand.");
}

public void testUnaryExpression() {
Expand Down

0 comments on commit b102fff

Please sign in to comment.