🐊Putout plugin adds support of minifiers used in @putout/minify and minify.
npm i @putout/plugin-putout -D
- ✅ apply-template-literal;
- ✅ apply-ternary;
- ✅ convert-array-from-to-spread;
- ✅ convert-const-to-let;
- ✅ convert-let-to-var;
- ✅ convert-if-to-logical;
- ✅ convert-return-to-sequence-expression;
- ✅ convert-strict-equal-to-equal;
- ✅ expand-bindings;
- ✅ extract-body;
- ✅ join-continued-strings;
- ✅ inline;
- ✅ mangle-names;
- ✅ merge-assignment-expressions;
- ✅ merge-loops;
- ✅ merge-variables;
- ✅ remove-return-undefined;
- ✅ remove-var-undefined;
- ✅ shorten-names;j
- ✅ simplify-floor;
- ✅ types;
{
"rules": {
"minify/apply-ternary": "on",
"minify/apply-template-literal": "on",
"minify/convert-const-to-let": "on",
"minify/convert-let-to-var": "on",
"minify/convert-if-to-logical": "on",
"minify/convert-strict-equal-to-equal": "on",
"minify/convert-array-from-to-spread": "on",
"minify/convert-return-to-sequence-expression": "on",
"minify/extract-body": "on",
"minify/expand-bindings": "on",
"minify/mangle-names": ["on", {
"mangleClassNames": true
}],
"minify/merge-assignment-expressions": "on",
"minify/merge-variables": "on",
"minify/merge-loops": "on",
"minify/remove-var-undefined": "on",
"minify/remove-return-undefined": "on",
"minify/simplify-floor": "on",
"minify/shorten-names": "on",
"minify/join-continued-strings": "on",
"minify/inline": "on",
"minify/types": "on"
}
}Check out in 🐊Putout Editor.
if (a)
b();
else
c();a ? b() : c();Not only short, but also fast:
// 34.795ms
for (let i = 0; i < 1_000_000; i++)
String(i);
// 28.302ms
for (let i = 0; i < 1_000_000; i++)
i.toString();
// 24.818ms
for (let i = 0; i < 1_000_000; i++)
`${i}`;x.toString();
String(x);String(x);Check out in 🐊Putout Editor.
if (a)
console.log('hello');
if (b) {
console.log('hello');
console.log('world');
}
if (a) {
console.log(1);
console.log(2);
} else {
console.log(3);
console.log(4);
}a && console.log('hello');
b && (console.log('hello'), console.log('world'));
a ? (console.log(1), console.log(2)) : (console.log(3), console.log(4));const a = 5;let a = 5;
Lexical declaration cannot appear in a single-statement context(c) MDN
Checkout in 🐊Putout Editor.
javascript: let a = 3;
if (5)
let b = 3;
javascript: var a = 3;
if (5)
var b = 3;Check out in 🐊Putout Editor.
() => {
d();
return 1;
};() => {
d();
return 1;
};Check out in 🐊Putout Editor.
a === b;a == b;Array
.from(a)
.map((x, i) => `${i}: ${x}`);[...a].map((x, i) => `${i}: ${x}`);Check out in 🐊Putout Editor.
if (x)
return;
const hello = () => {
return 'world';
};if (x)
return;
const hello = () => 'world';Check out in 🐊Putout Editor.
const y = 'abc';
const x = y;
const fn = require(x);
const a = 5;
const b = a;
const c = b;
fn(c);require('abc')(5);Checkout in 🐊Putout Editor.
var a = undefined;var a;const fn = () => {
if (a)
return undefined;
return undefined;
};const fn = () => {
if (a)
return;
};Check out in 🐊Putout Editor.
function generate() {
const hello = 'hi';
return hello;
}function generate() {
const a = 'hi';
return a;
}When you want to preserve class names use
{
"rules": {
"minify/mangle-names": ["on", {
"mangleClassNames": false
}]
}
}In this case you will see:
class Hello {
world() {
const hello = 'hello';
return hello;
}
}class Hello {
world() {
const a = 'hello';
return a;
}
}Check out in 🐊Putout Editor.
a = 'hello';
b = 'hello';
c = 'hello';
d = 'hello';a = b = c = d = 'hello';Check out in 🐊Putout Editor.
var a;
var b;var a, b;Check out in 🐊Putout Editor.
for (const aa of a)
d.push(aa);
for (const bb of b)
d.push(bb);for (const aa of [...a, ...b])
d.push(aa);Not only shorter, but faster:
// 5.027ms
for (let i = 0; i < 1_000_000; i++)
Math.floor(i + 0.5);
// 3.493ms
for (let i = 0; i < 1_000_000; i++)
~~(i + 0.5);Math.floor(x);~~x;Feats good to @putout/plugin-declare.
Check out in 🐊Putout Editor.
const a = (b) => {
Object.keys(b);
};
const b = (keys) => {
Object.keys(keys);
};
Object.freeze(a);
Object.defineProperty(b);const a = (b) => {
keys(b);
};
const b = (keys) => {
Object.keys(keys);
};
freeze(a);
defineProperty(b);Check out in 🐊Putout Editor.
const a = undefined;
const b = true;
const c = false;const a = void 0;
const b = !0;
const c = !1;Join continued strings to one line. Check out in 🐊Putout Editor.
console.log(`\
1\
2\
3`, '\
a\
b\
c');console.log(` 1 2 3`, ' a b c');Check out in 🐊Putout Editor.
let x = 1;
--x;
if (!x)
console.log('hello');let x = 1;
if (!--x)
console.log('hello');MIT