Skip to content

Commit

Permalink
fix(simplify): fix conditional expression pattern match transformatio…
Browse files Browse the repository at this point in the history
…n logic (babel#754)
  • Loading branch information
boopathi authored Dec 11, 2017
1 parent 37064b4 commit 033d9ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions packages/babel-plugin-minify-simplify/__tests__/simplify-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
]);

Expand Down

0 comments on commit 033d9ab

Please sign in to comment.