From 6546ad112588f8157de9b12a0540071d0f712fd6 Mon Sep 17 00:00:00 2001 From: Sylvester Aswin Date: Thu, 15 Feb 2018 21:32:53 +0100 Subject: [PATCH] Refactor test cases for minify simplily. (#799) --- .../fixtures/arrow-block-empty/actual.js | 2 + .../fixtures/arrow-block-empty/expected.js | 2 + .../__tests__/fixtures/arrow-block/actual.js | 2 + .../fixtures/arrow-block/expected.js | 2 + .../fixtures/arrow-short-hand/actual.js | 1 + .../fixtures/arrow-short-hand/expected.js | 1 + .../bail-multiple-statements/actual.js | 10 + .../bail-multiple-statements/expected.js | 8 + .../fixtures/block-to-sequence/actual.js | 4 + .../fixtures/block-to-sequence/expected.js | 1 + .../fixtures/combine-returns/actual.js | 12 + .../fixtures/combine-returns/expected.js | 3 + .../actual.js | 16 + .../expected.js | 48 + .../common-conditional-operations/actual.js | 1 + .../common-conditional-operations/expected.js | 3 + .../convert-gaurded-nots-to-ors-2/actual.js | 4 + .../convert-gaurded-nots-to-ors-2/expected.js | 1 + .../convert-gaurded-nots-to-ors/actual.js | 2 + .../convert-gaurded-nots-to-ors/expected.js | 1 + .../__tests__/fixtures/do-while/actual.js | 3 + .../__tests__/fixtures/do-while/expected.js | 1 + .../fixtures/early-return-2/actual.js | 6 + .../fixtures/early-return-2/expected.js | 4 + .../fixtures/early-returns/actual.js | 19 + .../fixtures/early-returns/expected.js | 15 + .../actual.js | 6 + .../expected.js | 8 + .../__tests__/fixtures/empty-return/actual.js | 4 + .../fixtures/empty-return/expected.js | 3 + .../fixtures/empty-vars-first/actual.js | 1 + .../fixtures/empty-vars-first/expected.js | 5 + .../flip-binary-expressions/actual.js | 1 + .../flip-binary-expressions/expected.js | 1 + .../fixtures/flip-conditionals/actual.js | 1 + .../fixtures/flip-conditionals/expected.js | 1 + .../fixtures/flip-logical-expr-2/actual.js | 1 + .../fixtures/flip-logical-expr-2/expected.js | 1 + .../fixtures/flip-logical-expr/actual.js | 2 + .../fixtures/flip-logical-expr/expected.js | 2 + .../__tests__/fixtures/for-sequence/actual.js | 5 + .../fixtures/for-sequence/expected.js | 3 + .../fixtures/handle-to-boolean-2/actual.js | 4 + .../fixtures/handle-to-boolean-2/expected.js | 3 + .../fixtures/handle-to-boolean/actual.js | 3 + .../fixtures/handle-to-boolean/expected.js | 3 + .../fixtures/handle-void-returns-2/actual.js | 9 + .../handle-void-returns-2/expected.js | 3 + .../fixtures/handle-void-returns/actual.js | 7 + .../fixtures/handle-void-returns/expected.js | 3 + .../fixtures/hoist-functions/actual.js | 5 + .../fixtures/hoist-functions/expected.js | 4 + .../__tests__/fixtures/if-break-2/actual.js | 4 + .../__tests__/fixtures/if-break-2/expected.js | 1 + .../__tests__/fixtures/if-break-3/actual.js | 8 + .../__tests__/fixtures/if-break-3/expected.js | 1 + .../__tests__/fixtures/if-break-4/actual.js | 8 + .../__tests__/fixtures/if-break-4/expected.js | 1 + .../__tests__/fixtures/if-break-5/actual.js | 10 + .../__tests__/fixtures/if-break-5/expected.js | 4 + .../__tests__/fixtures/if-break/actual.js | 3 + .../__tests__/fixtures/if-break/expected.js | 1 + .../__tests__/fixtures/if-complex/actual.js | 17 + .../__tests__/fixtures/if-complex/expected.js | 7 + .../if-conditional-return-2/actual.js | 12 + .../if-conditional-return-2/expected.js | 3 + .../if-conditional-return-3/actual.js | 6 + .../if-conditional-return-3/expected.js | 3 + .../if-conditional-return-4/actual.js | 7 + .../if-conditional-return-4/expected.js | 7 + .../fixtures/if-conditional-return/actual.js | 12 + .../if-conditional-return/expected.js | 3 + .../fixtures/if-continue-2/actual.js | 5 + .../fixtures/if-continue-2/expected.js | 1 + .../fixtures/if-continue-3/actual.js | 10 + .../fixtures/if-continue-3/expected.js | 3 + .../__tests__/fixtures/if-continue/actual.js | 4 + .../fixtures/if-continue/expected.js | 1 + .../fixtures/if-else-blocks/actual.js | 7 + .../fixtures/if-else-blocks/expected.js | 7 + .../fixtures/if-empty-blocks/actual.js | 13 + .../fixtures/if-empty-blocks/expected.js | 1 + .../__tests__/fixtures/if-return-2/actual.js | 11 + .../fixtures/if-return-2/expected.js | 7 + .../__tests__/fixtures/if-return-3/actual.js | 7 + .../fixtures/if-return-3/expected.js | 6 + .../__tests__/fixtures/if-return-4/actual.js | 7 + .../fixtures/if-return-4/expected.js | 6 + .../__tests__/fixtures/if-return-5/actual.js | 9 + .../fixtures/if-return-5/expected.js | 9 + .../__tests__/fixtures/if-return-6/actual.js | 8 + .../fixtures/if-return-6/expected.js | 5 + .../fixtures/if-return-hoisted-fn/actual.js | 9 + .../fixtures/if-return-hoisted-fn/expected.js | 9 + .../__tests__/fixtures/if-return/actual.js | 6 + .../__tests__/fixtures/if-return/expected.js | 3 + .../fixtures/if-sequence-test/actual.js | 6 + .../fixtures/if-sequence-test/expected.js | 3 + .../__tests__/fixtures/if-to-gaurds/actual.js | 3 + .../fixtures/if-to-gaurds/expected.js | 3 + .../fixtures/if-to-ternary-10/actual.js | 8 + .../fixtures/if-to-ternary-10/expected.js | 2 + .../fixtures/if-to-ternary-11/actual.js | 8 + .../fixtures/if-to-ternary-11/expected.js | 2 + .../fixtures/if-to-ternary-12/actual.js | 7 + .../fixtures/if-to-ternary-12/expected.js | 1 + .../fixtures/if-to-ternary-2/actual.js | 8 + .../fixtures/if-to-ternary-2/expected.js | 3 + .../fixtures/if-to-ternary-3/actual.js | 9 + .../fixtures/if-to-ternary-3/expected.js | 3 + .../fixtures/if-to-ternary-4/actual.js | 8 + .../fixtures/if-to-ternary-4/expected.js | 3 + .../fixtures/if-to-ternary-5/actual.js | 7 + .../fixtures/if-to-ternary-5/expected.js | 3 + .../fixtures/if-to-ternary-6/actual.js | 7 + .../fixtures/if-to-ternary-6/expected.js | 3 + .../fixtures/if-to-ternary-7/actual.js | 7 + .../fixtures/if-to-ternary-7/expected.js | 3 + .../fixtures/if-to-ternary-8/actual.js | 22 + .../fixtures/if-to-ternary-8/expected.js | 4 + .../fixtures/if-to-ternary-9/actual.js | 8 + .../fixtures/if-to-ternary-9/expected.js | 2 + .../actual.js | 7 + .../expected.js | 1 + .../actual.js | 5 + .../expected.js | 1 + .../actual.js | 7 + .../expected.js | 1 + .../fixtures/if-to-ternary-return-2/actual.js | 12 + .../if-to-ternary-return-2/expected.js | 3 + .../fixtures/if-to-ternary/actual.js | 4 + .../fixtures/if-to-ternary/expected.js | 3 + .../fixtures/iife-to-unary/actual.js | 6 + .../fixtures/iife-to-unary/expected.js | 5 + .../__tests__/fixtures/iife-to-unary/skip | 0 .../__tests__/fixtures/issue-115/actual.js | 4 + .../__tests__/fixtures/issue-115/expected.js | 3 + .../__tests__/fixtures/issue-198/actual.js | 8 + .../__tests__/fixtures/issue-198/expected.js | 8 + .../__tests__/fixtures/issue-208/actual.js | 5 + .../__tests__/fixtures/issue-208/expected.js | 4 + .../__tests__/fixtures/issue-281/actual.js | 6 + .../__tests__/fixtures/issue-281/expected.js | 4 + .../__tests__/fixtures/issue-423/actual.js | 11 + .../__tests__/fixtures/issue-423/expected.js | 3 + .../__tests__/fixtures/issue-455/actual.js | 7 + .../__tests__/fixtures/issue-455/expected.js | 9 + .../__tests__/fixtures/issue-560/actual.js | 6 + .../__tests__/fixtures/issue-560/expected.js | 6 + .../__tests__/fixtures/issue-637/actual.js | 9 + .../__tests__/fixtures/issue-637/expected.js | 7 + .../__tests__/fixtures/issue-689/actual.js | 7 + .../__tests__/fixtures/issue-689/expected.js | 3 + .../fixtures/keep-directives/actual.js | 4 + .../fixtures/keep-directives/expected.js | 5 + .../__tests__/fixtures/merge-if-2/actual.js | 8 + .../__tests__/fixtures/merge-if-2/expected.js | 7 + .../__tests__/fixtures/merge-if-3/actual.js | 5 + .../__tests__/fixtures/merge-if-3/expected.js | 3 + .../__tests__/fixtures/merge-if-4/actual.js | 7 + .../__tests__/fixtures/merge-if-4/expected.js | 3 + .../__tests__/fixtures/merge-if-5/actual.js | 13 + .../__tests__/fixtures/merge-if-5/expected.js | 3 + .../__tests__/fixtures/merge-if/actual.js | 5 + .../__tests__/fixtures/merge-if/expected.js | 1 + .../__tests__/fixtures/merge-return/actual.js | 5 + .../fixtures/merge-return/expected.js | 3 + .../fixtures/merge-to-for-init-2/actual.js | 5 + .../fixtures/merge-to-for-init-2/expected.js | 3 + .../fixtures/merge-to-for-init/actual.js | 5 + .../fixtures/merge-to-for-init/expected.js | 3 + .../fixtures/remove-block-2/actual.js | 5 + .../fixtures/remove-block-2/expected.js | 3 + .../__tests__/fixtures/remove-block/actual.js | 11 + .../fixtures/remove-block/expected.js | 3 + .../fixtures/remove-fn-expr-parens/actual.js | 1 + .../remove-fn-expr-parens/expected.js | 1 + .../fixtures/remove-for-block/actual.js | 3 + .../fixtures/remove-for-block/expected.js | 1 + .../fixtures/return-inside-loop/actual.js | 10 + .../fixtures/return-inside-loop/expected.js | 6 + .../fixtures/super-assignments/actual.js | 5 + .../fixtures/super-assignments/expected.js | 5 + .../switch-expr-last-break-2/actual.js | 10 + .../switch-expr-last-break-2/expected.js | 9 + .../fixtures/switch-expr-last-break/actual.js | 8 + .../switch-expr-last-break/expected.js | 8 + .../switch-expr-sequence-test/actual.js | 8 + .../switch-expr-sequence-test/expected.js | 7 + .../switch-expr-to-sequence/actual.js | 12 + .../switch-expr-to-sequence/expected.js | 11 + .../switch-expr-to-ternary-2/actual.js | 12 + .../switch-expr-to-ternary-2/expected.js | 3 + .../switch-expr-to-ternary-3/actual.js | 11 + .../switch-expr-to-ternary-3/expected.js | 3 + .../switch-expr-to-ternary-break-2/actual.js | 17 + .../expected.js | 3 + .../switch-expr-to-ternary-break/actual.js | 17 + .../switch-expr-to-ternary-break/expected.js | 3 + .../actual.js | 12 + .../expected.js | 3 + .../actual.js | 17 + .../expected.js | 3 + .../fixtures/switch-expr-to-ternary/actual.js | 13 + .../switch-expr-to-ternary/expected.js | 3 + .../template-literals-assignments/actual.js | 1 + .../template-literals-assignments/expected.js | 1 + .../fixtures/throw-seq-expr/actual.js | 4 + .../fixtures/throw-seq-expr/expected.js | 3 + .../fixtures/to-sequence-expr-2/actual.js | 6 + .../fixtures/to-sequence-expr-2/expected.js | 6 + .../fixtures/to-sequence-expr/actual.js | 18 + .../fixtures/to-sequence-expr/expected.js | 18 + .../fixtures/to-sequence-return-2/actual.js | 10 + .../fixtures/to-sequence-return-2/expected.js | 9 + .../fixtures/to-sequence-return/actual.js | 5 + .../fixtures/to-sequence-return/expected.js | 3 + .../__tests__/fixtures/to-sequence/actual.js | 9 + .../fixtures/to-sequence/expected.js | 7 + .../fixtures/unary-conditional-2/actual.js | 1 + .../fixtures/unary-conditional-2/expected.js | 1 + .../fixtures/unary-conditional/actual.js | 1 + .../fixtures/unary-conditional/expected.js | 1 + .../fixtures/unary-sequence/actual.js | 1 + .../fixtures/unary-sequence/expected.js | 1 + .../fixtures/whiles-to-fors-2/actual.js | 6 + .../fixtures/whiles-to-fors-2/expected.js | 3 + .../fixtures/whiles-to-fors-3/actual.js | 7 + .../fixtures/whiles-to-fors-3/expected.js | 5 + .../fixtures/whiles-to-fors/actual.js | 5 + .../fixtures/whiles-to-fors/expected.js | 3 + .../__tests__/index.js | 2 + .../__tests__/simplify-test.js | 2236 +---------------- 233 files changed, 1321 insertions(+), 2228 deletions(-) create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/skip create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/actual.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/expected.js create mode 100644 packages/babel-plugin-minify-simplify/__tests__/index.js diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/actual.js new file mode 100644 index 000000000..f768fd836 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/actual.js @@ -0,0 +1,2 @@ +const a = () => {}; +const b = () => {return;}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/expected.js new file mode 100644 index 000000000..34ef9cd09 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block-empty/expected.js @@ -0,0 +1,2 @@ +const a = () => {}; +const b = () => {}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/actual.js new file mode 100644 index 000000000..62fabc84e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/actual.js @@ -0,0 +1,2 @@ +const a = () => {return (3, 4);}; +const b = () => {return 3;}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/expected.js new file mode 100644 index 000000000..d6cdea725 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-block/expected.js @@ -0,0 +1,2 @@ +const a = () => (3, 4); +const b = () => 3; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/actual.js new file mode 100644 index 000000000..9b0c41fe4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/actual.js @@ -0,0 +1 @@ +const f = () => a; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/expected.js new file mode 100644 index 000000000..9b0c41fe4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/arrow-short-hand/expected.js @@ -0,0 +1 @@ +const f = () => a; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/actual.js new file mode 100644 index 000000000..3c3b52d0f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/actual.js @@ -0,0 +1,10 @@ +function foo() { + if(window.self != window.top) { + if(__DEV__) { + console.log('lol', name); + } + return; + } + lol(); + try { lol() } catch (e) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/expected.js new file mode 100644 index 000000000..3ab62cb62 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/bail-multiple-statements/expected.js @@ -0,0 +1,8 @@ +function foo() { + if (window.self != window.top) return void (__DEV__ && console.log('lol', name)); + lol(); + + try { + lol(); + } catch (e) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/actual.js new file mode 100644 index 000000000..42f0903dc --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/actual.js @@ -0,0 +1,4 @@ +for (var x = 0; x < 10; x++) { + console.log(x); + console.log(x); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/expected.js new file mode 100644 index 000000000..951dc51f7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/block-to-sequence/expected.js @@ -0,0 +1 @@ +for (var x = 0; x < 10; x++) console.log(x), console.log(x); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/actual.js new file mode 100644 index 000000000..7c0a950db --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/actual.js @@ -0,0 +1,12 @@ +function foo() { + if (a) { + if (a.b) { + if(a.b.c) { + if(a.b.c()){ + return; + } + } + } + } + for (; true;) wat(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/expected.js new file mode 100644 index 000000000..94a9b0e91 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/combine-returns/expected.js @@ -0,0 +1,3 @@ +function foo() { + if (!(a && a.b && a.b.c && a.b.c())) for (; true;) wat(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/actual.js new file mode 100644 index 000000000..b32830de2 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/actual.js @@ -0,0 +1,16 @@ +function f1() { return a == b ? true : x; } +function f2() { return a == b ? false : x; } +function f3() { return a < b ? !0 : x; } +function f4() { return a < b ? !1 : x; } +function f5() { return c ? !0 : x; } +function f6() { return c ? false : x; } +function f7() { return !c ? true : x; } +function f8() { return !c ? !1 : x; } +function g1() { return a == b ? x : true; } +function g2() { return a == b ? x : false; } +function g3() { return a < b ? x : !0; } +function g4() { return a < b ? x : !1; } +function g5() { return c ? x : true; } +function g6() { return c ? x : !1; } +function g7() { return !c ? x : !0; } +function g8() { return !c ? x : false; } \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/expected.js new file mode 100644 index 000000000..31f7f67f5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-expression-patterns/expected.js @@ -0,0 +1,48 @@ +function f1() { + return !(a != b) || x; +} +function f2() { + return a != b && x; +} +function f3() { + return !!(a < b) || x; +} +function f4() { + return !(a < b) && x; +} +function f5() { + return !!c || x; +} +function f6() { + return !c && x; +} +function f7() { + return !c || x; +} +function f8() { + return !!c && x; +} +function g1() { + return a != b || x; +} +function g2() { + return !(a != b) && x; +} +function g3() { + return !(a < b) || x; +} +function g4() { + return !!(a < b) && x; +} +function g5() { + return !c || x; +} +function g6() { + return !!c && x; +} +function g7() { + return !!c || x; +} +function g8() { + return !c && x; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/actual.js new file mode 100644 index 000000000..e19faa9b4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/actual.js @@ -0,0 +1 @@ +function h1() { return a && b ? (foo(), true) : false } \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/expected.js new file mode 100644 index 000000000..133976fb9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/common-conditional-operations/expected.js @@ -0,0 +1,3 @@ +function h1() { + return !!(a && b) && (foo(), true); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/actual.js new file mode 100644 index 000000000..95d1a829b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/actual.js @@ -0,0 +1,4 @@ +if (!foo && foo !== bar) { + wow(); + such(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/expected.js new file mode 100644 index 000000000..6c0ed13d1 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors-2/expected.js @@ -0,0 +1 @@ +!foo && foo !== bar && (wow(), such()); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/actual.js new file mode 100644 index 000000000..19c987540 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/actual.js @@ -0,0 +1,2 @@ +x(); +if (!foo.bar) foo.bar = wat; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/expected.js new file mode 100644 index 000000000..990719c24 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/convert-gaurded-nots-to-ors/expected.js @@ -0,0 +1 @@ +x(), !foo.bar && (foo.bar = wat); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/actual.js new file mode 100644 index 000000000..1e8664198 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/actual.js @@ -0,0 +1,3 @@ +do { + foo(); +} while (1); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/expected.js new file mode 100644 index 000000000..b159bf8b3 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/do-while/expected.js @@ -0,0 +1 @@ +do foo(); while (1); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/actual.js new file mode 100644 index 000000000..f7f4e69a8 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/actual.js @@ -0,0 +1,6 @@ +function foo() { + wow(); + if (x) { + return; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/expected.js new file mode 100644 index 000000000..7340ba31f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-return-2/expected.js @@ -0,0 +1,4 @@ +function foo() { + wow(); + x; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/actual.js new file mode 100644 index 000000000..6c4bbaec0 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/actual.js @@ -0,0 +1,19 @@ +function foo(a) { + if (lol) return; + doThings(); + doOtherThings(); +} +function bar(a) { + if (lol) { + return; + } + try { + doThings(); + } catch (e) { + doOtherThings(); + } +} +function baz() { + while (wow) if (lol) return; + boo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/expected.js new file mode 100644 index 000000000..084aa9c39 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/early-returns/expected.js @@ -0,0 +1,15 @@ +function foo(a) { + lol || (doThings(), doOtherThings()); +} +function bar(a) { + if (!lol) try { + doThings(); + } catch (e) { + doOtherThings(); + } +} +function baz() { + for (; wow;) if (lol) return; + + boo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/actual.js new file mode 100644 index 000000000..bd4079352 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/actual.js @@ -0,0 +1,6 @@ +function foo() { + for (i in p) {} + for (; ;) {} + switch(1) {} + try { a } catch(e) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/expected.js new file mode 100644 index 000000000..756add0a3 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-blocks-to-empty-statements/expected.js @@ -0,0 +1,8 @@ +function foo() { + for (i in p); + for (;;); + switch (1) {} + try { + a; + } catch (e) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/actual.js new file mode 100644 index 000000000..0dc63acae --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/actual.js @@ -0,0 +1,4 @@ +function foo() { + lol(); + return; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/expected.js new file mode 100644 index 000000000..80da67d88 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-return/expected.js @@ -0,0 +1,3 @@ +function foo() { + lol(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/actual.js new file mode 100644 index 000000000..1cf5a511d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/actual.js @@ -0,0 +1 @@ +var x = 1, y, z = 2, zx, a; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/expected.js new file mode 100644 index 000000000..adb1f26e4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/empty-vars-first/expected.js @@ -0,0 +1,5 @@ +var y, + zx, + a, + x = 1, + z = 2; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/actual.js new file mode 100644 index 000000000..d291eba53 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/actual.js @@ -0,0 +1 @@ +if (!(!a && b == a && !b && b < a)) for(;;) a(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/expected.js new file mode 100644 index 000000000..260b81a50 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-binary-expressions/expected.js @@ -0,0 +1 @@ +if (a || b != a || b || !(b < a)) for (;;) a(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/actual.js new file mode 100644 index 000000000..ebf50dcba --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/actual.js @@ -0,0 +1 @@ +!foo ? 'foo' : 'bar'; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/expected.js new file mode 100644 index 000000000..676221ae7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-conditionals/expected.js @@ -0,0 +1 @@ +foo ? 'bar' : 'foo'; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/actual.js new file mode 100644 index 000000000..d23bd015f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/actual.js @@ -0,0 +1 @@ +if (!(1 !== foo || !bar)) for (;;); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/expected.js new file mode 100644 index 000000000..796e6c0b7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr-2/expected.js @@ -0,0 +1 @@ +if (1 === foo && bar) for (;;); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/actual.js new file mode 100644 index 000000000..bfa5e3e1f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/actual.js @@ -0,0 +1,2 @@ +!x && foo(); +if (!(null == r)) for (;;); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/expected.js new file mode 100644 index 000000000..a17fecaa0 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/flip-logical-expr/expected.js @@ -0,0 +1,2 @@ + +if (!x && foo(), null != r) for (;;); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/actual.js new file mode 100644 index 000000000..b747012bc --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/actual.js @@ -0,0 +1,5 @@ +function foo() { + x = 1; + a(); + for (var a in b) wow(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/expected.js new file mode 100644 index 000000000..e3c0da60a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/for-sequence/expected.js @@ -0,0 +1,3 @@ +function foo() { + for (var a in x = 1, a(), b) wow(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/actual.js new file mode 100644 index 000000000..2493be00c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/actual.js @@ -0,0 +1,4 @@ +function x(a, b) { + a = a || b; + return b === a || !a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/expected.js new file mode 100644 index 000000000..7dc04a95b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean-2/expected.js @@ -0,0 +1,3 @@ +function x(a, b) { + return a = a || b, b === a || !a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/actual.js new file mode 100644 index 000000000..c5c194d1b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/actual.js @@ -0,0 +1,3 @@ +function x(a) { + return !!a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/expected.js new file mode 100644 index 000000000..c5c194d1b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-to-boolean/expected.js @@ -0,0 +1,3 @@ +function x(a) { + return !!a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/actual.js new file mode 100644 index 000000000..8936e2644 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/actual.js @@ -0,0 +1,9 @@ +function foo(a) { + if (a && a.b != null) { + if ((a.c--) === 1) { + return; + } + return a.b; + } + return bar(a); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/expected.js new file mode 100644 index 000000000..3531cf519 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns-2/expected.js @@ -0,0 +1,3 @@ +function foo(a) { + return a && a.b != null ? a.c-- === 1 ? void 0 : a.b : bar(a); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/actual.js new file mode 100644 index 000000000..02cfa0f49 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (a) { + return; + } + + return wow; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/expected.js new file mode 100644 index 000000000..41e5dc129 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/handle-void-returns/expected.js @@ -0,0 +1,3 @@ +function foo() { + return a ? void 0 : wow; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/actual.js new file mode 100644 index 000000000..26c21cbb5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/actual.js @@ -0,0 +1,5 @@ +function foo() { + a(); + function bar() {} + b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/expected.js new file mode 100644 index 000000000..38be96a2f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/hoist-functions/expected.js @@ -0,0 +1,4 @@ +function foo() { + function bar() {} + a(), b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/actual.js new file mode 100644 index 000000000..c5cb9ab02 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/actual.js @@ -0,0 +1,4 @@ +for (i = 1; i <= j; i++) { + foo(); + if (bar) break; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/expected.js new file mode 100644 index 000000000..409205000 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-2/expected.js @@ -0,0 +1 @@ +for (i = 1; i <= j && (foo(), !bar); i++); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/actual.js new file mode 100644 index 000000000..27cb340f2 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/actual.js @@ -0,0 +1,8 @@ +for (i = 1; i <= j; i++) { + if (bar) { + break; + } else { + wat(); + if (x) throw 1 + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/expected.js new file mode 100644 index 000000000..8ece8bc2a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-3/expected.js @@ -0,0 +1 @@ +for (i = 1; i <= j && !bar; i++) if (wat(), x) throw 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/actual.js new file mode 100644 index 000000000..82b3e3280 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/actual.js @@ -0,0 +1,8 @@ +for (i = 1; i <= j; i++) { + if (bar) { + wat(); + if (x) throw 1; + } else { + break; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/expected.js new file mode 100644 index 000000000..471c119d9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-4/expected.js @@ -0,0 +1 @@ +for (i = 1; i <= j && !!bar; i++) if (wat(), x) throw 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/actual.js new file mode 100644 index 000000000..90ca40ded --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/actual.js @@ -0,0 +1,10 @@ +for (i = 1; i <= j; i++) { + foo(); + if (bar) { + break; + } else { + wat(); + if (x) throw 1 + } + hi(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/expected.js new file mode 100644 index 000000000..7000a0174 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break-5/expected.js @@ -0,0 +1,4 @@ +for (i = 1; i <= j && (foo(), !bar); i++) { + if (wat(), x) throw 1; + hi(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/actual.js new file mode 100644 index 000000000..c29956729 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/actual.js @@ -0,0 +1,3 @@ +for (i = 1; i <= j; i++) { + if (bar) break; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/expected.js new file mode 100644 index 000000000..7f0c4dd2f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-break/expected.js @@ -0,0 +1 @@ +for (i = 1; i <= j && !bar; i++); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/actual.js new file mode 100644 index 000000000..555d2b6ab --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/actual.js @@ -0,0 +1,17 @@ +function foo(a) { + if (a && a.b != null) { + if ((a.c--) === 1) { + delete a.c; + } + return a.b; + } + return bar(a); +} + +function foo2(a) { + if (a) { + return a.b; + } else { + return bar(a); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/expected.js new file mode 100644 index 000000000..273b609ba --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-complex/expected.js @@ -0,0 +1,7 @@ +function foo(a) { + return a && a.b != null ? (a.c-- === 1 && delete a.c, a.b) : bar(a); +} + +function foo2(a) { + return a ? a.b : bar(a); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/actual.js new file mode 100644 index 000000000..da2eddcde --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/actual.js @@ -0,0 +1,12 @@ +function foo() { + if (x) { + delete x.x; + if (bar()) return 2; + } + + if (bar) { + x(); + } else { + y(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/expected.js new file mode 100644 index 000000000..1fa7aef9b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-2/expected.js @@ -0,0 +1,3 @@ +function foo() { + return x && (delete x.x, bar()) ? 2 : void (bar ? x() : y()); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/actual.js new file mode 100644 index 000000000..dacbb77ca --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/actual.js @@ -0,0 +1,6 @@ +function foo() { + if (x) { + delete x.x; + if (bar()) return; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/expected.js new file mode 100644 index 000000000..d4c218465 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-3/expected.js @@ -0,0 +1,3 @@ +function foo() { + x && (delete x.x, bar()); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/actual.js new file mode 100644 index 000000000..ca7ad3cd5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (x) { + var f = wow; + delete x.x; + if (bar()) return; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/expected.js new file mode 100644 index 000000000..35d6cffd4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return-4/expected.js @@ -0,0 +1,7 @@ +function foo() { + if (x) { + var f = wow; + + if (delete x.x, bar()) return; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/actual.js new file mode 100644 index 000000000..fb14de5a9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/actual.js @@ -0,0 +1,12 @@ +function foo() { + if (x) { + delete x.x; + if (bar()) return; + } + + if (bar) { + x(); + } else { + y(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/expected.js new file mode 100644 index 000000000..05759a75b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-conditional-return/expected.js @@ -0,0 +1,3 @@ +function foo() { + x && (delete x.x, bar()) || (bar ? x() : y()); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/actual.js new file mode 100644 index 000000000..843629f97 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/actual.js @@ -0,0 +1,5 @@ +for (;;) { + a = b; + if (!foo) continue; + bar = foo; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/expected.js new file mode 100644 index 000000000..15e649ff9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-2/expected.js @@ -0,0 +1 @@ +for (;;) a = b, foo && (bar = foo); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/actual.js new file mode 100644 index 000000000..6efce2124 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/actual.js @@ -0,0 +1,10 @@ +function wow() { + for(;;) { + if (foo) { + if (bar) { + continue; + } + } + wat(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/expected.js new file mode 100644 index 000000000..68756b501 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue-3/expected.js @@ -0,0 +1,3 @@ +function wow() { + for (;;) foo && bar || wat(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/actual.js new file mode 100644 index 000000000..4a20c2b67 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/actual.js @@ -0,0 +1,4 @@ +for (var p in foo) { + if (p) continue; + bar(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/expected.js new file mode 100644 index 000000000..b22ad0ec2 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-continue/expected.js @@ -0,0 +1 @@ +for (var p in foo) p || bar(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/actual.js new file mode 100644 index 000000000..a90a948a9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/actual.js @@ -0,0 +1,7 @@ +if (false) { + let { a } = foo(); +} else if (true) { + const x = bar(); +} else { + function baz() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/expected.js new file mode 100644 index 000000000..a90a948a9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-else-blocks/expected.js @@ -0,0 +1,7 @@ +if (false) { + let { a } = foo(); +} else if (true) { + const x = bar(); +} else { + function baz() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/actual.js new file mode 100644 index 000000000..7c45d3135 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/actual.js @@ -0,0 +1,13 @@ +if (a) { +} else { + foo(); +} + +if (a) { + foo(); +} else if (b) { +} + +if (a) { +} else { +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/expected.js new file mode 100644 index 000000000..276a54207 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-empty-blocks/expected.js @@ -0,0 +1 @@ +a || foo(), a ? foo() : b, a; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/actual.js new file mode 100644 index 000000000..90e949f99 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/actual.js @@ -0,0 +1,11 @@ +function foo() { + if (foo) { + if (bar) { + return false; + } + if (baz) { + return false; + } + } + return true; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/expected.js new file mode 100644 index 000000000..b72d76d15 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-2/expected.js @@ -0,0 +1,7 @@ +function foo() { + if (foo) { + if (bar) return false; + if (baz) return false; + } + return true; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/actual.js new file mode 100644 index 000000000..a7af0b284 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/actual.js @@ -0,0 +1,7 @@ +function x() { + for (;;) { + x(); + if (foo) return 1; + else y(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/expected.js new file mode 100644 index 000000000..5d5711354 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-3/expected.js @@ -0,0 +1,6 @@ +function x() { + for (;;) { + if (x(), foo) return 1; + y(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/actual.js new file mode 100644 index 000000000..91226f4b4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/actual.js @@ -0,0 +1,7 @@ +function x() { + if (!bar) return; + var x = foo; + if (!foo) return + if (y) + throw y; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/expected.js new file mode 100644 index 000000000..1568d86d8 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-4/expected.js @@ -0,0 +1,6 @@ +function x() { + if (bar) { + var x = foo; + if (foo && y) throw y; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/actual.js new file mode 100644 index 000000000..8d33d87ee --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/actual.js @@ -0,0 +1,9 @@ +function x() { + var x = foo; + if (hi) { + var y = z; + if (!foo) return; + if (x) throw y; + } + x(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/expected.js new file mode 100644 index 000000000..8d33d87ee --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-5/expected.js @@ -0,0 +1,9 @@ +function x() { + var x = foo; + if (hi) { + var y = z; + if (!foo) return; + if (x) throw y; + } + x(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/actual.js new file mode 100644 index 000000000..5b27562e5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/actual.js @@ -0,0 +1,8 @@ +function foo() { + if (a) { + if (x) return; + else return x; + } + const b = 1; + return "doesn't matter if this is reached or not"; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/expected.js new file mode 100644 index 000000000..e9856a37d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-6/expected.js @@ -0,0 +1,5 @@ +function foo() { + if (a) return x ? void 0 : x; + const b = 1; + return "doesn't matter if this is reached or not"; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/actual.js new file mode 100644 index 000000000..9803e87d4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/actual.js @@ -0,0 +1,9 @@ +function foo() { + bar(); + if(x) return; + const {a}=b; + function bar () { + baz(); + bar(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/expected.js new file mode 100644 index 000000000..dcc00c881 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return-hoisted-fn/expected.js @@ -0,0 +1,9 @@ +function foo() { + function bar() { + baz(), bar(); + } + + if (bar(), !x) { + const { a } = b; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/actual.js new file mode 100644 index 000000000..2bcfaba08 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/actual.js @@ -0,0 +1,6 @@ +function foo() { + if (x) { + delete x.x; + if (bar()) return x; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/expected.js new file mode 100644 index 000000000..9da5d639c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-return/expected.js @@ -0,0 +1,3 @@ +function foo() { + if (x && (delete x.x, bar())) return x; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/actual.js new file mode 100644 index 000000000..c9b62773c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/actual.js @@ -0,0 +1,6 @@ +function bar() { + wow(); + if (foo) { + throw x(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/expected.js new file mode 100644 index 000000000..6c0b0beeb --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-sequence-test/expected.js @@ -0,0 +1,3 @@ +function bar() { + if (wow(), foo) throw x(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/actual.js new file mode 100644 index 000000000..e6cc1c159 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/actual.js @@ -0,0 +1,3 @@ +function foo() { + if (x) a(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/expected.js new file mode 100644 index 000000000..f6bae1ce5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-gaurds/expected.js @@ -0,0 +1,3 @@ +function foo() { + x && a(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/actual.js new file mode 100644 index 000000000..285ab30ee --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/actual.js @@ -0,0 +1,8 @@ +var x; +if (a) { + x = foo; +} else if (b) { + x = bar; +} else { + y = baz; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/expected.js new file mode 100644 index 000000000..433aa7913 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-10/expected.js @@ -0,0 +1,2 @@ +var x; +a ? x = foo : b ? x = bar : y = baz; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/actual.js new file mode 100644 index 000000000..58cb84103 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/actual.js @@ -0,0 +1,8 @@ +var x; +if (a) { + x = foo; +} else if (b) { + x = bar; +} else { + baz(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/expected.js new file mode 100644 index 000000000..dec2dbb83 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-11/expected.js @@ -0,0 +1,2 @@ +var x; +a ? x = foo : b ? x = bar : baz(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/actual.js new file mode 100644 index 000000000..65064de0c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/actual.js @@ -0,0 +1,7 @@ +if (a) { + x.b = foo; +} else if (b) { + x.b = bar; +} else { + x.b = baz; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/expected.js new file mode 100644 index 000000000..a34d6234d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-12/expected.js @@ -0,0 +1 @@ +x.b = a ? foo : b ? bar : baz; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/actual.js new file mode 100644 index 000000000..53e251974 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/actual.js @@ -0,0 +1,8 @@ +function foo() { + if (1) { + return 2; + } else { + lol(1); + lol(2); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/expected.js new file mode 100644 index 000000000..113430884 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-2/expected.js @@ -0,0 +1,3 @@ +function foo() { + return 1 ? 2 : void (lol(1), lol(2)); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/actual.js new file mode 100644 index 000000000..09036200a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/actual.js @@ -0,0 +1,9 @@ +function foo() { + if(window.self != window.top) { + if(__DEV__) { + console.log('lol', name); + } + return; + } + lol(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/expected.js new file mode 100644 index 000000000..e9184addf --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-3/expected.js @@ -0,0 +1,3 @@ +function foo() { + return window.self == window.top ? void lol() : void (__DEV__ && console.log('lol', name)); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/actual.js new file mode 100644 index 000000000..3c3416d16 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/actual.js @@ -0,0 +1,8 @@ +function foo() { + if (b) { + return foo; + } else { + a(); + b(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/expected.js new file mode 100644 index 000000000..06072bc50 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-4/expected.js @@ -0,0 +1,3 @@ +function foo() { + return b ? foo : void (a(), b()); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/actual.js new file mode 100644 index 000000000..1d6d6bfdc --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (b) { + foo(); + } else { + return bar; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/expected.js new file mode 100644 index 000000000..24ff8e982 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-5/expected.js @@ -0,0 +1,3 @@ +function foo() { + return b ? void foo() : bar; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/actual.js new file mode 100644 index 000000000..5644e9ad1 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (b) { + foo(); + } else { + return; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/expected.js new file mode 100644 index 000000000..d7d36d031 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-6/expected.js @@ -0,0 +1,3 @@ +function foo() { + b && foo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/actual.js new file mode 100644 index 000000000..17c458c79 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (b) { + return; + } else { + foo(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/expected.js new file mode 100644 index 000000000..57871f0f1 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-7/expected.js @@ -0,0 +1,3 @@ +function foo() { + b || foo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/actual.js new file mode 100644 index 000000000..40f77ad08 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/actual.js @@ -0,0 +1,22 @@ +function lawl() { + var a = 1; + if (b) { + return c; + } + + if (a) { + bar(); + return; + } + + if (d) { + if (g) { + this['s'] = morebutts; + return wat; + } + return boo; + } + + haha(); + return butts; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/expected.js new file mode 100644 index 000000000..b7d8bab7d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-8/expected.js @@ -0,0 +1,4 @@ +function lawl() { + var a = 1; + return b ? c : a ? void bar() : d ? g ? (this['s'] = morebutts, wat) : boo : (haha(), butts); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/actual.js new file mode 100644 index 000000000..0e55be40e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/actual.js @@ -0,0 +1,8 @@ +var x; +if (a) { + x = foo; +} else if (b) { + x = bar; +} else { + x = baz; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/expected.js new file mode 100644 index 000000000..8ac672d52 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-9/expected.js @@ -0,0 +1,2 @@ +var x; +x = a ? foo : b ? bar : baz; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/actual.js new file mode 100644 index 000000000..417fb8a25 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/actual.js @@ -0,0 +1,7 @@ +if (a) { + x.b += foo; +} else if (b) { + x.b -= bar; +} else { + x.b += baz; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/expected.js new file mode 100644 index 000000000..9582d9ca7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-2/expected.js @@ -0,0 +1 @@ +a ? x.b += foo : b ? x.b -= bar : x.b += baz; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/actual.js new file mode 100644 index 000000000..e285eff40 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/actual.js @@ -0,0 +1,5 @@ +if (a) { + this.a = 1; +} else { + this.b = 2; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/expected.js new file mode 100644 index 000000000..b44c03716 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator-3/expected.js @@ -0,0 +1 @@ +a ? this.a = 1 : this.b = 2; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/actual.js new file mode 100644 index 000000000..bda1d87da --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/actual.js @@ -0,0 +1,7 @@ +if (a) { + x.b += foo; +} else if (b) { + x.b += bar; +} else { + x.b += baz; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/expected.js new file mode 100644 index 000000000..f28700aac --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-assignment-operator/expected.js @@ -0,0 +1 @@ +x.b += a ? foo : b ? bar : baz; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/actual.js new file mode 100644 index 000000000..27d749e25 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/actual.js @@ -0,0 +1,12 @@ +function foo() { + if (foo) { + bar(foo); + return foo; + } else if (baz) { + bar(baz); + return baz; + } else if (wat) { + bar(wat); + return wat; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/expected.js new file mode 100644 index 000000000..937bee0de --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary-return-2/expected.js @@ -0,0 +1,3 @@ +function foo() { + return foo ? (bar(foo), foo) : baz ? (bar(baz), baz) : wat ? (bar(wat), wat) : void 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/actual.js new file mode 100644 index 000000000..f77e310db --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/actual.js @@ -0,0 +1,4 @@ +function foo() { + if (x) a(); + else b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/expected.js new file mode 100644 index 000000000..4c589d514 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/if-to-ternary/expected.js @@ -0,0 +1,3 @@ +function foo() { + x ? a() : b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/actual.js new file mode 100644 index 000000000..8d3f5ea18 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/actual.js @@ -0,0 +1,6 @@ +(function() { + x(); +})(); +y = function () { + x(); +}(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/expected.js new file mode 100644 index 000000000..1483ff09c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/expected.js @@ -0,0 +1,5 @@ +!function () { + x(); +}(), y = function () { + x(); +}(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/skip b/packages/babel-plugin-minify-simplify/__tests__/fixtures/iife-to-unary/skip new file mode 100644 index 000000000..e69de29bb diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/actual.js new file mode 100644 index 000000000..4c1ebedb3 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/actual.js @@ -0,0 +1,4 @@ +(function () { + a = x ? true : false; + c = 1 ? (this.get(x), a = b, true) : (foo.bar, false); +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/expected.js new file mode 100644 index 000000000..9dd4597ed --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-115/expected.js @@ -0,0 +1,3 @@ +(function () { + a = !!x, c = 1 ? (this.get(x), a = b, true) : (foo.bar, false); +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/actual.js new file mode 100644 index 000000000..a3fa6eeac --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/actual.js @@ -0,0 +1,8 @@ +function foo() { + let a, + { b } = x; + while (true) { + bar(a, b); + } + return [a, b]; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/expected.js new file mode 100644 index 000000000..8a14b13e4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-198/expected.js @@ -0,0 +1,8 @@ +function foo() { + let a, + { b } = x; + + for (; true;) bar(a, b); + + return [a, b]; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/actual.js new file mode 100644 index 000000000..18fc4b635 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/actual.js @@ -0,0 +1,5 @@ +!function () { + var x; + { } + alert(x); +}() \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/expected.js new file mode 100644 index 000000000..7b283eb6e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-208/expected.js @@ -0,0 +1,4 @@ +!function () { + var x; + alert(x); +}(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/actual.js new file mode 100644 index 000000000..d4876ffea --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/actual.js @@ -0,0 +1,6 @@ +function foo() { + if (x) + return; + function bar() {} + bar(a); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/expected.js new file mode 100644 index 000000000..928868cd7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-281/expected.js @@ -0,0 +1,4 @@ +function foo() { + function bar() {} + x || bar(a); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/actual.js new file mode 100644 index 000000000..c085935d3 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/actual.js @@ -0,0 +1,11 @@ +function foo(bar) { + switch (bar) { + case 'a': + return 1; + case 'b': + default: + return 4; + case 'c': + return 3; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/expected.js new file mode 100644 index 000000000..94c76105f --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-423/expected.js @@ -0,0 +1,3 @@ +function foo(bar) { + return bar === 'a' ? 1 : bar === 'c' ? 3 : 4; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/actual.js new file mode 100644 index 000000000..8c91cc0cb --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/actual.js @@ -0,0 +1,7 @@ +function foo(param) { + if (param === null) return; + let thingA = param.a; + let thingB = param.b; + if (!thingA && !thingB) return; + let thingC = param.c; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/expected.js new file mode 100644 index 000000000..8fd7d74bb --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-455/expected.js @@ -0,0 +1,9 @@ +function foo(param) { + if (param !== null) { + let thingA = param.a; + let thingB = param.b; + if (thingA || thingB) { + let thingC = param.c; + } + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/actual.js new file mode 100644 index 000000000..2add8c987 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/actual.js @@ -0,0 +1,6 @@ +function foo() { + while (true) { + const {x} = a; + const {y} = b; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/expected.js new file mode 100644 index 000000000..19b81c12a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-560/expected.js @@ -0,0 +1,6 @@ +function foo() { + for (; true;) { + const { x } = a; + const { y } = b; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/actual.js new file mode 100644 index 000000000..08a36c594 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/actual.js @@ -0,0 +1,9 @@ +function test(a) { + const clash = () => {}; + if (a) { + return clash(); + } else { + const clash = () => {}; + return clash(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/expected.js new file mode 100644 index 000000000..d3ec1b882 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-637/expected.js @@ -0,0 +1,7 @@ +function test(a) { + const clash = () => {}; + if (a) return clash();else { + const clash = () => {}; + return clash(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/actual.js new file mode 100644 index 000000000..89f3155a6 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/actual.js @@ -0,0 +1,7 @@ +function foo(object, property, value) { + if (object && property) { + object[property] = value; + return true; + } + return false; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/expected.js new file mode 100644 index 000000000..9f0a20972 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/issue-689/expected.js @@ -0,0 +1,3 @@ +function foo(object, property, value) { + return !!(object && property) && (object[property] = value, true); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/actual.js new file mode 100644 index 000000000..95cbbf932 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/actual.js @@ -0,0 +1,4 @@ +function a() { + 'use strict'; + foo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/expected.js new file mode 100644 index 000000000..10faa5195 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/keep-directives/expected.js @@ -0,0 +1,5 @@ +function a() { + 'use strict'; + + foo(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/actual.js new file mode 100644 index 000000000..e9b2edc6d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/actual.js @@ -0,0 +1,8 @@ +// FIXME: for some reason, the inner `if` statement gets indented 4 spaces. +` + function foo() { + if (a) { + if (b()) return false; + } else if (c()) return true; + } + ` \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/expected.js new file mode 100644 index 000000000..5f93aa5ae --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-2/expected.js @@ -0,0 +1,7 @@ +` + function foo() { + if (a) { + if (b()) return false; + } else if (c()) return true; + } + `; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/actual.js new file mode 100644 index 000000000..609193ddd --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/actual.js @@ -0,0 +1,5 @@ +function foo() { + if (a) return b; + if (c) return d; + return e; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/expected.js new file mode 100644 index 000000000..f1c16162e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-3/expected.js @@ -0,0 +1,3 @@ +function foo() { + return a ? b : c ? d : e; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/actual.js new file mode 100644 index 000000000..bfafc5fce --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/actual.js @@ -0,0 +1,7 @@ +function foo() { + if (bar) return; + if (far) return; + if (faz) return; + + return e; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/expected.js new file mode 100644 index 000000000..f77b44841 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-4/expected.js @@ -0,0 +1,3 @@ +function foo() { + return bar || far || faz ? void 0 : e; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/actual.js new file mode 100644 index 000000000..ae2b48170 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/actual.js @@ -0,0 +1,13 @@ +if (x) { + try { + foo(); + } catch (e) {} +} else if (y) { + if (a) { + bar(); + } else if (b) { + baz(); + } else { + for (;;) 1; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/expected.js new file mode 100644 index 000000000..b0a295026 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if-5/expected.js @@ -0,0 +1,3 @@ +if (x) try { + foo(); + } catch (e) {} else if (y) if (a) bar();else if (b) baz();else for (;;) 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/actual.js new file mode 100644 index 000000000..322df8e30 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/actual.js @@ -0,0 +1,5 @@ +if (a) { + if (b) { + throw 'wow'; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/expected.js new file mode 100644 index 000000000..d7b2171d4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-if/expected.js @@ -0,0 +1 @@ +if (a && b) throw 'wow'; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/actual.js new file mode 100644 index 000000000..8d75ccf0a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/actual.js @@ -0,0 +1,5 @@ +function foo() { + if (a) return b; + c = d; + return z; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/expected.js new file mode 100644 index 000000000..5cb5110f1 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-return/expected.js @@ -0,0 +1,3 @@ +function foo() { + return a ? b : (c = d, z); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/actual.js new file mode 100644 index 000000000..73c11cd68 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/actual.js @@ -0,0 +1,5 @@ +function foo() { + x(); + y(); + for (z(); i < 10; i++) z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/expected.js new file mode 100644 index 000000000..62bcaa0cb --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init-2/expected.js @@ -0,0 +1,3 @@ +function foo() { + for (x(), y(), z(); i < 10; i++) z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/actual.js new file mode 100644 index 000000000..07361b35a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/actual.js @@ -0,0 +1,5 @@ +function foo() { + x(); + y(); + for (; i < 10; i++) z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/expected.js new file mode 100644 index 000000000..40d868a82 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/merge-to-for-init/expected.js @@ -0,0 +1,3 @@ +function foo() { + for (x(), y(); i < 10; i++) z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/actual.js new file mode 100644 index 000000000..b5d446ff9 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/actual.js @@ -0,0 +1,5 @@ +function x() { + if (a) { + if (b) for (;;) wow(); + } else c(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/expected.js new file mode 100644 index 000000000..eed9fd8f7 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block-2/expected.js @@ -0,0 +1,3 @@ +function x() { + if (!a) c();else if (b) for (;;) wow(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/actual.js new file mode 100644 index 000000000..eca76412b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/actual.js @@ -0,0 +1,11 @@ +function x() { + if (a) { + if (b) { + for(;;) { + if (a) b(); + } + } + } else { + wat(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/expected.js new file mode 100644 index 000000000..56fdfba73 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-block/expected.js @@ -0,0 +1,3 @@ +function x() { + if (!a) wat();else if (b) for (;;) a && b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/actual.js new file mode 100644 index 000000000..e13383bdb --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/actual.js @@ -0,0 +1 @@ +x, (function() {})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/expected.js new file mode 100644 index 000000000..500f824d5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-fn-expr-parens/expected.js @@ -0,0 +1 @@ +x, function () {}(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/actual.js new file mode 100644 index 000000000..c1a1e30e1 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/actual.js @@ -0,0 +1,3 @@ +for (var x = 0; x < 10; x++) { + console.log(x); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/expected.js new file mode 100644 index 000000000..c2d37c43b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/remove-for-block/expected.js @@ -0,0 +1 @@ +for (var x = 0; x < 10; x++) console.log(x); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/actual.js new file mode 100644 index 000000000..a4d23b9bc --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/actual.js @@ -0,0 +1,10 @@ +function foo() { + while(1) { + if (a === null) { + b(); + return; + } + a(); + b(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/expected.js new file mode 100644 index 000000000..e7c8d026b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/return-inside-loop/expected.js @@ -0,0 +1,6 @@ +function foo() { + for (; 1;) { + if (a === null) return void b(); + a(), b(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/actual.js new file mode 100644 index 000000000..92903584c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/actual.js @@ -0,0 +1,5 @@ +class Foo { + foo() { + super.foo = super.foo + 1; + } +}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/expected.js new file mode 100644 index 000000000..4c8311604 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/super-assignments/expected.js @@ -0,0 +1,5 @@ +class Foo { + foo() { + ++super.foo; + } +}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/actual.js new file mode 100644 index 000000000..315d542da --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/actual.js @@ -0,0 +1,10 @@ +loop: while (foo) { + switch (bar) { + case 47: + break; + } + switch (baz) { + default: + break loop; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/expected.js new file mode 100644 index 000000000..d7a4cda0d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break-2/expected.js @@ -0,0 +1,9 @@ +loop: for (; foo;) { + switch (bar) { + case 47: + } + switch (baz) { + default: + break loop; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/actual.js new file mode 100644 index 000000000..0871043fe --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/actual.js @@ -0,0 +1,8 @@ +switch (foo) { + case 'foo': + throw bar(); + break; + case 'bar': + wow(); + break; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/expected.js new file mode 100644 index 000000000..9d76b97dc --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-last-break/expected.js @@ -0,0 +1,8 @@ +switch (foo) { + case 'foo': + throw bar(); + break; + case 'bar': + wow(); + +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/actual.js new file mode 100644 index 000000000..5b909d57e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/actual.js @@ -0,0 +1,8 @@ +function bar() { + wow(); + switch (foo) { + case 'foo': + throw x(); + break; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/expected.js new file mode 100644 index 000000000..d1b16729d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-sequence-test/expected.js @@ -0,0 +1,7 @@ +function bar() { + switch (wow(), foo) { + case 'foo': + throw x(); + + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/actual.js new file mode 100644 index 000000000..b8544171d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/actual.js @@ -0,0 +1,12 @@ +function bar() { + switch (foo) { + case 'foo': + bar(); + foo(); + break; + case 'bar': + wow(); + return wo; + break; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/expected.js new file mode 100644 index 000000000..589ad3712 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-sequence/expected.js @@ -0,0 +1,11 @@ +function bar() { + switch (foo) { + case 'foo': + bar(), foo(); + + break; + case 'bar': + return wow(), wo; + + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/actual.js new file mode 100644 index 000000000..765bac8dd --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/actual.js @@ -0,0 +1,12 @@ +function bar() { + switch (foo) { + case 'foo': + return 1; + case foo.bar: + return 2; + case wow: + wow(); + return 3; + } + return 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/expected.js new file mode 100644 index 000000000..f4b5fe717 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-2/expected.js @@ -0,0 +1,3 @@ +function bar() { + return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/actual.js new file mode 100644 index 000000000..100eb59c8 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/actual.js @@ -0,0 +1,11 @@ +function bar() { + switch (foo) { + case 'foo': + return 1; + case foo.bar: + return 2; + case wow: + wow(); + return 3; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/expected.js new file mode 100644 index 000000000..a34bfa8ae --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-3/expected.js @@ -0,0 +1,3 @@ +function bar() { + return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : void 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/actual.js new file mode 100644 index 000000000..e6ce2ed53 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/actual.js @@ -0,0 +1,17 @@ +function bar() { + switch (foo) { + case 'foo': + foo(); + break; + case foo.bar: + wow(); + wat(); + break; + case shh: + case wow: + baa(); + break; + default: + meh(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/expected.js new file mode 100644 index 000000000..03b9878be --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break-2/expected.js @@ -0,0 +1,3 @@ +function bar() { + foo === 'foo' ? foo() : foo === foo.bar ? (wow(), wat()) : foo === shh || foo === wow ? baa() : meh(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/actual.js new file mode 100644 index 000000000..e6ce2ed53 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/actual.js @@ -0,0 +1,17 @@ +function bar() { + switch (foo) { + case 'foo': + foo(); + break; + case foo.bar: + wow(); + wat(); + break; + case shh: + case wow: + baa(); + break; + default: + meh(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/expected.js new file mode 100644 index 000000000..03b9878be --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-break/expected.js @@ -0,0 +1,3 @@ +function bar() { + foo === 'foo' ? foo() : foo === foo.bar ? (wow(), wat()) : foo === shh || foo === wow ? baa() : meh(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/actual.js new file mode 100644 index 000000000..0a806a424 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/actual.js @@ -0,0 +1,12 @@ +function foo(bar) { + switch (bar) { + case 'a': + case 'b': + return 1; + case 'd': + default: + return 4; + case 'c': + return 3; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/expected.js new file mode 100644 index 000000000..7b770914a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough-2/expected.js @@ -0,0 +1,3 @@ +function foo(bar) { + return bar === 'a' || bar === 'b' ? 1 : bar === 'c' ? 3 : 4; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/actual.js new file mode 100644 index 000000000..b4d2b691a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/actual.js @@ -0,0 +1,17 @@ +function bar() { + switch (foo) { + case 'foo': + return 1; + case foo.bar: + case wow: + wow(); + return 3; + case boo: + return 4; + case baz: + case wat: + return 5; + default: + return 0; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/expected.js new file mode 100644 index 000000000..94606785b --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary-fallthrough/expected.js @@ -0,0 +1,3 @@ +function bar() { + return foo === 'foo' ? 1 : foo === foo.bar || foo === wow ? (wow(), 3) : foo === boo ? 4 : foo === baz || foo === wat ? 5 : 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/actual.js new file mode 100644 index 000000000..268a75695 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/actual.js @@ -0,0 +1,13 @@ +function bar() { + switch (foo) { + case 'foo': + return 1; + case foo.bar: + return 2; + case wow: + wow(); + return 3; + default: + return 0; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/expected.js new file mode 100644 index 000000000..f4b5fe717 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/switch-expr-to-ternary/expected.js @@ -0,0 +1,3 @@ +function bar() { + return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/actual.js new file mode 100644 index 000000000..2e5499be6 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/actual.js @@ -0,0 +1 @@ +foo[`x`] = foo[`x`] + 1; diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/expected.js new file mode 100644 index 000000000..c4fb29ba5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/template-literals-assignments/expected.js @@ -0,0 +1 @@ +foo[`x`] = foo[`x`] + 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/actual.js new file mode 100644 index 000000000..5adad63d5 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/actual.js @@ -0,0 +1,4 @@ +function x() { + z(); + throw y; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/expected.js new file mode 100644 index 000000000..87ae1d0a2 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/throw-seq-expr/expected.js @@ -0,0 +1,3 @@ +function x() { + throw z(), y; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/actual.js new file mode 100644 index 000000000..dc6f50793 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/actual.js @@ -0,0 +1,6 @@ +function bar() { + var z; + c(); + for (z in { a: 1}) x(z); + z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/expected.js new file mode 100644 index 000000000..79c2b7656 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr-2/expected.js @@ -0,0 +1,6 @@ +function bar() { + var z; + + for (z in c(), { a: 1 }) x(z); + z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/actual.js new file mode 100644 index 000000000..ce9a2ed2a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/actual.js @@ -0,0 +1,18 @@ +function foo() { + a(); + var x = bar(); + b(x); + this.d = x; +} +function bar() { + x(); + while (x) { + if (x) x(); + } + try { y(); } catch (e) {} + var z = x(); + z(); + while (a) b(); + c(); + z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/expected.js new file mode 100644 index 000000000..602a2a928 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-expr/expected.js @@ -0,0 +1,18 @@ +function foo() { + a(); + + var x = bar(); + b(x), this.d = x; +} +function bar() { + for (x(); x;) x && x(); + + try { + y(); + } catch (e) {} + var z = x(); + + for (z(); a;) b(); + + c(), z(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/actual.js new file mode 100644 index 000000000..bd0abd152 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/actual.js @@ -0,0 +1,10 @@ +function foo() { + try { + x(); + } catch (e) { + 1; + } + + y(); + return 1; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/expected.js new file mode 100644 index 000000000..b9ba266af --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return-2/expected.js @@ -0,0 +1,9 @@ +function foo() { + try { + x(); + } catch (e) { + 1; + } + + return y(), 1; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/actual.js new file mode 100644 index 000000000..2de9a968d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/actual.js @@ -0,0 +1,5 @@ +function foo() { + y(); + x(); + return 1; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/expected.js new file mode 100644 index 000000000..29524a6f8 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence-return/expected.js @@ -0,0 +1,3 @@ +function foo() { + return y(), x(), 1; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/actual.js new file mode 100644 index 000000000..88d15dd0c --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/actual.js @@ -0,0 +1,9 @@ +x(); +y(); +for (var x = 0; x < 10; x++) { + var z = foo(); + console.log(z); + console.log(z); +} +a(); +b = 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/expected.js new file mode 100644 index 000000000..61fc6a21a --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/to-sequence/expected.js @@ -0,0 +1,7 @@ +x(), y(); + +for (var x = 0; x < 10; x++) { + var z = foo(); + console.log(z), console.log(z); +} +a(), b = 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/actual.js new file mode 100644 index 000000000..cd065277e --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/actual.js @@ -0,0 +1 @@ +!(!a && b) ? b : c \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/expected.js new file mode 100644 index 000000000..1fa9e73bf --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional-2/expected.js @@ -0,0 +1 @@ +!a && b ? c : b; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/actual.js new file mode 100644 index 000000000..39dfb3f38 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/actual.js @@ -0,0 +1 @@ +!(a ? b : c); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/expected.js new file mode 100644 index 000000000..8d6812036 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-conditional/expected.js @@ -0,0 +1 @@ +a ? !b : !c; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/actual.js new file mode 100644 index 000000000..b5e774c92 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/actual.js @@ -0,0 +1 @@ +!(a, b, c); \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/expected.js new file mode 100644 index 000000000..69d7f06d4 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/unary-sequence/expected.js @@ -0,0 +1 @@ +a, b, !c; \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/actual.js new file mode 100644 index 000000000..a88c2a086 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/actual.js @@ -0,0 +1,6 @@ +function foo() { + let bar = baz; + while(true) { + bar(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/expected.js new file mode 100644 index 000000000..fec1e0a0d --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-2/expected.js @@ -0,0 +1,3 @@ +function foo() { + for (let bar = baz; true;) bar(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/actual.js new file mode 100644 index 000000000..143b6e6bd --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/actual.js @@ -0,0 +1,7 @@ +function foo() { + var a = 1; + while (true) { + bar(a); + } + return a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/expected.js new file mode 100644 index 000000000..676a59fdf --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors-3/expected.js @@ -0,0 +1,5 @@ +function foo() { + for (var a = 1; true;) bar(a); + + return a; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/actual.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/actual.js new file mode 100644 index 000000000..03f317164 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/actual.js @@ -0,0 +1,5 @@ +function foo(a) { + while(true) { + bar(); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/expected.js b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/expected.js new file mode 100644 index 000000000..de262d054 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/fixtures/whiles-to-fors/expected.js @@ -0,0 +1,3 @@ +function foo(a) { + for (; true;) bar(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-simplify/__tests__/index.js b/packages/babel-plugin-minify-simplify/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-simplify/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js b/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js index ade42b62b..e37c27b70 100644 --- a/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js +++ b/packages/babel-plugin-minify-simplify/__tests__/simplify-test.js @@ -39,1964 +39,23 @@ const thePlugin = require("test-transform")(plugin); describe("simplify-plugin", () => { thePlugin( - "should flip conditionals", - ` - !foo ? 'foo' : 'bar'; - `, - ` - foo ? 'bar' : 'foo'; - ` - ); - - thePlugin( - "should turn a for loop block to a single statement", - ` - for (var x = 0; x < 10; x++) { - console.log(x); - } - `, - ` - for (var x = 0; x < 10; x++) console.log(x); - ` - ); - - thePlugin( - "should turn block statements into a comma expression", - ` - for (var x = 0; x < 10; x++) { - console.log(x); - console.log(x); - } - `, - ` - for (var x = 0; x < 10; x++) console.log(x), console.log(x); - ` - ); - - thePlugin( - "should merge lines of code into one comma expression where possible", - ` - x(); - y(); - for (var x = 0; x < 10; x++) { - var z = foo(); - console.log(z); - console.log(z); - } - a(); - b = 1; - `, - ` - x(), y(); - - for (var x = 0; x < 10; x++) { - var z = foo(); - console.log(z), console.log(z); - } - a(), b = 1; - ` - ); - - thePlugin( - "should turn `if` statements into gaurded expressions", - ` - function foo() { - if (x) a(); - } - `, - ` - function foo() { - x && a(); - } - ` - ); - - thePlugin( - "should turn if statements into a ternary", - ` - function foo() { - if (x) a(); - else b(); - } - `, - ` - function foo() { - x ? a() : b(); - } - ` - ); - - thePlugin( - "should minify complex `if` statements", - ` - function foo(a) { - if (a && a.b != null) { - if ((a.c--) === 1) { - delete a.c; - } - return a.b; - } - return bar(a); - } - - function foo2(a) { - if (a) { - return a.b; - } else { - return bar(a); - } - } - `, - ` - function foo(a) { - return a && a.b != null ? (a.c-- === 1 && delete a.c, a.b) : bar(a); - } - - function foo2(a) { - return a ? a.b : bar(a); - } - ` - ); - - thePlugin.skip( - "should convert (function () {...})() into !function () {}()", - ` - (function() { - x(); - })(); - y = function () { - x(); - }(); - `, - ` - !function () { - x(); - }(), y = function () { - x(); - }(); - ` - ); - - thePlugin( - "should remove the `else` block if there is an early return", - ` - function foo() { - if (1) { - return 2; - } else { - lol(1); - lol(2); - } - } - `, - ` - function foo() { - return 1 ? 2 : void (lol(1), lol(2)); - } - ` - ); - - thePlugin( - "should merge expressions into a comma expression in a `return` statement", - ` - function foo() { - y(); - x(); - return 1; - } - `, - ` - function foo() { - return y(), x(), 1; - } - ` - ); - - thePlugin( - "should merge blocks into a `return` statement with a comma expression", - ` - function foo() { - try { - x(); - } catch (e) { - 1; - } - - y(); - return 1; - } - `, - ` - function foo() { - try { - x(); - } catch (e) { - 1; - } - - return y(), 1; - } - ` - ); - - // https://github.com/babel/minify/issues/208 - thePlugin( - "should not regresson #208 by handling empty blocks when merging lines into sequences", - ` - !function () { - var x; - { } - alert(x); - }() - `, - ` - !function () { - var x; - alert(x); - }(); - ` - ); - - thePlugin( - "should merge expressions into the init part of a `for` loop", - ` - function foo() { - x(); - y(); - for (; i < 10; i++) z(); - } - `, - ` - function foo() { - for (x(), y(); i < 10; i++) z(); - } - ` - ); - - thePlugin( - "should merge statements into the init part of a `for` loop even when there are other expressions there", - ` - function foo() { - x(); - y(); - for (z(); i < 10; i++) z(); - } - `, - ` - function foo() { - for (x(), y(), z(); i < 10; i++) z(); - } - ` - ); - - thePlugin( - "should remove empty `return` statements", - ` - function foo() { - lol(); - return; - } - `, - ` - function foo() { - lol(); - } - ` - ); - - thePlugin( - "should merge if statements with following expressions using void", - ` - function foo() { - if(window.self != window.top) { - if(__DEV__) { - console.log('lol', name); - } - return; - } - lol(); - } - `, - ` - function foo() { - return window.self == window.top ? void lol() : void (__DEV__ && console.log('lol', name)); - } - ` - ); - - thePlugin( - "should not try to merge `if` when there are multiple statements to follow", - ` - function foo() { - if(window.self != window.top) { - if(__DEV__) { - console.log('lol', name); - } - return; - } - lol(); - try { lol() } catch (e) {} - } - `, - ` - function foo() { - if (window.self != window.top) return void (__DEV__ && console.log('lol', name)); - lol(); - - try { - lol(); - } catch (e) {} - } - ` - ); - - thePlugin( - "should handle missing return arg when merging if statements", - ` - function foo() { - if (a) { - return; - } - - return wow; - } - `, - ` - function foo() { - return a ? void 0 : wow; - } - ` - ); - - thePlugin( - "should handle returns with no args", - ` - function foo(a) { - if (a && a.b != null) { - if ((a.c--) === 1) { - return; - } - return a.b; - } - return bar(a); - } - `, - ` - function foo(a) { - return a && a.b != null ? a.c-- === 1 ? void 0 : a.b : bar(a); - } - ` - ); - - thePlugin( - "should convert whiles to fors", - ` - function foo(a) { - while(true) { - bar(); - } - } - `, - ` - function foo(a) { - for (; true;) bar(); - } - ` - ); - - thePlugin( - "should convert whiles to fors and merge vars", - ` - function foo() { - let bar = baz; - while(true) { - bar(); - } - } - `, - ` - function foo() { - for (let bar = baz; true;) bar(); - } - ` - ); - - // https://github.com/babel/minify/issues/198 - thePlugin( - "should convert while->for and NOT merge let/const if any is refereced outside the loop", - ` - function foo() { - let a, - { b } = x; - while (true) { - bar(a, b); - } - return [a, b]; - } - `, - ` - function foo() { - let a, - { b } = x; - - for (; true;) bar(a, b); - - return [a, b]; - } - ` - ); - - thePlugin( - "should convert while->for and merge var even if any is refereced outside the loop", - ` - function foo() { - var a = 1; - while (true) { - bar(a); - } - return a; - } - `, - ` - function foo() { - for (var a = 1; true;) bar(a); - - return a; - } - ` - ); - - thePlugin( - "should combine returns", - ` - function foo() { - if (a) { - if (a.b) { - if(a.b.c) { - if(a.b.c()){ - return; - } - } - } - } - for (; true;) wat(); - } - `, - ` - function foo() { - if (!(a && a.b && a.b.c && a.b.c())) for (; true;) wat(); - } - ` - ); - - thePlugin( - "should convert early returns to negated if blocks", - ` - function foo(a) { - if (lol) return; - doThings(); - doOtherThings(); - } - function bar(a) { - if (lol) { - return; - } - try { - doThings(); - } catch (e) { - doOtherThings(); - } - } - function baz() { - while (wow) if (lol) return; - boo(); - } - `, - ` - function foo(a) { - lol || (doThings(), doOtherThings()); - } - function bar(a) { - if (!lol) try { - doThings(); - } catch (e) { - doOtherThings(); - } - } - function baz() { - for (; wow;) if (lol) return; - - boo(); - } - ` - ); - - thePlugin( - "should remove early return when no other statements", - ` - function foo() { - wow(); - if (x) { - return; - } - } - `, - ` - function foo() { - wow(); - x; - } - ` - ); - - thePlugin( - "earlyReturnTransform: it shouldn't error on shorthand arrow functions", - ` - const f = () => a; - `, - ` - const f = () => a; - ` - ); - - // TODO merge var z into the init part of for. - thePlugin( - "should merge function blocks into sequence expressions", - ` - function foo() { - a(); - var x = bar(); - b(x); - this.d = x; - } - function bar() { - x(); - while (x) { - if (x) x(); - } - try { y(); } catch (e) {} - var z = x(); - z(); - while (a) b(); - c(); - z(); - } - `, - ` - function foo() { - a(); - - var x = bar(); - b(x), this.d = x; - } - function bar() { - for (x(); x;) x && x(); - - try { - y(); - } catch (e) {} - var z = x(); - - for (z(); a;) b(); - - c(), z(); - } - ` - ); - - thePlugin( - "should merge function blocks into sequence expressions (part 2)", - ` - function bar() { - var z; - c(); - for (z in { a: 1}) x(z); - z(); - } - `, - ` - function bar() { - var z; - - for (z in c(), { a: 1 }) x(z); - z(); - } - ` - ); - - thePlugin( - "should merge if statements when there is no alternate", - ` - if (a) { - if (b) { - throw 'wow'; - } - } - `, - ` - if (a && b) throw 'wow'; - ` - ); - - thePlugin( - "should not merge if statements if changes semantics", - // FIXME: for some reason, the inner `if` statement gets indented 4 spaces. - ` - function foo() { - if (a) { - if (b()) return false; - } else if (c()) return true; - } - ` - ); - - thePlugin( - "should merge if/return statements", - ` - function foo() { - if (a) return b; - if (c) return d; - return e; - } - `, - ` - function foo() { - return a ? b : c ? d : e; - } - ` - ); - - thePlugin( - "should merge if/return statements 2", - ` - function foo() { - if (bar) return; - if (far) return; - if (faz) return; -1 - return e; - } - `, - ` - function foo() { - return bar || far || faz ? void 0 : e; - } - ` - ); - - thePlugin( - "should merge return statements with expression in between", - ` - function foo() { - if (a) return b; - c = d; - return z; - } - `, - ` - function foo() { - return a ? b : (c = d, z); - } - ` - ); - - thePlugin( - "should hoist functions", - ` - function foo() { - a(); - function bar() {} - b(); - } - `, - ` - function foo() { - function bar() {} - a(), b(); - } - ` - ); - - thePlugin( - "should not return inside a loop", - ` - function foo() { - while(1) { - if (a === null) { - b(); - return; - } - a(); - b(); - } - } - `, - ` - function foo() { - for (; 1;) { - if (a === null) return void b(); - a(), b(); - } - } - ` - ); - - thePlugin( - "should make if with one return into a conditional", - ` - function foo() { - if (b) { - return foo; - } else { - a(); - b(); - } - } - `, - ` - function foo() { - return b ? foo : void (a(), b()); - } - ` - ); - - thePlugin( - "should make if with one return into a conditional 2", - ` - function foo() { - if (b) { - foo(); - } else { - return bar; - } - } - `, - ` - function foo() { - return b ? void foo() : bar; - } - ` - ); - - thePlugin( - "should make if with one return into a conditional 3", - ` - function foo() { - if (b) { - foo(); - } else { - return; - } - } - `, - ` - function foo() { - b && foo(); - } - ` - ); - - thePlugin( - "should make if with one return into a conditional 4", - ` - function foo() { - if (b) { - return; - } else { - foo(); - } - } - `, - ` - function foo() { - b || foo(); - } - ` - ); - - thePlugin( - "should not merge if", - ` - if (x) { - try { - foo(); - } catch (e) {} - } else if (y) { - if (a) { - bar(); - } else if (b) { - baz(); - } else { - for (;;) 1; - } - } - `, - ` - if (x) try { - foo(); - } catch (e) {} else if (y) if (a) bar();else if (b) baz();else for (;;) 1; - ` - ); - - it("should merge expressions into if statements test"); - it("should understand continue statements"); - - thePlugin( - "should handle do while statements", - ` - do { - foo(); - } while (1); - `, - ` - do foo(); while (1); - ` - ); - - thePlugin( - "should handle multiple interplays of if statements and returns", - ` - function lawl() { - var a = 1; - if (b) { - return c; - } - - if (a) { - bar(); - return; - } - - if (d) { - if (g) { - this['s'] = morebutts; - return wat; - } - return boo; - } - - haha(); - return butts; - } - `, - ` - function lawl() { - var a = 1; - return b ? c : a ? void bar() : d ? g ? (this['s'] = morebutts, wat) : boo : (haha(), butts); - } - ` - ); - - thePlugin( - "should handle empty blocks in if statements", - ` - if (a) { - } else { - foo(); - } - - if (a) { - foo(); - } else if (b) { - } - - if (a) { - } else { - } - `, - ` - a || foo(), a ? foo() : b, a; - ` - ); - - thePlugin( - "re-arrange conditionals for assignment", - ` - var x; - if (a) { - x = foo; - } else if (b) { - x = bar; - } else { - x = baz; - } - `, - ` - var x; - x = a ? foo : b ? bar : baz; - ` - ); - - thePlugin( - "should bail on re-arranging conditionals for assignment", - ` - var x; - if (a) { - x = foo; - } else if (b) { - x = bar; - } else { - y = baz; - } - `, - ` - var x; - a ? x = foo : b ? x = bar : y = baz; - ` - ); - - thePlugin( - "should bail on re-arranging conditionals for assignment", - ` - var x; - if (a) { - x = foo; - } else if (b) { - x = bar; - } else { - baz(); - } - `, - ` - var x; - a ? x = foo : b ? x = bar : baz(); - ` - ); - - thePlugin( - "re-arranging conditionals for assignment member exprs", - ` - if (a) { - x.b = foo; - } else if (b) { - x.b = bar; - } else { - x.b = baz; - } - `, - ` - x.b = a ? foo : b ? bar : baz; - ` - ); - - thePlugin( - "re-arranging conditionals for assignment with operators", - ` - if (a) { - x.b += foo; - } else if (b) { - x.b += bar; - } else { - x.b += baz; - } - `, - ` - x.b += a ? foo : b ? bar : baz; - ` - ); - - thePlugin( - "should bail on different operators", - ` - if (a) { - x.b += foo; - } else if (b) { - x.b -= bar; - } else { - x.b += baz; - } - `, - ` - a ? x.b += foo : b ? x.b -= bar : x.b += baz; - ` - ); - - thePlugin( - "should bail on different member exprs", - ` - if (a) { - this.a = 1; - } else { - this.b = 2; - } - `, - ` - a ? this.a = 1 : this.b = 2; - ` - ); - - thePlugin( - "should turn continue into negated if", - ` - for (var p in foo) { - if (p) continue; - bar(); - } - `, - ` - for (var p in foo) p || bar(); - ` - ); - - thePlugin( - "should flip logical expressions", - ` - !x && foo(); - if (!(null == r)) for (;;); - `, - ` - if (!x && foo(), null != r) for (;;); - ` - ); - - thePlugin( - "should flip logical expressions 2", - ` - if (!(1 !== foo || !bar)) for (;;); - `, - ` - if (1 === foo && bar) for (;;); - ` - ); - - thePlugin( - "should combine to a single return statement", - ` - function foo() { - if (foo) { - bar(foo); - return foo; - } else if (baz) { - bar(baz); - return baz; - } else if (wat) { - bar(wat); - return wat; - } - } - `, - ` - function foo() { - return foo ? (bar(foo), foo) : baz ? (bar(baz), baz) : wat ? (bar(wat), wat) : void 0; - } - ` - ); - - thePlugin( - "should inline break condition in for test", - ` - for (i = 1; i <= j; i++) { - if (bar) break; - } - `, - ` - for (i = 1; i <= j && !bar; i++); - ` - ); - - thePlugin( - "should inline break condition in for test 2", - ` - for (i = 1; i <= j; i++) { - foo(); - if (bar) break; - } - `, - ` - for (i = 1; i <= j && (foo(), !bar); i++); - ` - ); - - thePlugin( - "should inline break condition in for test 3", - ` - for (i = 1; i <= j; i++) { - if (bar) { - break; - } else { - wat(); - if (x) throw 1 - } - } - `, - ` - for (i = 1; i <= j && !bar; i++) if (wat(), x) throw 1; - ` - ); - - // TODO: see `!!` below. - thePlugin( - "should inline break condition in for test 4", - ` - for (i = 1; i <= j; i++) { - if (bar) { - wat(); - if (x) throw 1; - } else { - break; - } - } - `, - ` - for (i = 1; i <= j && !!bar; i++) if (wat(), x) throw 1; - ` - ); - - // TODO: only apply ! unary to last in seq expr - thePlugin( - "should inline break condition in for test 5", - ` - for (i = 1; i <= j; i++) { - foo(); - if (bar) { - break; - } else { - wat(); - if (x) throw 1 - } - hi(); - } - `, - ` - for (i = 1; i <= j && (foo(), !bar); i++) { - if (wat(), x) throw 1; - hi(); - } - ` - ); - - thePlugin( - "should merge conditional returns into test", - ` - function foo() { - if (x) { - delete x.x; - if (bar()) return; - } - - if (bar) { - x(); - } else { - y(); - } - } - `, - ` - function foo() { - x && (delete x.x, bar()) || (bar ? x() : y()); - } - ` - ); - - thePlugin( - "should bail on mrege conditional return into test", - ` - function foo() { - if (x) { - delete x.x; - if (bar()) return 2; - } - - if (bar) { - x(); - } else { - y(); - } - } - `, - ` - function foo() { - return x && (delete x.x, bar()) ? 2 : void (bar ? x() : y()); - } - ` - ); - - thePlugin( - "should merge conditional return into test 2", - ` - function foo() { - if (x) { - delete x.x; - if (bar()) return; - } - } - `, - ` - function foo() { - x && (delete x.x, bar()); - } - ` - ); - - thePlugin( - "should handle return argument", - ` - function foo() { - if (x) { - delete x.x; - if (bar()) return x; - } - } - `, - ` - function foo() { - if (x && (delete x.x, bar())) return x; - } - ` - ); - - thePlugin( - "should bail on conditional return into test", - ` - function foo() { - if (x) { - var f = wow; - delete x.x; - if (bar()) return; - } - } - `, - ` - function foo() { - if (x) { - var f = wow; - - if (delete x.x, bar()) return; - } - } - ` - ); - - thePlugin( - "should recombine after continue merging", - ` - for (;;) { - a = b; - if (!foo) continue; - bar = foo; - } - `, - ` - for (;;) a = b, foo && (bar = foo); - ` - ); - - thePlugin( - "should not assume undefined", - ` - function foo() { - if (foo) { - if (bar) { - return false; - } - if (baz) { - return false; - } - } - return true; - } - `, - ` - function foo() { - if (foo) { - if (bar) return false; - if (baz) return false; - } - return true; - } - ` - ); - - thePlugin( - "should keep directives", - ` - function a() { - 'use strict'; - foo(); - } - `, - ` - function a() { - 'use strict'; - - foo(); - } - ` - ); - - thePlugin( - "should handle continue in nested if", - ` - function wow() { - for(;;) { - if (foo) { - if (bar) { - continue; - } - } - wat(); - } - } - `, - ` - function wow() { - for (;;) foo && bar || wat(); - } - ` - ); - - thePlugin( - "should convert gaurded nots to ors", - ` - x(); - if (!foo.bar) foo.bar = wat; - `, - ` - x(), !foo.bar && (foo.bar = wat); - ` - ); - - thePlugin( - "should convert gaurded nots to ors", - ` - if (!foo && foo !== bar) { - wow(); - such(); - } - `, - ` - !foo && foo !== bar && (wow(), such()); - ` - ); - - thePlugin( - "should put the empty vars first", - ` - var x = 1, y, z = 2, zx, a; - `, - ` - var y, - zx, - a, - x = 1, - z = 2; - ` - ); - - thePlugin( - "function expression in sequennce doesnt need parens", - ` - x, (function() {})(); - `, - ` - x, function () {}(); - ` - ); - - thePlugin( - "should turn early return else block into statement", - ` - function x() { - for (;;) { - x(); - if (foo) return 1; - else y(); - } - } - `, - ` - function x() { - for (;;) { - if (x(), foo) return 1; - y(); - } - } - ` - ); - - thePlugin( - "should remove block", - ` - function x() { - if (a) { - if (b) { - for(;;) { - if (a) b(); - } - } - } else { - wat(); - } - } - `, - ` - function x() { - if (!a) wat();else if (b) for (;;) a && b(); - } - ` - ); - - // TODO - thePlugin( - "should merge things into throw statement seq expr", - ` - function x() { - z(); - throw y; - } - `, - ` - function x() { - throw z(), y; - } - ` - ); - - // TODO: - // Fix indenting - thePlugin( - "should negate early return if", - ` - function x() { - if (!bar) return; - var x = foo; - if (!foo) return - if (y) - throw y; - } - `, - ` - function x() { - if (bar) { - var x = foo; - if (foo && y) throw y; - } - } - ` - ); - - thePlugin( - "should not negate early return if", - ` - function x() { - var x = foo; - if (hi) { - var y = z; - if (!foo) return; - if (x) throw y; - } - x(); - } - `, - ` - function x() { - var x = foo; - if (hi) { - var y = z; - if (!foo) return; - if (x) throw y; - } - x(); - } - ` - ); - - thePlugin( - "switch if to avoid blocking", - ` - function x() { - if (a) { - if (b) for (;;) wow(); - } else c(); - } - `, - ` - function x() { - if (!a) c();else if (b) for (;;) wow(); - } - ` - ); - - thePlugin( - "should remove last break statement in switch", - ` - switch (foo) { - case 'foo': - throw bar(); - break; - case 'bar': - wow(); - break; - } - `, - ` - switch (foo) { - case 'foo': - throw bar(); - break; - case 'bar': - wow(); - - } - ` - ); - - thePlugin( - "should not remove last break statement if it contains a label", - ` - loop: while (foo) { - switch (bar) { - case 47: - break; - } - switch (baz) { - default: - break loop; - } - } - `, - ` - loop: for (; foo;) { - switch (bar) { - case 47: - } - switch (baz) { - default: - break loop; - } - } - ` - ); - - thePlugin( - "should convert consequents in switch into sequence expressions", - ` - function bar() { - switch (foo) { - case 'foo': - bar(); - foo(); - break; - case 'bar': - wow(); - return wo; - break; - } - } - `, - ` - function bar() { - switch (foo) { - case 'foo': - bar(), foo(); - - break; - case 'bar': - return wow(), wo; - - } - } - ` - ); - - thePlugin( - "should convert switch statements to returns", - ` - function bar() { - switch (foo) { - case 'foo': - return 1; - case foo.bar: - return 2; - case wow: - wow(); - return 3; - default: - return 0; - } - } - `, - ` - function bar() { - return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : 0; - } - ` - ); - - thePlugin( - "should convert switch statements with next return as default to returns", - ` - function bar() { - switch (foo) { - case 'foo': - return 1; - case foo.bar: - return 2; - case wow: - wow(); - return 3; - } - return 0; - } - `, - ` - function bar() { - return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : 0; - } - ` - ); - - thePlugin( - "if last statement in function should consider the default return a void", - ` - function bar() { - switch (foo) { - case 'foo': - return 1; - case foo.bar: - return 2; - case wow: - wow(); - return 3; - } - } - `, - ` - function bar() { - return foo === 'foo' ? 1 : foo === foo.bar ? 2 : foo === wow ? (wow(), 3) : void 0; - } - ` - ); - - /* eslint-disable max-len */ - thePlugin( - "should convert switch statements w/ fallthrough to return", - ` - function bar() { - switch (foo) { - case 'foo': - return 1; - case foo.bar: - case wow: - wow(); - return 3; - case boo: - return 4; - case baz: - case wat: - return 5; - default: - return 0; - } - } - `, - ` - function bar() { - return foo === 'foo' ? 1 : foo === foo.bar || foo === wow ? (wow(), 3) : foo === boo ? 4 : foo === baz || foo === wat ? 5 : 0; - } - ` - ); - /* eslint-enable max-len */ - - thePlugin( - "should convert non-return switch to conditionals", - ` - function bar() { - switch (foo) { - case 'foo': - foo(); - break; - case foo.bar: - wow(); - wat(); - break; - case shh: - case wow: - baa(); - break; - default: - meh(); - } - } - `, - ` - function bar() { - foo === 'foo' ? foo() : foo === foo.bar ? (wow(), wat()) : foo === shh || foo === wow ? baa() : meh(); - } - ` - ); - - thePlugin( - "should put sequence in switch test", - ` - function bar() { - wow(); - switch (foo) { - case 'foo': - throw x(); - break; - } - } - `, - ` - function bar() { - switch (wow(), foo) { - case 'foo': - throw x(); - - } - } - ` - ); - - thePlugin( - "should put sequence in if test", - ` - function bar() { - wow(); - if (foo) { - throw x(); - } - } - `, - ` - function bar() { - if (wow(), foo) throw x(); - } - ` - ); - - thePlugin( - "should convert non-return switch to conditionals", - ` - function bar() { - switch (foo) { - case 'foo': - foo(); - break; - case foo.bar: - wow(); - wat(); - break; - case shh: - case wow: - baa(); - break; - default: - meh(); - } - } - `, - ` - function bar() { - foo === 'foo' ? foo() : foo === foo.bar ? (wow(), wat()) : foo === shh || foo === wow ? baa() : meh(); - } - ` - ); - - thePlugin( - "should not change type", - ` - function x(a) { - return !!a; - } - ` - ); - - thePlugin( - "should not change type", - ` - function x(a, b) { - a = a || b; - return b === a || !a; - } - `, - ` - function x(a, b) { - return a = a || b, b === a || !a; - } - ` - ); - - thePlugin( - "should apply unary to only the last element of a sequence expr", - ` - !(a, b, c); - `, - ` - a, b, !c; - ` - ); - - thePlugin( - "should apply unary to both sides of the conditional", - ` - !(a ? b : c); - `, - ` - a ? !b : !c; - ` - ); - - thePlugin( - "should flip alt and cons if condition is unary", - ` - !(!a && b) ? b : c - `, - ` - !a && b ? c : b; - ` - ); - - thePlugin( - "should merge previous expressions in the for loop right", - ` - function foo() { - x = 1; - a(); - for (var a in b) wow(); - } - `, - ` - function foo() { - for (var a in x = 1, a(), b) wow(); - } - ` - ); - - thePlugin( - "should convert empty blocks to empty statements", + "should fix issue#323 with != and !==", ` function foo() { - for (i in p) {} - for (; ;) {} - switch(1) {} - try { a } catch(e) {} + var x, y; + y = o[x]; + foo(y !== undefined); } `, ` function foo() { - for (i in p); - for (;;); - switch (1) {} - try { - a; - } catch (e) {} + var x, y; + y = o[x], foo(y !== undefined); } - ` - ); - - thePlugin( - "should flip binary expressions", - ` - if (!(!a && b == a && !b && b < a)) for(;;) a(); - `, - ` - if (a || b != a || b || !(b < a)) for (;;) a(); - ` - ); - - // From UglifyJS - thePlugin( - "should simplify common conditional expression patterns", - ` - function f1() { return a == b ? true : x; } - function f2() { return a == b ? false : x; } - function f3() { return a < b ? !0 : x; } - function f4() { return a < b ? !1 : x; } - function f5() { return c ? !0 : x; } - function f6() { return c ? false : x; } - function f7() { return !c ? true : x; } - function f8() { return !c ? !1 : x; } - function g1() { return a == b ? x : true; } - function g2() { return a == b ? x : false; } - function g3() { return a < b ? x : !0; } - function g4() { return a < b ? x : !1; } - function g5() { return c ? x : true; } - function g6() { return c ? x : !1; } - function g7() { return !c ? x : !0; } - function g8() { return !c ? x : false; } `, - ` - function f1() { - return !(a != b) || x; - } - function f2() { - return a != b && x; - } - function f3() { - return !!(a < b) || x; - } - function f4() { - return !(a < b) && x; - } - function f5() { - return !!c || x; - } - function f6() { - return !c && x; - } - function f7() { - return !c || x; - } - function f8() { - return !!c && x; - } - function g1() { - return a != b || x; - } - function g2() { - return !(a != b) && x; - } - function g3() { - return !(a < b) || x; - } - function g4() { - return !!(a < b) && x; - } - function g5() { - return !c || x; - } - function g6() { - return !!c && x; - } - function g7() { - return !!c || x; - } - function g8() { - return !c && x; + { + plugins: [plugin, comparisonPlugin] } - ` - ); - - thePlugin( - "should simplify common conditional operations 2", - ` - function h1() { return a && b ? (foo(), true) : false } - `, - ` - function h1() { - return !!(a && b) && (foo(), true); - } - ` - ); - - thePlugin( - "should fix issue#689", - ` - function foo(object, property, value) { - if (object && property) { - object[property] = value; - return true; - } - return false; - } - `, - ` - function foo(object, property, value) { - return !!(object && property) && (object[property] = value, true); - } - ` ); // From UglifyJS @@ -2146,35 +205,6 @@ describe("simplify-plugin", () => { ` ); - // https://github.com/babel/minify/issues/115 - thePlugin( - "should transform impure conditional statements correctly - issue#115", - ` - (function () { - a = x ? true : false; - c = 1 ? (this.get(x), a = b, true) : (foo.bar, false); - })(); - `, - ` - (function () { - a = !!x, c = 1 ? (this.get(x), a = b, true) : (foo.bar, false); - })(); - ` - ); - - thePlugin( - "should require block for single block scoped declaration in if/else", - ` - if (false) { - let { a } = foo(); - } else if (true) { - const x = bar(); - } else { - function baz() {} - } - ` - ); - thePlugin.inEachLine( "should simplify assignments", ` @@ -2337,254 +367,4 @@ describe("simplify-plugin", () => { foo.bar = foo.bar || {}; ` ); - - thePlugin( - "should simplify assignments w. super", - ` - class Foo { - foo() { - super.foo = super.foo + 1; - } - }; - `, - ` - class Foo { - foo() { - ++super.foo; - } - }; - ` - ); - - thePlugin( - "should not simplify assignments w. template literals", - ` - foo[\`x\`] = foo[\`x\`] + 1; - ` - ); - - // TODO: - // Fix indenting - thePlugin( - "should consider hoisted definitions in if_return", - ` - function foo() { - bar(); - if(x) return; - const {a}=b; - function bar () { - baz(); - bar(); - } - } - `, - ` - function foo() { - function bar() { - baz(), bar(); - } - - if (bar(), !x) { - const { a } = b; - } - } - ` - ); - - thePlugin( - "should optimize if..else..returns", - ` - function foo() { - if (a) { - if (x) return; - else return x; - } - const b = 1; - return "doesn't matter if this is reached or not"; - } - `, - ` - function foo() { - if (a) return x ? void 0 : x; - const b = 1; - return "doesn't matter if this is reached or not"; - } - ` - ); - - thePlugin( - "should fix issue#281 with if..return", - ` - function foo() { - if (x) - return; - function bar() {} - bar(a); - } - `, - ` - function foo() { - function bar() {} - x || bar(a); - } - ` - ); - - thePlugin( - "should fix issue#323 with != and !==", - ` - function foo() { - var x, y; - y = o[x]; - foo(y !== undefined); - } - `, - ` - function foo() { - var x, y; - y = o[x], foo(y !== undefined); - } - `, - { - plugins: [plugin, comparisonPlugin] - } - ); - - thePlugin( - "should fix issue#423 with fallthrough in default case", - ` - function foo(bar) { - switch (bar) { - case 'a': - return 1; - case 'b': - default: - return 4; - case 'c': - return 3; - } - } - `, - ` - function foo(bar) { - return bar === 'a' ? 1 : bar === 'c' ? 3 : 4; - } - ` - ); - - thePlugin( - "should convert multiple fallthrough in switch to conditional expression", - ` - function foo(bar) { - switch (bar) { - case 'a': - case 'b': - return 1; - case 'd': - default: - return 4; - case 'c': - return 3; - } - } - `, - ` - function foo(bar) { - return bar === 'a' || bar === 'b' ? 1 : bar === 'c' ? 3 : 4; - } - ` - ); - - thePlugin( - "should fix#455 and deopt when scope tree is not updated", - ` - function foo(param) { - if (param === null) return; - let thingA = param.a; - let thingB = param.b; - if (!thingA && !thingB) return; - let thingC = param.c; - } - `, - ` - function foo(param) { - if (param !== null) { - let thingA = param.a; - let thingB = param.b; - if (thingA || thingB) { - let thingC = param.c; - } - } - } - ` - ); - - thePlugin( - "should convert simple arrow block to expression", - ` - const a = () => {return (3, 4);}; - const b = () => {return 3;}; - `, - ` - const a = () => (3, 4); - const b = () => 3; - ` - ); - - thePlugin( - "should NOT convert empty arrow block to expression", - ` - const a = () => {}; - const b = () => {return;}; - `, - ` - const a = () => {}; - const b = () => {}; - ` - ); - - thePlugin( - "should NOT remove block for early continue transforms - fix issue#560", - ` - function foo() { - while (true) { - const {x} = a; - const {y} = b; - } - } - `, - ` - function foo() { - for (; true;) { - const { x } = a; - const { y } = b; - } - } - ` - ); - - // TODO: issue-637 - thePlugin( - "should NOT remove else block when ", - ` - function test(a) { - const clash = () => {}; - if (a) { - return clash(); - } else { - const clash = () => {}; - return clash(); - } - } - `, - ` - function test(a) { - const clash = () => {}; - if (a) return clash();else { - const clash = () => {}; - return clash(); - } - } - ` - ); });