Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Remove NOT in IfStatement with EmptyStatement (-s) #408

Merged
merged 1 commit into from

2 participants

@RGustBardon

If the only statement of a nonterminal IfStatement is a nonterminal
EmptyStatement or a nonterminal IfStatement consists of two
nonterminal EmptyStatement symbols, such a statement is transformed
into a nonterminal ExpressionStatement that consists of a
UnaryExpression with the logical NOT operator and the expression found
in the nonterminal IfStatement. The operator in question is
superfluous.

This patch omits the negation by detecting the described case earlier.

@RGustBardon RGustBardon Remove NOT in IfStatement with EmptyStatement (-s)
If the only statement of a nonterminal IfStatement is a nonterminal
EmptyStatement or a nonterminal IfStatement consists of two
nonterminal EmptyStatement symbols, such a statement is transformed
into a nonterminal ExpressionStatement that consists of a
UnaryExpression with the logical NOT operator and the expression found
in the nonterminal IfStatement.  The operator in question is
superfluous.

This patch omits the negation by detecting the described case earlier.
e90dbc9
@mishoo mishoo merged commit 4c72a63 into mishoo:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 5, 2012
  1. @RGustBardon

    Remove NOT in IfStatement with EmptyStatement (-s)

    RGustBardon authored
    If the only statement of a nonterminal IfStatement is a nonterminal
    EmptyStatement or a nonterminal IfStatement consists of two
    nonterminal EmptyStatement symbols, such a statement is transformed
    into a nonterminal ExpressionStatement that consists of a
    UnaryExpression with the logical NOT operator and the expression found
    in the nonterminal IfStatement.  The operator in question is
    superfluous.
    
    This patch omits the negation by detecting the described case earlier.
This page is out of date. Refresh to see the latest.
View
5 lib/process.js
@@ -1242,6 +1242,9 @@ function ast_squeeze(ast, options) {
t = walk(t);
e = walk(e);
+ if (empty(e) && empty(t))
+ return [ "stat", c ];
+
if (empty(t)) {
c = negate(c);
t = e;
@@ -1262,8 +1265,6 @@ function ast_squeeze(ast, options) {
}
})();
}
- if (empty(e) && empty(t))
- return [ "stat", c ];
var ret = [ "if", c, t, e ];
if (t[0] == "if" && empty(t[3]) && empty(e)) {
ret = best_of(ret, walk([ "if", [ "binary", "&&", c, t[1] ], t[2] ]));
View
1  test/unit/compress/expected/if-not.js
@@ -0,0 +1 @@
+_,_
View
1  test/unit/compress/test/if-not.js
@@ -0,0 +1 @@
+if(_);if(_);else;
Something went wrong with that request. Please try again.