Skip to content

Commit

Permalink
fixed files form Closure #84
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 70a7e7b commit b644546
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ Node processArrayLiteral(ArrayLiteral literalNode) {
@Override
Node processAssignment(Assignment assignmentNode) {
Node assign = processInfixExpression(assignmentNode);
Node target = assign.getFirstChild();
if (!validAssignmentTarget(target)) {
errorReporter.error(
"invalid assignment target",
sourceName,
target.getLineno(), "", 0);
}
return assign;
}

Expand Down Expand Up @@ -794,6 +801,17 @@ Node processUnaryExpression(UnaryExpression exprNode) {
operand.setDouble(-operand.getDouble());
return operand;
} else {
if (type == Token.INC || type == Token.DEC) {
if (!validAssignmentTarget(operand)) {
String msg = (type == Token.INC)
? "invalid increment target"
: "invalid decrement target";
errorReporter.error(
msg,
sourceName,
operand.getLineno(), "", 0);
}
}

Node node = newNode(type, operand);
if (exprNode.isPostfix()) {
Expand All @@ -803,6 +821,15 @@ Node processUnaryExpression(UnaryExpression exprNode) {
}
}

private boolean validAssignmentTarget(Node target) {
switch (target.getType()) {
case Token.NAME:
case Token.GETPROP:
case Token.GETELEM:
return true;
}
return false;
}

@Override
Node processVariableDeclaration(VariableDeclaration declarationNode) {
Expand Down

0 comments on commit b644546

Please sign in to comment.