diff --git a/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js b/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js index 4f1ee3689..ade42b62b 100644 --- a/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js +++ b/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js @@ -1969,6 +1969,36 @@ describe("simplify-plugin", () => { ` ); + thePlugin( + "should simplify common conditional operations 2", + ` + function h1() { return a && b ? (foo(), true) : false } + `, + ` + function h1() { + return !!(a && b) && (foo(), true); + } + ` + ); + + thePlugin( + "should fix issue#689", + ` + function foo(object, property, value) { + if (object && property) { + object[property] = value; + return true; + } + return false; + } + `, + ` + function foo(object, property, value) { + return !!(object && property) && (object[property] = value, true); + } + ` + ); + // From UglifyJS thePlugin.inEachLine( "should simplify logical expression of the following forms of && by compressing to the right", diff --git a/packages/babel-plugin-minify-simplify/src/conditional-expression.js b/packages/babel-plugin-minify-simplify/src/conditional-expression.js index deb980e17..17dfc8a84 100644 --- a/packages/babel-plugin-minify-simplify/src/conditional-expression.js +++ b/packages/babel-plugin-minify-simplify/src/conditional-expression.js @@ -31,7 +31,7 @@ module.exports = t => { [EX, EX, true, (e, c) => or(not(e), c)], - [LE, EX, false, (e, c) => and(e, c)], + [LE, EX, false, (e, c) => and(notnot(e), c)], [EX, EX, false, (e, c) => and(notnot(e), c)] ]);