Skip to content

Commit

Permalink
feature: @putout/minify: simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed May 28, 2024
1 parent c7493fd commit 58caf38
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
24 changes: 7 additions & 17 deletions lib/minify.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
import {print} from '@putout/printer';
import {parse, transform} from 'putout';
import {
getPlugins,
getAfterTransform,
getThirdPassPlugins,
getSecondPassOptions,
getThirdPassOptions,
getFirstPassOptions,
} from './plugins.js';

export const minify = (source, options) => {
const ast = parse(source, {
printer: 'putout',
});

transform(ast, source, {
rules: {
'conditions/apply-if': 'off',
'conditions/convert-equal-to-strict-equal': 'off',
'promises/add-missing-await': 'off',
},
plugins: getPlugins(options),
});
const ast = parse(source);

transform(ast, source, getAfterTransform(options));
transform(ast, source, getThirdPassPlugins(options));
transform(ast, source, getFirstPassOptions(options));
transform(ast, source, getSecondPassOptions(options));
transform(ast, source, getThirdPassOptions(options));

const code = print(ast, {
format: {
Expand Down
15 changes: 11 additions & 4 deletions lib/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const parseOptions = (options) => ({
...options,
});

export const getAfterTransform = (options) => {
export const getSecondPassOptions = (options) => {
const {
mangle,
mangleClassNames,
Expand All @@ -63,7 +63,7 @@ export const getAfterTransform = (options) => {
};
};

export const getThirdPassPlugins = (options) => {
export const getThirdPassOptions = (options) => {
const {
mangle,
mangleClassNames,
Expand All @@ -84,7 +84,7 @@ export const getThirdPassPlugins = (options) => {
};
};

export const getPlugins = (options) => {
export const getFirstPassOptions = (options) => {
const {
removeUnusedVariables,
removeConsole,
Expand Down Expand Up @@ -127,5 +127,12 @@ export const getPlugins = (options) => {
['promises', promises],
].filter(Boolean);

return plugins;
return {
rules: {
'conditions/apply-if': 'off',
'conditions/convert-equal-to-strict-equal': 'off',
'promises/add-missing-await': 'off',
},
plugins,
};
};

0 comments on commit 58caf38

Please sign in to comment.