From 0b7520cea887af3e1f2a4cd1fc53d810be99585b Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 8 Jan 2024 18:16:48 +0200 Subject: [PATCH] feature: @putout/minify: add simpmlify-ternary --- README.md | 1 + lib/plugins.js | 2 ++ package.json | 4 +++- test/fixture/simplify-ternary-fix.js | 1 + test/fixture/simplify-ternary.js | 1 + test/minify.js | 5 +++++ 6 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test/fixture/simplify-ternary-fix.js create mode 100644 test/fixture/simplify-ternary.js diff --git a/README.md b/README.md index d5f4d5d..be596b9 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Here is list of supported 🐊**Putout** transformations: - ✅ [`remove-console`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-console#readme); - ✅ [`remove-debugger`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-debugger#readme); - ✅ [`remove-unreachable-code`](https://github.com/coderaiser/putout/tree/v29.0.0/packages/plugin-remove-unreachable-code#readme); +- ✅ [`simplify-ternary`](https://github.com/coderaiser/putout/tree/v34.0.0/packages/plugin-simplify-ternary#readme); - ✅ [`types`](https://github.com/coderaiser/putout/tree/v29.7.1/packages/plugin-types#readme); - ✅ [`for-of`](https://github.com/coderaiser/putout/tree/v29.7.1/packages/plugin-for-of#readme); diff --git a/lib/plugins.js b/lib/plugins.js index d6fbeeb..e3595c4 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -17,6 +17,7 @@ import removeUselessElse from '@putout/plugin-remove-useless-else'; import removeUnusedExpressions from '@putout/plugin-remove-unused-expressions'; import removeUnreferencedVariables from '@putout/plugin-remove-unreferenced-variables'; import reuseDuplicateInit from '@putout/plugin-reuse-duplicate-init'; +import simplifyTernary from '@putout/plugin-simplify-ternary'; import mergeDuplicateFunctions from '@putout/plugin-merge-duplicate-functions'; import forOf from '@putout/plugin-for-of'; import removeNestedBlocks from '@putout/plugin-remove-nested-blocks'; @@ -114,6 +115,7 @@ export const getPlugins = (options) => { ['merge-duplicate-functions', mergeDuplicateFunctions], ['minify/shorten-names', shortenNames], ['new', newPlugin], + ['simplify-ternary', simplifyTernary], ['types', types], ].filter(Boolean); diff --git a/package.json b/package.json index 1930034..cf87a67 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,9 @@ "build": "madrun build", "minify": "madrun minify" }, - "dependencies": {}, + "dependencies": { + "@putout/plugin-simplify-ternary": "^7.0.0" + }, "keywords": [ "putout", "minify", diff --git a/test/fixture/simplify-ternary-fix.js b/test/fixture/simplify-ternary-fix.js new file mode 100644 index 0000000..f57846a --- /dev/null +++ b/test/fixture/simplify-ternary-fix.js @@ -0,0 +1 @@ +x=y&&z; \ No newline at end of file diff --git a/test/fixture/simplify-ternary.js b/test/fixture/simplify-ternary.js new file mode 100644 index 0000000..feefe3b --- /dev/null +++ b/test/fixture/simplify-ternary.js @@ -0,0 +1 @@ +x = y ? z : false; \ No newline at end of file diff --git a/test/minify.js b/test/minify.js index d4f4f7c..98ad3b5 100644 --- a/test/minify.js +++ b/test/minify.js @@ -283,6 +283,11 @@ test('@putout/minify: mangle-names-overlap', (t) => { t.end(); }); +test('@putout/minify: simplify-ternary', (t) => { + t.minify('simplify-ternary'); + t.end(); +}); + test('@putout/minify: mangle: disabled', (t) => { t.minify('mangle-disabled', { mangle: false,