* Fix workflow * Trigger * [auto] Update compiled version * [auto] Commit modules * Push Windows changes * Fix * [auto] Update compiled version * Try removing cwd * [auto] Update compiled version * Try with path module * [auto] Update compiled version * Fix path * [auto] Update compiled version * Use raw path * [auto] Update compiled version * Other path * [auto] Update compiled version * Avoid @action/exec * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * test * [auto] Update compiled version * Try with shelljs * [auto] Update compiled version * Fix my stupidity * Copy scripts to local dir * [auto] Update compiled version * Still use path * [auto] Update compiled version * Delete entrypoint.sh * [auto] Update compiled version * Make file executable * [auto] Update compiled version * Try using bash * [auto] Update compiled version
61 lines
1.6 KiB
JavaScript
61 lines
1.6 KiB
JavaScript
"use strict";
|
|
|
|
module.exports = function ({
|
|
types: t
|
|
}) {
|
|
const isVoid0 = require("babel-helper-is-void-0")(t);
|
|
|
|
return {
|
|
name: "minify-flip-comparisons",
|
|
visitor: {
|
|
// flip comparisons with a pure right hand value, this ensures
|
|
// consistency with comparisons and increases the length of
|
|
// strings that gzip can match
|
|
// typeof blah === 'function' -> 'function' === typeof blah
|
|
BinaryExpression(path) {
|
|
const node = path.node;
|
|
const right = node.right,
|
|
left = node.left; // Make sure we have a constant on the right.
|
|
|
|
if (!t.isLiteral(right) && !isVoid0(right) && !(t.isUnaryExpression(right) && t.isLiteral(right.argument)) && !t.isObjectExpression(right) && !t.isArrayExpression(right)) {
|
|
return;
|
|
} // Commutative operators.
|
|
|
|
|
|
if (t.EQUALITY_BINARY_OPERATORS.indexOf(node.operator) >= 0 || ["*", "^", "&", "|"].indexOf(node.operator) >= 0) {
|
|
node.left = right;
|
|
node.right = left;
|
|
return;
|
|
}
|
|
|
|
if (t.BOOLEAN_NUMBER_BINARY_OPERATORS.indexOf(node.operator) >= 0) {
|
|
node.left = right;
|
|
node.right = left;
|
|
let operator;
|
|
|
|
switch (node.operator) {
|
|
case ">":
|
|
operator = "<";
|
|
break;
|
|
|
|
case "<":
|
|
operator = ">";
|
|
break;
|
|
|
|
case ">=":
|
|
operator = "<=";
|
|
break;
|
|
|
|
case "<=":
|
|
operator = ">=";
|
|
break;
|
|
}
|
|
|
|
node.operator = operator;
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
};
|
|
}; |