summaryrefslogtreecommitdiff
path: root/node_modules/babel-plugin-minify-flip-comparisons
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/babel-plugin-minify-flip-comparisons')
-rw-r--r--node_modules/babel-plugin-minify-flip-comparisons/README.md55
-rw-r--r--node_modules/babel-plugin-minify-flip-comparisons/lib/index.js61
-rw-r--r--node_modules/babel-plugin-minify-flip-comparisons/package.json17
3 files changed, 133 insertions, 0 deletions
diff --git a/node_modules/babel-plugin-minify-flip-comparisons/README.md b/node_modules/babel-plugin-minify-flip-comparisons/README.md
new file mode 100644
index 00000000..952dcd6c
--- /dev/null
+++ b/node_modules/babel-plugin-minify-flip-comparisons/README.md
@@ -0,0 +1,55 @@
+# babel-plugin-minify-flip-comparisons
+
+**Note:** while this plugin doesn’t shorten the output in any way, it does optimize it for repetition-based compression algorithms such as gzip.
+
+## Example
+
+**In**
+
+```javascript
+const foo = a === 1;
+if (bar !== null) {
+ var baz = 0;
+}
+```
+
+**Out**
+
+```javascript
+const foo = 1 === a;
+if (null !== bar) {
+ var baz = 0;
+}
+```
+
+## Installation
+
+```sh
+npm install babel-plugin-minify-flip-comparisons --save-dev
+```
+
+## Usage
+
+### Via `.babelrc` (Recommended)
+
+**.babelrc**
+
+```json
+{
+ "plugins": ["minify-flip-comparisons"]
+}
+```
+
+### Via CLI
+
+```sh
+babel --plugins minify-flip-comparisons script.js
+```
+
+### Via Node API
+
+```javascript
+require("@babel/core").transform("code", {
+ plugins: ["minify-flip-comparisons"]
+});
+```
diff --git a/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js b/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js
new file mode 100644
index 00000000..47820515
--- /dev/null
+++ b/node_modules/babel-plugin-minify-flip-comparisons/lib/index.js
@@ -0,0 +1,61 @@
+"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;
+ }
+ }
+
+ }
+ };
+}; \ No newline at end of file
diff --git a/node_modules/babel-plugin-minify-flip-comparisons/package.json b/node_modules/babel-plugin-minify-flip-comparisons/package.json
new file mode 100644
index 00000000..ba4b6c7a
--- /dev/null
+++ b/node_modules/babel-plugin-minify-flip-comparisons/package.json
@@ -0,0 +1,17 @@
+{
+ "name": "babel-plugin-minify-flip-comparisons",
+ "version": "0.4.3",
+ "description": "",
+ "keywords": [
+ "babel-plugin"
+ ],
+ "homepage": "https://github.com/babel/minify#readme",
+ "bugs": "https://github.com/babel/minify/issues",
+ "license": "MIT",
+ "author": "amasad",
+ "main": "lib/index.js",
+ "repository": "https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-flip-comparisons",
+ "dependencies": {
+ "babel-helper-is-void-0": "^0.4.3"
+ }
+}