1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-03 12:20:04 +02:00

add some packages

This commit is contained in:
s2
2018-05-05 13:54:07 +02:00
parent 48c1138518
commit ff6e20677d
3738 changed files with 215920 additions and 0 deletions

View File

@@ -0,0 +1,55 @@
# babel-plugin-minify-flip-comparisons
**Note:** while this plugin doesnt 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
```
## 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"]
});
```

View File

@@ -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;
}
}
}
};
};

View File

@@ -0,0 +1,49 @@
{
"_from": "babel-plugin-minify-flip-comparisons@^0.4.1",
"_id": "babel-plugin-minify-flip-comparisons@0.4.1",
"_inBundle": false,
"_integrity": "sha1-5wfl2rxpXJnNKSP+lw7ZrHjE5ws=",
"_location": "/babel-plugin-minify-flip-comparisons",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "babel-plugin-minify-flip-comparisons@^0.4.1",
"name": "babel-plugin-minify-flip-comparisons",
"escapedName": "babel-plugin-minify-flip-comparisons",
"rawSpec": "^0.4.1",
"saveSpec": null,
"fetchSpec": "^0.4.1"
},
"_requiredBy": [
"/babel-preset-minify"
],
"_resolved": "https://registry.npmjs.org/babel-plugin-minify-flip-comparisons/-/babel-plugin-minify-flip-comparisons-0.4.1.tgz",
"_shasum": "e707e5dabc695c99cd2923fe970ed9ac78c4e70b",
"_spec": "babel-plugin-minify-flip-comparisons@^0.4.1",
"_where": "/home/s2/Documents/Code/minifyfromhtml/node_modules/babel-preset-minify",
"author": {
"name": "amasad"
},
"bugs": {
"url": "https://github.com/babel/minify/issues"
},
"bundleDependencies": false,
"dependencies": {
"babel-helper-is-void-0": "^0.4.1"
},
"deprecated": false,
"description": "**Note:** while this plugin doesnt shorten the output in any way, it does optimize it for repetition-based compression algorithms such as gzip.",
"homepage": "https://github.com/babel/minify#readme",
"keywords": [
"babel-plugin"
],
"license": "MIT",
"main": "lib/index.js",
"name": "babel-plugin-minify-flip-comparisons",
"repository": {
"type": "git",
"url": "https://github.com/babel/minify/tree/master/packages/babel-plugin-minify-flip-comparisons"
},
"version": "0.4.1"
}