Skip to content

Commit

Permalink
fixed files form Closure #22
Browse files Browse the repository at this point in the history
  • Loading branch information
tdurieux committed Mar 7, 2017
1 parent 551a256 commit 1633d83
Showing 1 changed file with 2 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,44 +98,20 @@ public void visit(NodeTraversal t, Node n, Node parent) {
// Do not try to remove a block or an expr result. We already handle
// these cases when we visit the child, and the peephole passes will
// fix up the tree in more clever ways when these are removed.
if (parent.getType() == Token.COMMA) {
Node gramps = parent.getParent();
if (gramps.isCall() && parent == gramps.getFirstChild()) {
if (n == parent.getFirstChild() && parent.getChildCount() == 2 && n.getNext().isName() && "eval".equals(n.getNext().getString())) {
if (n.isExprResult() || n.isBlock()) {
return;
}
}

// This no-op statement was there so that JSDoc information could
// be attached to the name. This check should not complain about it.
if (n == parent.getLastChild()) {
for (Node an : parent.getAncestors()) {
int ancestorType = an.getType();
if (ancestorType == Token.COMMA)
continue;
if (ancestorType != Token.EXPR_RESULT && ancestorType != Token.BLOCK)
return;
else
break;
}
}
} else if (parent.getType() != Token.EXPR_RESULT && parent.getType() != Token.BLOCK) {
if (parent.getType() == Token.FOR && parent.getChildCount() == 4 && (n == parent.getFirstChild() ||
n == parent.getFirstChild().getNext().getNext())) {
} else {
if (n.isQualifiedName() && n.getJSDocInfo() != null) {
return;
}
}

boolean isResultUsed = NodeUtil.isExpressionResultUsed(n);
boolean isSimpleOp = NodeUtil.isSimpleOperatorType(n.getType());
if (!isResultUsed &&
(isSimpleOp || !NodeUtil.mayHaveSideEffects(n, t.getCompiler()))) {
if (n.isQualifiedName() && n.getJSDocInfo() != null) {
return;
} else if (n.isExprResult()) {
return;
}
String msg = "This code lacks side-effects. Is there a bug?";
if (n.isString()) {
msg = "Is there a missing '+' on the previous line?";
Expand Down

0 comments on commit 1633d83

Please sign in to comment.