Skip to content

Commit

Permalink
fix: @putout/plugin-minify: merge-loops: add
Browse files Browse the repository at this point in the history
  • Loading branch information
coderaiser committed Jan 8, 2024
1 parent bd7fdb9 commit 2f66f5f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions packages/plugin-minify/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as extractBody from './extract-body/index.js';
import * as expandBindings from './expand-bindings/index.js';
import * as mangleNames from './mangle-names/index.js';
import * as mergeVariables from './merge-variables/index.js';
import * as mergeLoops from './merge-loops/index.js';
import * as shortenNames from './shorten-names/index.js';
import * as removeVarUndefined from './remove-var-undefined/index.js';
import * as removeReturnUndefined from './remove-return-undefined/index.js';
Expand All @@ -24,6 +25,7 @@ export const rules = {
'expand-bindings': expandBindings,
'mangle-names': mangleNames,
'merge-variables': mergeVariables,
'merge-loops': mergeLoops,
'shorten-names': shortenNames,
'remove-var-undefined': removeVarUndefined,
'remove-return-undefined': removeReturnUndefined,
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-minify/lib/merge-loops/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const replace = () => ({

if (compare(next, FOR)) {
const {__b: __z} = getTemplateValues(next, FOR);

remove(next);

return createLoop({
Expand Down
10 changes: 4 additions & 6 deletions packages/plugin-minify/test/fixture/merge-loops-fix.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
(a.forEach((A) => d.push(A)), b.forEach((_) => d.push(_)));
for (const _ of [...a, ...b])
d.push(_);

b.forEach((B) => d.push(B));
b.forEach((c) => d.push(c));

for (const c of a)
d.push(c);

for (const C of b)
for (const C of [...a, ...b])
d.push(C);

0 comments on commit 2f66f5f

Please sign in to comment.