Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix void context transform
!cond && ok() => cond || ok()
Close #45
- Loading branch information
1 parent
8f8c610
commit 569562c
Showing
9 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/* | ||
Copyright (C) 2012 Mihai Bazon <mihai.bazon@gmail.com> | ||
Copyright (C) 2012 Yusuke Suzuki <utatane.tea@gmail.com> | ||
Redistribution and use in source and binary forms, with or without | ||
|
@@ -43,13 +44,20 @@ | |
continue; | ||
} | ||
} else if (expr.type === Syntax.LogicalExpression) { | ||
if (expr.left.type === Syntax.UnaryExpression) { | ||
if (expr.left.operator === '!') { | ||
// !cond && ok() => cond || ok() | ||
modified = true; | ||
expr.left = expr.left.argument; | ||
expr.operator = (expr.operator === '||') ? '&&' : '||'; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mishoo
|
||
if (expr.left.type === Syntax.UnaryExpression && expr.left.operator === '!' && | ||
expr.right.type === Syntax.UnaryExpression && expr.right.operator === '!') { | ||
// !cond && !ok() => !(cond || ok()) | ||
// this introduces more optimizations | ||
modified = true; | ||
expr.left = expr.left.argument; | ||
expr.right = expr.right.argument; | ||
expr.operator = (expr.operator === '||') ? '&&' : '||'; | ||
expr = common.moveLocation(expr, { | ||
type: Syntax.UnaryExpression, | ||
operator: '!', | ||
argument: expr | ||
}); | ||
continue; | ||
} | ||
} else if (expr.type === Syntax.ConditionalExpression) { | ||
if (expr.test.type === Syntax.UnaryExpression && expr.test.operator === '!') { | ||
|
@@ -74,6 +82,13 @@ | |
expr = expr.argument; | ||
continue; | ||
} | ||
} else if (expr.type === Syntax.LogicalExpression) { | ||
if (expr.left.type === Syntax.UnaryExpression && expr.left.operator === '!') { | ||
// !cond && ok() => cond || ok() | ||
modified = true; | ||
expr.left = expr.left.argument; | ||
expr.operator = (expr.operator === '||') ? '&&' : '||'; | ||
} | ||
} | ||
break; | ||
} while (true); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
!ok||ok2() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Because of global environment | ||
if (!ok || ok2()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(function(){ok&&ok2()}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(function () { | ||
if (!ok || ok2()); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(function(){while(!ok||ok2())ok3()}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(function () { | ||
while (!ok || ok2()) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
ok3(); | ||
} | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(function(){while(!(ok&&ok2()))ok3()}()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// TODO(Constellation): | ||
// This transformation sometimes make script bigger size. | ||
// So we should handle it in post processing pass. | ||
(function () { | ||
while (!ok || !ok2()) { | ||
ok3(); | ||
} | ||
}()); |
@mishoo:
I took a mistake on boolean context transformation.
This transformation should be done in void context.
Thanks for your report! Your files and movies help me a lot! I added your name to copyright comment.