From d144fd2256fab79e08a6ca380f9e77d4a6d7bff1 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 17:05:12 +0100 Subject: [PATCH 1/6] Move tests to individual fixtures - flip-comparisons --- .../binary-expr-constants-first/actual.js | 9 ++ .../binary-expr-constants-first/expected.js | 9 ++ .../binary-expr-pures-first/actual.js | 14 +++ .../binary-expr-pures-first/expected.js | 14 +++ .../binary-expr-values-first/actual.js | 2 + .../binary-expr-values-first/expected.js | 2 + .../conditionals-same-consequent/actual.js | 1 + .../conditionals-same-consequent/expected.js | 1 + .../__tests__/flip-comparisons-test.js | 87 ------------------- .../__tests__/index.js | 2 + 10 files changed, 54 insertions(+), 87 deletions(-) create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/actual.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/expected.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/actual.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/expected.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/actual.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/expected.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/actual.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/expected.js delete mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/flip-comparisons-test.js create mode 100644 packages/babel-plugin-minify-flip-comparisons/__tests__/index.js diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/actual.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/actual.js new file mode 100644 index 000000000..1373d7398 --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/actual.js @@ -0,0 +1,9 @@ +// constants first +a === -1; + +x * 100; +x + 100; +x - 100; +x / 100; +x > 100; +x === void 0; diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/expected.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/expected.js new file mode 100644 index 000000000..a968934cc --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-constants-first/expected.js @@ -0,0 +1,9 @@ +// constants first +-1 === a; + +100 * x; +x + 100; +x - 100; +x / 100; +100 < x; +void 0 === x; \ No newline at end of file diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/actual.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/actual.js new file mode 100644 index 000000000..2fc3733dd --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/actual.js @@ -0,0 +1,14 @@ +// pures first + +a === null; + +a === {}; + +function foo() { + if (foo !== null) { + var bar; + bar = baz; + } + x(); + return x; +} diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/expected.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/expected.js new file mode 100644 index 000000000..6c6c45ec8 --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-pures-first/expected.js @@ -0,0 +1,14 @@ +// pures first + +null === a; + +({}) === a; + +function foo() { + if (null !== foo) { + var bar; + bar = baz; + } + x(); + return x; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/actual.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/actual.js new file mode 100644 index 000000000..9d99c90db --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/actual.js @@ -0,0 +1,2 @@ +// values first +a === 1; diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/expected.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/expected.js new file mode 100644 index 000000000..9147277a9 --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/binary-expr-values-first/expected.js @@ -0,0 +1,2 @@ +// values first +1 === a; \ No newline at end of file diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/actual.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/actual.js new file mode 100644 index 000000000..8aeaf6d1c --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/actual.js @@ -0,0 +1 @@ +x === null ? undefined : x === undefined ? undefined : x ? foo(x) : wat(); diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/expected.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/expected.js new file mode 100644 index 000000000..ebbde3a1d --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/fixtures/conditionals-same-consequent/expected.js @@ -0,0 +1 @@ +null === x ? undefined : x === undefined ? undefined : x ? foo(x) : wat(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/flip-comparisons-test.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/flip-comparisons-test.js deleted file mode 100644 index b35aa46f2..000000000 --- a/packages/babel-plugin-minify-flip-comparisons/__tests__/flip-comparisons-test.js +++ /dev/null @@ -1,87 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("flip-comparisons", () => { - thePlugin( - "should merge two conditionals if they share the same consequent", - ` - x === null ? undefined : x === undefined ? undefined : x ? foo(x) : wat(); - `, - ` - null === x ? undefined : x === undefined ? undefined : x ? foo(x) : wat(); - ` - ); - - thePlugin( - "should put values first in binary expressions", - ` - a === 1; - `, - ` - 1 === a; - ` - ); - - thePlugin( - "should put constants first in binary expressions", - ` - a === -1; - `, - ` - -1 === a; - ` - ); - - thePlugin( - "should put pures first in binary expressions", - ` - a === null; - - a === {}; - - function foo() { - if (foo !== null) { - var bar; - bar = baz; - } - x(); - return x; - } - `, - ` - null === a; - - ({}) === a; - - function foo() { - if (null !== foo) { - var bar; - bar = baz; - } - x(); - return x; - } - ` - ); - - thePlugin( - "should put constants first in binary expressions", - ` - x * 100; - x + 100; - x - 100; - x / 100; - x > 100; - x === void 0; - `, - ` - 100 * x; - x + 100; - x - 100; - x / 100; - 100 < x; - void 0 === x; - ` - ); -}); diff --git a/packages/babel-plugin-minify-flip-comparisons/__tests__/index.js b/packages/babel-plugin-minify-flip-comparisons/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-flip-comparisons/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); From 9a728f6eb9a8572d22296a70caab48933d290f27 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 17:10:21 +0100 Subject: [PATCH 2/6] Move tests to fixtures - guardedExpressions --- .../fixtures/flip-logical-expr/actual.js | 1 + .../fixtures/flip-logical-expr/expected.js | 1 + .../fixtures/reachable-impure-stmts/actual.js | 2 + .../reachable-impure-stmts/expected.js | 2 + .../fixtures/simplify-falsy-expr/actual.js | 7 +++ .../fixtures/simplify-falsy-expr/expected.js | 7 +++ .../fixtures/simplify-truthy-expr/actual.js | 4 ++ .../fixtures/simplify-truthy-expr/expected.js | 4 ++ .../__tests__/guarded-expressions-test.js | 61 ------------------- .../__tests__/index.js | 2 + 10 files changed, 30 insertions(+), 61 deletions(-) create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/actual.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/expected.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/actual.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/expected.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/actual.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/expected.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/actual.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/expected.js delete mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/guarded-expressions-test.js create mode 100644 packages/babel-plugin-minify-guarded-expressions/__tests__/index.js diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/actual.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/actual.js new file mode 100644 index 000000000..e093246ae --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/actual.js @@ -0,0 +1 @@ +!x && foo(); diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/expected.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/expected.js new file mode 100644 index 000000000..0f6f29988 --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/flip-logical-expr/expected.js @@ -0,0 +1 @@ +x || foo(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/actual.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/actual.js new file mode 100644 index 000000000..9d60e60c8 --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/actual.js @@ -0,0 +1,2 @@ +a && void alert("Side effect"); +alert(func() || true); diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/expected.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/expected.js new file mode 100644 index 000000000..446ffa55b --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/reachable-impure-stmts/expected.js @@ -0,0 +1,2 @@ +a && void alert("Side effect"); +alert(func() || true); \ No newline at end of file diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/actual.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/actual.js new file mode 100644 index 000000000..5080f81ea --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/actual.js @@ -0,0 +1,7 @@ +alert(0 && new Foo()); +if (0 && something()) for (;;); +alert(false && new Foo()); +alert(undefined && new Foo()); +alert(null && new Foo()); +alert("" && new Foo()); +alert(new Foo() || false); diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/expected.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/expected.js new file mode 100644 index 000000000..def9e1e0d --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-falsy-expr/expected.js @@ -0,0 +1,7 @@ +alert(0); +if (0) for (;;); +alert(false); +alert(undefined); +alert(null); +alert(""); +alert(new Foo() || false); \ No newline at end of file diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/actual.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/actual.js new file mode 100644 index 000000000..7d4c861f0 --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/actual.js @@ -0,0 +1,4 @@ +alert(1 && new Bar()); +alert(true && new Bar()); +alert("hello" && new Bar()); +alert(!false && new Bar()); diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/expected.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/expected.js new file mode 100644 index 000000000..b83e49caa --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/fixtures/simplify-truthy-expr/expected.js @@ -0,0 +1,4 @@ +alert(new Bar()); +alert(new Bar()); +alert(new Bar()); +alert(new Bar()); \ No newline at end of file diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/guarded-expressions-test.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/guarded-expressions-test.js deleted file mode 100644 index ddd0d285f..000000000 --- a/packages/babel-plugin-minify-guarded-expressions/__tests__/guarded-expressions-test.js +++ /dev/null @@ -1,61 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("guarded-expressions-plugin", () => { - thePlugin( - "should flip logical expressions", - ` - !x && foo(); - `, - ` - x || foo(); - ` - ); - - thePlugin( - "should simplify falsy logical expressions", - ` - alert(0 && new Foo()); - if (0 && something()) for(;;); - alert(false && new Foo()); - alert(undefined && new Foo()); - alert(null && new Foo()); - alert("" && new Foo()); - alert(new Foo() || false); - `, - ` - alert(0); - if (0) for (;;); - alert(false); - alert(undefined); - alert(null); - alert(""); - alert(new Foo() || false); - ` - ); - - thePlugin( - "should simplify truthy expressions", - ` - alert(1 && new Bar()); - alert(true && new Bar()); - alert("hello" && new Bar()); - alert(!false && new Bar()); - `, - ` - alert(new Bar()); - alert(new Bar()); - alert(new Bar()); - alert(new Bar()); - ` - ); - - thePlugin( - "should not remove reachable impure statements", - ` - a && void alert('Side effect'); - alert(func() || true); - ` - ); -}); diff --git a/packages/babel-plugin-minify-guarded-expressions/__tests__/index.js b/packages/babel-plugin-minify-guarded-expressions/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-guarded-expressions/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); From f3b640af0dfa301d38573386c552d2108671bb24 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 17:15:17 +0100 Subject: [PATCH 3/6] Move tests to fixtures - infinity --- .../fixtures/assignment-expr/actual.js | 1 + .../fixtures/assignment-expr/expected.js | 1 + .../__tests__/fixtures/destructure/actual.js | 3 ++ .../fixtures/destructure/expected.js | 3 ++ .../__tests__/fixtures/fn-param/actual.js | 3 ++ .../__tests__/fixtures/fn-param/expected.js | 3 ++ .../__tests__/fixtures/property/actual.js | 2 + .../__tests__/fixtures/property/expected.js | 2 + .../__tests__/fixtures/to-1-over-0/actual.js | 1 + .../fixtures/to-1-over-0/expected.js | 1 + .../__tests__/index.js | 2 + .../__tests__/infinity-test.js | 48 ------------------- 12 files changed, 22 insertions(+), 48 deletions(-) create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/actual.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/expected.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/actual.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/expected.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/actual.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/expected.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/property/actual.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/property/expected.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/actual.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/expected.js create mode 100644 packages/babel-plugin-minify-infinity/__tests__/index.js delete mode 100644 packages/babel-plugin-minify-infinity/__tests__/infinity-test.js diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/actual.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/actual.js new file mode 100644 index 000000000..20510ef5b --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/actual.js @@ -0,0 +1 @@ +Infinity = 1; diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/expected.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/expected.js new file mode 100644 index 000000000..233ca56bf --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/assignment-expr/expected.js @@ -0,0 +1 @@ +Infinity = 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/actual.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/actual.js new file mode 100644 index 000000000..e44dc7c09 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/actual.js @@ -0,0 +1,3 @@ +({ Infinity } = 1); +[Infinity] = foo; +[...Infinity] = foo; diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/expected.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/expected.js new file mode 100644 index 000000000..d3aac08e4 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/destructure/expected.js @@ -0,0 +1,3 @@ +({ Infinity } = 1); +[Infinity] = foo; +[...Infinity] = foo; \ No newline at end of file diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/actual.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/actual.js new file mode 100644 index 000000000..b6a47eb6f --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/actual.js @@ -0,0 +1,3 @@ +function a(Infinity) {} +function b(...Infinity) {} +function c({ Infinity }) {} diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/expected.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/expected.js new file mode 100644 index 000000000..3a2243a48 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/fn-param/expected.js @@ -0,0 +1,3 @@ +function a(Infinity) {} +function b(...Infinity) {} +function c({ Infinity }) {} \ No newline at end of file diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/actual.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/actual.js new file mode 100644 index 000000000..1f59d089a --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/actual.js @@ -0,0 +1,2 @@ +var x = { Infinity: 0 }; +x.Infinity; diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/expected.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/expected.js new file mode 100644 index 000000000..499939117 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/property/expected.js @@ -0,0 +1,2 @@ +var x = { Infinity: 0 }; +x.Infinity; \ No newline at end of file diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/actual.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/actual.js new file mode 100644 index 000000000..744c9130d --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/actual.js @@ -0,0 +1 @@ +Infinity; diff --git a/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/expected.js b/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/expected.js new file mode 100644 index 000000000..80738b0c8 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/fixtures/to-1-over-0/expected.js @@ -0,0 +1 @@ +1 / 0; \ No newline at end of file diff --git a/packages/babel-plugin-minify-infinity/__tests__/index.js b/packages/babel-plugin-minify-infinity/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-infinity/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-minify-infinity/__tests__/infinity-test.js b/packages/babel-plugin-minify-infinity/__tests__/infinity-test.js deleted file mode 100644 index d1c4a381d..000000000 --- a/packages/babel-plugin-minify-infinity/__tests__/infinity-test.js +++ /dev/null @@ -1,48 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("minify-infinity", () => { - thePlugin( - "should convert Infinity to division over 0", - ` - Infinity; - `, - ` - 1 / 0; - ` - ); - - thePlugin( - "should not convert Infinity when it’s a property", - ` - var x = { Infinity: 0 }; - x.Infinity; - ` - ); - - thePlugin( - "should not convert Infinity if it’s a assignment expression", - ` - Infinity = 1; - ` - ); - - thePlugin( - "should not convert Infinity when it’s destructed", - ` - ({ Infinity } = 1); - [Infinity] = foo; - [...Infinity] = foo; - ` - ); - - thePlugin( - "should not convert Infinity when as a function params", - ` - function a(Infinity) {} - function a(...Infinity) {} - function a({ Infinity }) {} - ` - ); -}); From ca1820f818205a65d19cd9adf9b9ce6b8d53bcdc Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 17:26:46 +0100 Subject: [PATCH 4/6] Move tests to fixtures - numeric-literals --- .../__tests__/mangle-names-test.js | 27 -------- .../__tests__/fixtures/exponential/actual.js | 3 + .../fixtures/exponential/expected.js | 3 + .../extreme-float-resolution/actual.js | 1 + .../extreme-float-resolution/expected.js | 1 + .../__tests__/fixtures/float/actual.js | 2 + .../__tests__/fixtures/float/expected.js | 2 + .../fixtures/integer-literals/actual.js | 13 ++++ .../fixtures/integer-literals/expected.js | 4 ++ .../__tests__/index.js | 2 + .../__tests__/numeric-literals-test.js | 67 ------------------- 11 files changed, 31 insertions(+), 94 deletions(-) create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/actual.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/expected.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/actual.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/expected.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/actual.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/expected.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/actual.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/expected.js create mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/index.js delete mode 100644 packages/babel-plugin-minify-numeric-literals/__tests__/numeric-literals-test.js diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js index cf009685d..008ca2451 100644 --- a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js +++ b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js @@ -4,33 +4,6 @@ const mangler = require("../src/index"); const thePlugin = require("test-transform")(mangler); describe("mangle-names", () => { - thePlugin( - "should not mangle names in the global namespace", - ` - var Foo = 1; - ` - ); - - thePlugin( - "should mangle names", - ` - function foo() { - var xxx = 1; - if (xxx) { - console.log(xxx); - } - } - `, - ` - function foo() { - var a = 1; - if (a) { - console.log(a); - } - } - ` - ); - thePlugin( "should handle name collisions", ` diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/actual.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/actual.js new file mode 100644 index 000000000..6d9b36023 --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/actual.js @@ -0,0 +1,3 @@ +[1e1, 1e2, 1.5e3, -1e1, -1e2, -1.5e3, 1e-1, 1e-2, 1.5e-3, 1e-4]; +[1.5e4, 15e-2, 1.5e-4]; +[123000, 12345600000]; diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/expected.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/expected.js new file mode 100644 index 000000000..b7e56973d --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/exponential/expected.js @@ -0,0 +1,3 @@ +[10, 1e2, 1500, -10, -1e2, -1500, .1, .01, .0015, 1e-4]; +[15e3, .15, 15e-5]; +[123e3, 123456e5]; \ No newline at end of file diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/actual.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/actual.js new file mode 100644 index 000000000..e2e6ca8c4 --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/actual.js @@ -0,0 +1 @@ +[+0.000000000001, -0.00000000001]; diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/expected.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/expected.js new file mode 100644 index 000000000..ab18dcbe6 --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/extreme-float-resolution/expected.js @@ -0,0 +1 @@ +[+1e-12, -1e-11]; \ No newline at end of file diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/actual.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/actual.js new file mode 100644 index 000000000..0def4a54c --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/actual.js @@ -0,0 +1,2 @@ +[.123456, 1.23456, 12.3456, -0.123456, -1.23456, -12.3456]; +[0.10, 0.010, 0.0010]; diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/expected.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/expected.js new file mode 100644 index 000000000..34ee94f58 --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/float/expected.js @@ -0,0 +1,2 @@ +[.123456, 1.23456, 12.3456, -.123456, -1.23456, -12.3456]; +[.1, .01, .001]; \ No newline at end of file diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/actual.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/actual.js new file mode 100644 index 000000000..5e53e889e --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/actual.js @@ -0,0 +1,13 @@ +[1, 10, 100, 1000, 10000, -1, -10, -100, -1000, -10000]; +[0x1, 0xa, 0x64, 0x3e8, 0xfffffff, -0x1, -0xa, -0x64, -0x3e8, -0xfffffff]; +[0o1, 0o12, 0o144, 0o1750, -0o1, -0o12, -0o144, -0o1750]; +[ + 0b1, + 0b1010, + 0b1100100, + 0b1111101000, + -0b1, + -0b1010, + -0b1100100, + -0b1111101000 +]; diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/expected.js b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/expected.js new file mode 100644 index 000000000..4c0f53d9f --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/fixtures/integer-literals/expected.js @@ -0,0 +1,4 @@ +[1, 10, 100, 1e3, 1e4, -1, -10, -100, -1e3, -1e4]; +[1, 10, 100, 1e3, 0xfffffff, -1, -10, -100, -1e3, -0xfffffff]; +[1, 10, 100, 1e3, -1, -10, -100, -1e3]; +[1, 10, 100, 1e3, -1, -10, -100, -1e3]; \ No newline at end of file diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/index.js b/packages/babel-plugin-minify-numeric-literals/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-numeric-literals/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-minify-numeric-literals/__tests__/numeric-literals-test.js b/packages/babel-plugin-minify-numeric-literals/__tests__/numeric-literals-test.js deleted file mode 100644 index 630c54448..000000000 --- a/packages/babel-plugin-minify-numeric-literals/__tests__/numeric-literals-test.js +++ /dev/null @@ -1,67 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("numeric-literals", () => { - thePlugin( - "should shorten integer literals correctly", - ` - [1, 10, 100, 1000, 10000, -1, -10, -100, -1000, -10000]; - [0x1, 0xa, 0x64, 0x3e8, 0xfffffff, -0x1, -0xa, -0x64, -0x3e8, -0xfffffff]; - [0o1, 0o12, 0o144, 0o1750, -0o1, -0o12, -0o144, -0o1750]; - [0b1, 0b1010, 0b1100100, 0b1111101000, -0b1, -0b1010, -0b1100100, -0b1111101000] - `, - ` - [1, 10, 100, 1e3, 1e4, -1, -10, -100, -1e3, -1e4]; - [1, 10, 100, 1e3, 0xfffffff, -1, -10, -100, -1e3, -0xfffffff]; - [1, 10, 100, 1e3, -1, -10, -100, -1e3]; - [1, 10, 100, 1e3, -1, -10, -100, -1e3]; - ` - ); - - thePlugin( - "should shorten floats correctly", - ` - [.123456, 1.23456, 12.3456, -0.123456, -1.23456, -12.3456]; - [0.10, 0.010, 0.0010]; - `, - ` - [.123456, 1.23456, 12.3456, -.123456, -1.23456, -12.3456]; - [.1, .01, .001]; - ` - ); - - thePlugin( - "should shorten existing exponential literals correctly", - ` - [1e1, 1e2, 1.5e3, -1e1, -1e2, -1.5e3, 1e-1, 1e-2, 1.5e-3, 1e-4]; - [1.5e4, 15e-2, 1.5e-4]; - `, - ` - [10, 1e2, 1500, -10, -1e2, -1500, .1, .01, .0015, 1e-4]; - [15e3, .15, 15e-5]; - ` - ); - - thePlugin( - "should represent literals in exponential form when optimal", - ` - [123000, 12345600000]; - `, - ` - [123e3, 123456e5]; - ` - ); - - // TODO: this seems to be specific to how Babel output numbers - // for some reason it adds + in the beginning - thePlugin.skip( - "should handle extreme float resolution correctly", - ` - [+0.000000000001, -0.00000000001]; - `, - ` - [+1e-12, -1e-11]; - ` - ); -}); From 5a41708a3c5b15e8bde8e72e6ef1695f3c233659 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 17:33:43 +0100 Subject: [PATCH 5/6] ignore tmp files (*~$) --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eb4a164dc..d3c35ea92 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ coverage .test_gen_* lib/ *.log +*~ From b65e927924fde49b71b78d877775046eaa5478d8 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Thu, 9 Nov 2017 22:36:08 +0100 Subject: [PATCH 6/6] Move tests to fixtures - mangler --- .../__tests__/fixtures/basic/actual.js | 6 + .../__tests__/fixtures/basic/expected.js | 6 + .../__tests__/fixtures/classes/actual.js | 10 + .../__tests__/fixtures/classes/expected.js | 10 + .../__tests__/fixtures/closures-2/actual.js | 8 + .../__tests__/fixtures/closures-2/expected.js | 8 + .../__tests__/fixtures/closures/actual.js | 9 + .../__tests__/fixtures/closures/expected.js | 9 + .../fixtures/constant-violations-2/actual.js | 12 + .../constant-violations-2/expected.js | 12 + .../fixtures/constant-violations-3/actual.js | 5 + .../constant-violations-3/expected.js | 5 + .../fixtures/constant-violations-4/actual.js | 20 + .../constant-violations-4/expected.js | 20 + .../fixtures/constant-violations/actual.js | 12 + .../fixtures/constant-violations/expected.js | 12 + .../fixtures/deeply-nested/actual.js | 12 + .../fixtures/deeply-nested/expected.js | 12 + .../fixtures/destructuring/actual.js | 15 + .../fixtures/destructuring/expected.js | 15 + .../fixtures/eval-scope-ignore/actual.js | 10 + .../fixtures/eval-scope-ignore/expected.js | 10 + .../fixtures/eval-scope-ignore/options.json | 3 + .../__tests__/fixtures/eval-scope/actual.js | 10 + .../__tests__/fixtures/eval-scope/expected.js | 10 + .../fixtures/fn-only-thunk/actual.js | 8 + .../fixtures/fn-only-thunk/expected.js | 8 + .../__tests__/fixtures/fn-params/actual.js | 5 + .../__tests__/fixtures/fn-params/expected.js | 5 + .../fixtures/global-conflicts/actual.js | 6 + .../fixtures/global-conflicts/expected.js | 6 + .../__tests__/fixtures/globals-2/actual.js | 11 + .../__tests__/fixtures/globals-2/expected.js | 11 + .../__tests__/fixtures/globals/actual.js | 1 + .../__tests__/fixtures/globals/expected.js | 1 + .../__tests__/fixtures/hoisted/actual.js | 13 + .../__tests__/fixtures/hoisted/expected.js | 13 + .../fixtures/issue-365-toplevel/actual.js | 3 + .../fixtures/issue-365-toplevel/expected.js | 3 + .../fixtures/issue-365-toplevel/options.json | 3 + .../__tests__/fixtures/issue-365/actual.js | 5 + .../__tests__/fixtures/issue-365/expected.js | 5 + .../__tests__/fixtures/issue-411/actual.js | 8 + .../__tests__/fixtures/issue-411/expected.js | 8 + .../fixtures/keep-class-name/actual.js | 9 + .../fixtures/keep-class-name/expected.js | 9 + .../fixtures/keep-class-name/options.json | 3 + .../__tests__/fixtures/keep-fn-name/actual.js | 11 + .../fixtures/keep-fn-name/expected.js | 11 + .../fixtures/keep-fn-name/options.json | 3 + .../__tests__/fixtures/labels-2/actual.js | 6 + .../__tests__/fixtures/labels-2/expected.js | 6 + .../__tests__/fixtures/labels-3/actual.js | 16 + .../__tests__/fixtures/labels-3/expected.js | 16 + .../__tests__/fixtures/labels/actual.js | 5 + .../__tests__/fixtures/labels/expected.js | 5 + .../fixtures/name-collisions/actual.js | 7 + .../fixtures/name-collisions/expected.js | 7 + .../__tests__/fixtures/nested-loops/actual.js | 7 + .../fixtures/nested-loops/expected.js | 7 + .../fixtures/order-independence/actual.js | 20 + .../fixtures/order-independence/expected.js | 20 + .../__tests__/fixtures/recursion/actual.js | 5 + .../__tests__/fixtures/recursion/expected.js | 5 + .../__tests__/fixtures/reuse/actual.js | 250 ++++ .../__tests__/fixtures/reuse/expected.js | 26 + .../safari-shadowing-loops-2/actual.js | 27 + .../safari-shadowing-loops-2/expected.js | 23 + .../safari-shadowing-loops-3/actual.js | 27 + .../safari-shadowing-loops-3/expected.js | 23 + .../fixtures/safari-shadowing-loops/README.md | 5 + .../fixtures/safari-shadowing-loops/actual.js | 29 + .../safari-shadowing-loops/expected.js | 25 + .../fixtures/safari-toplevel-loops/actual.js | 27 + .../safari-toplevel-loops/expected.js | 23 + .../__tests__/fixtures/shadow-outer/actual.js | 6 + .../fixtures/shadow-outer/expected.js | 6 + .../__tests__/fixtures/shadowing-2/actual.js | 8 + .../fixtures/shadowing-2/expected.js | 8 + .../__tests__/fixtures/shadowing/actual.js | 7 + .../__tests__/fixtures/shadowing/expected.js | 7 + .../fixtures/toplevel-and-exclude/actual.js | 4 + .../fixtures/toplevel-and-exclude/expected.js | 4 + .../toplevel-and-exclude/options.json | 7 + .../__tests__/fixtures/toplevel/actual.js | 14 + .../__tests__/fixtures/toplevel/expected.js | 14 + .../__tests__/fixtures/toplevel/options.json | 3 + .../__tests__/fixtures/try-catch/actual.js | 5 + .../__tests__/fixtures/try-catch/expected.js | 4 + .../__tests__/index.js | 2 + .../__tests__/mangle-names-test.js | 1322 +---------------- 91 files changed, 1158 insertions(+), 1310 deletions(-) create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/README.md create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/options.json create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/actual.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/expected.js create mode 100644 packages/babel-plugin-minify-mangle-names/__tests__/index.js diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/actual.js new file mode 100644 index 000000000..2897cf1f4 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/actual.js @@ -0,0 +1,6 @@ +function foo() { + var xxx = 1; + if (xxx) { + console.log(xxx); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/expected.js new file mode 100644 index 000000000..2f2e63e63 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/basic/expected.js @@ -0,0 +1,6 @@ +function foo() { + var a = 1; + if (a) { + console.log(a); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/actual.js new file mode 100644 index 000000000..5fc6e6c05 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/actual.js @@ -0,0 +1,10 @@ +class A {} +class B {} +new A(); +new B(); +function a() { + class A {} + class B {} + new A(); + new B(); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/expected.js new file mode 100644 index 000000000..978cb62d2 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/classes/expected.js @@ -0,0 +1,10 @@ +class A {} +class B {} +new A(); +new B(); +function a() { + class a {} + class b {} + new a(); + new b(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/actual.js new file mode 100644 index 000000000..fe4855be9 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/actual.js @@ -0,0 +1,8 @@ +function foo() { + function bar(baz) { + return function() { + bam(); + }; + } + function bam() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/expected.js new file mode 100644 index 000000000..c3eb19107 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures-2/expected.js @@ -0,0 +1,8 @@ +function foo() { + function a(a) { + return function () { + b(); + }; + } + function b() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/actual.js new file mode 100644 index 000000000..2932eb828 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/actual.js @@ -0,0 +1,9 @@ +function foo() { + function bar() { + var baz; + if (baz) { + bam(); + } + } + function bam() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/expected.js new file mode 100644 index 000000000..7499b266e --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/closures/expected.js @@ -0,0 +1,9 @@ +function foo() { + function a() { + var a; + if (a) { + b(); + } + } + function b() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/actual.js new file mode 100644 index 000000000..5db765a39 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/actual.js @@ -0,0 +1,12 @@ +!function() { + var bar = 1; + bar--; + var bar = 10; + foo(bar); + function foo() { + var foo = 10; + foo++; + var foo = 20; + foo(foo); + } +}; diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/expected.js new file mode 100644 index 000000000..3176d3f23 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-2/expected.js @@ -0,0 +1,12 @@ +!function () { + var b = 1; + b--; + var b = 10; + a(b); + function a() { + var a = 10; + a++; + var a = 20; + a(a); + } +}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/actual.js new file mode 100644 index 000000000..2b1b8c15d --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/actual.js @@ -0,0 +1,5 @@ +(function() { + var foo = bar, + foo = baz; + foo; +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/expected.js new file mode 100644 index 000000000..9abafa655 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-3/expected.js @@ -0,0 +1,5 @@ +(function () { + var a = bar, + a = baz; + a; +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/actual.js new file mode 100644 index 000000000..5ff7b8a48 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/actual.js @@ -0,0 +1,20 @@ +function foo() { + var x; + x; + x; + { + var x; + x; + x; + function y() { + var x; + x; + x; + { + var x; + x; + x; + } + } + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/expected.js new file mode 100644 index 000000000..7bd5abf07 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations-4/expected.js @@ -0,0 +1,20 @@ +function foo() { + var a; + a; + a; + { + var a; + a; + a; + function b() { + var a; + a; + a; + { + var a; + a; + a; + } + } + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/actual.js new file mode 100644 index 000000000..b6620f320 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/actual.js @@ -0,0 +1,12 @@ +!function() { + var foo = 1; + foo++; + var foo = 2; + foo++; +}; + +(function() { + var x = y; + x = z; + x; +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/expected.js new file mode 100644 index 000000000..8302eda47 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/constant-violations/expected.js @@ -0,0 +1,12 @@ +!function () { + var a = 1; + a++; + var a = 2; + a++; +}; + +(function () { + var a = y; + a = z; + a; +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/actual.js new file mode 100644 index 000000000..22ce17449 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/actual.js @@ -0,0 +1,12 @@ +function xoo() { + function foo(zz, xx, yy) { + function bar(zip, zap, zop) { + return function(bar) { + zap(); + return function() { + zip(); + }; + }; + } + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/expected.js new file mode 100644 index 000000000..2fe54cd35 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/deeply-nested/expected.js @@ -0,0 +1,12 @@ +function xoo() { + function a(a, b, c) { + function d(a, b, c) { + return function (c) { + b(); + return function () { + a(); + }; + }; + } + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/actual.js new file mode 100644 index 000000000..1788f4a6f --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/actual.js @@ -0,0 +1,15 @@ +// issue#326 +function a() { + let foo, bar, baz; + ({ foo, bar, baz } = {}); + return { foo, bar, baz }; +} +// issue#369 +function decodeMessage(message) { + let namespace; + let name; + let value = null; + + [, namespace, name, value] = message.split(",") || []; + console.log(name); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/expected.js new file mode 100644 index 000000000..45b5cc634 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/destructuring/expected.js @@ -0,0 +1,15 @@ +// issue#326 +function a() { + let a, b, c; + ({ foo: a, bar: b, baz: c } = {}); + return { foo: a, bar: b, baz: c }; +} +// issue#369 +function decodeMessage(a) { + let b; + let c; + let d = null; + + [, b, c, d] = a.split(",") || []; + console.log(c); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/actual.js new file mode 100644 index 000000000..3fc54d28f --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/actual.js @@ -0,0 +1,10 @@ +function foo() { + var inScopeOuter = 1; + (function() { + var inScopeInner = 2; + eval("..."); + (function() { + var outOfScope = 1; + })(); + })(); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/expected.js new file mode 100644 index 000000000..ec9cd40af --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/expected.js @@ -0,0 +1,10 @@ +function foo() { + var a = 1; + (function () { + var a = 2; + eval("..."); + (function () { + var a = 1; + })(); + })(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/options.json new file mode 100644 index 000000000..02da374fb --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope-ignore/options.json @@ -0,0 +1,3 @@ +{ + "eval": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/actual.js new file mode 100644 index 000000000..aec826745 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/actual.js @@ -0,0 +1,10 @@ +function foo() { + var inScopeOuter = 1; + (function() { + var inScopeInner = 2; + eval("inScopeInner + inScopeOuter"); + (function() { + var outOfScope = 1; + })(); + })(); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/expected.js new file mode 100644 index 000000000..710d5d539 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/eval-scope/expected.js @@ -0,0 +1,10 @@ +function foo() { + var inScopeOuter = 1; + (function () { + var inScopeInner = 2; + eval("inScopeInner + inScopeOuter"); + (function () { + var a = 1; + })(); + })(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/actual.js new file mode 100644 index 000000000..82ace16c9 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/actual.js @@ -0,0 +1,8 @@ +function foo() { + function xx(bar, baz) { + if (1) { + yy(bar, baz); + } + } + function yy() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/expected.js new file mode 100644 index 000000000..cf7822e0b --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-only-thunk/expected.js @@ -0,0 +1,8 @@ +function foo() { + function a(a, c) { + if (1) { + b(a, c); + } + } + function b() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/actual.js new file mode 100644 index 000000000..80ea21284 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/actual.js @@ -0,0 +1,5 @@ +function foo(xxx) { + if (xxx) { + console.log(xxx); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/expected.js new file mode 100644 index 000000000..96f23074c --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/fn-params/expected.js @@ -0,0 +1,5 @@ +function foo(a) { + if (a) { + console.log(a); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/actual.js new file mode 100644 index 000000000..11f255fa5 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/actual.js @@ -0,0 +1,6 @@ +function e() { + function foo() { + b = bar(); + } + function bar() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/expected.js new file mode 100644 index 000000000..975e3d9cd --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/global-conflicts/expected.js @@ -0,0 +1,6 @@ +function e() { + function a() { + b = c(); + } + function c() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/actual.js new file mode 100644 index 000000000..ad583300a --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/actual.js @@ -0,0 +1,11 @@ +class A {} +class B extends A {} +(function() { + class C { + constructor() { + new A(); + new B(); + C; + } + } +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/expected.js new file mode 100644 index 000000000..2806a9458 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals-2/expected.js @@ -0,0 +1,11 @@ +class A {} +class B extends A {} +(function () { + class a { + constructor() { + new A(); + new B(); + a; + } + } +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/actual.js new file mode 100644 index 000000000..40665d538 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/actual.js @@ -0,0 +1 @@ +var Foo = 1; diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/expected.js new file mode 100644 index 000000000..2171c4bc2 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/globals/expected.js @@ -0,0 +1 @@ +var Foo = 1; \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/actual.js new file mode 100644 index 000000000..3426c24ed --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/actual.js @@ -0,0 +1,13 @@ +(function() { + function foo() { + { + var baz = true; + + { + bar(); + } + } + } + + function bar() {} +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/expected.js new file mode 100644 index 000000000..217428cf6 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/hoisted/expected.js @@ -0,0 +1,13 @@ +(function () { + function a() { + { + var a = true; + + { + b(); + } + } + } + + function b() {} +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/actual.js new file mode 100644 index 000000000..a3c9bb03f --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/actual.js @@ -0,0 +1,3 @@ +class A {} +class B {} +eval(""); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/expected.js new file mode 100644 index 000000000..b153f29d4 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/expected.js @@ -0,0 +1,3 @@ +class A {} +class B {} +eval(""); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/options.json new file mode 100644 index 000000000..b66891133 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365-toplevel/options.json @@ -0,0 +1,3 @@ +{ + "topLevel": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/actual.js new file mode 100644 index 000000000..2eb389375 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/actual.js @@ -0,0 +1,5 @@ +function foo() { + eval(""); + class A {} + class B {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/expected.js new file mode 100644 index 000000000..f940f071e --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-365/expected.js @@ -0,0 +1,5 @@ +function foo() { + eval(""); + class A {} + class B {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/actual.js new file mode 100644 index 000000000..dfe7322ee --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/actual.js @@ -0,0 +1,8 @@ +!(function() { + function e(e) { + foo(e); + } + return function() { + return e(); + }; +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/expected.js new file mode 100644 index 000000000..d730ce9a2 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/issue-411/expected.js @@ -0,0 +1,8 @@ +!function () { + function a(a) { + foo(a); + } + return function () { + return a(); + }; +}(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/actual.js new file mode 100644 index 000000000..2f3618e95 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/actual.js @@ -0,0 +1,9 @@ +(function() { + class Foo {} + const Bar = class Bar extends Foo {}; + var foo = class Baz {}; + function bar() { + new foo(); + } + bar(); +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/expected.js new file mode 100644 index 000000000..9258a897a --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/expected.js @@ -0,0 +1,9 @@ +(function () { + class Foo {} + const b = class Bar extends Foo {}; + var c = class Baz {}; + function a() { + new c(); + } + a(); +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/options.json new file mode 100644 index 000000000..65cf0e8ad --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-class-name/options.json @@ -0,0 +1,3 @@ +{ + "keepClassName": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/actual.js new file mode 100644 index 000000000..25ad316d6 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/actual.js @@ -0,0 +1,11 @@ +(function() { + var foo = function foo() { + foo(); + }; + function bar() { + foo(); + } + bar(); + var baz = foo; + baz(); +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/expected.js new file mode 100644 index 000000000..32123742a --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/expected.js @@ -0,0 +1,11 @@ +(function () { + var a = function foo() { + foo(); + }; + function bar() { + a(); + } + bar(); + var b = a; + b(); +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/options.json new file mode 100644 index 000000000..285518e79 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/keep-fn-name/options.json @@ -0,0 +1,3 @@ +{ + "keepFnName": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/actual.js new file mode 100644 index 000000000..ad878a6a7 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/actual.js @@ -0,0 +1,6 @@ +function foo() { + meh: for (;;) { + var meh; + break meh; + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/expected.js new file mode 100644 index 000000000..0d15140c5 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-2/expected.js @@ -0,0 +1,6 @@ +function foo() { + meh: for (;;) { + var a; + break meh; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/actual.js new file mode 100644 index 000000000..f158168b5 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/actual.js @@ -0,0 +1,16 @@ +// https://phabricator.babeljs.io/T6957 +function foo() { + var meh; + meh: for (;;) { + break meh; + } + return meh; +} + +function f(a) { + try { + a: { + console.log(a); + } + } catch ($a) {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/expected.js new file mode 100644 index 000000000..41767dba6 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels-3/expected.js @@ -0,0 +1,16 @@ +// https://phabricator.babeljs.io/T6957 +function foo() { + var a; + meh: for (;;) { + break meh; + } + return a; +} + +function f(b) { + try { + a: { + console.log(b); + } + } catch (a) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/actual.js new file mode 100644 index 000000000..3aa5ee52b --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/actual.js @@ -0,0 +1,5 @@ +function foo() { + meh: for (;;) { + continue meh; + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/expected.js new file mode 100644 index 000000000..acd4dfcfc --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/labels/expected.js @@ -0,0 +1,5 @@ +function foo() { + meh: for (;;) { + continue meh; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/actual.js new file mode 100644 index 000000000..5cd7593b4 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/actual.js @@ -0,0 +1,7 @@ +function foo() { + var x = 2; + var xxx = 1; + if (xxx) { + console.log(xxx + x); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/expected.js new file mode 100644 index 000000000..fa5b33ae0 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/name-collisions/expected.js @@ -0,0 +1,7 @@ +function foo() { + var a = 2; + var b = 1; + if (b) { + console.log(b + a); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/actual.js new file mode 100644 index 000000000..945cd0268 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/actual.js @@ -0,0 +1,7 @@ +(function() { + for (let x in foo) { + for (let y in foo[x]) { + alert(foo[x][y]); + } + } +})(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/expected.js new file mode 100644 index 000000000..51a795303 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/nested-loops/expected.js @@ -0,0 +1,7 @@ +(function () { + for (let a in foo) { + for (let b in foo[a]) { + alert(foo[a][b]); + } + } +})(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/actual.js new file mode 100644 index 000000000..7443251af --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/actual.js @@ -0,0 +1,20 @@ +function foo() { + function bar(aaa, bbb, ccc) { + baz(aaa, bbb, ccc); + } + function baz() { + var baz = who(); + baz.bam(); + } + bar(); +} + +function foo2() { + (function bar() { + bar(); + return function() { + var bar = wow(); + bar.woo(); + }; + })(); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/expected.js new file mode 100644 index 000000000..6f168b66c --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/order-independence/expected.js @@ -0,0 +1,20 @@ +function foo() { + function a(a, c, d) { + b(a, c, d); + } + function b() { + var a = who(); + a.bam(); + } + a(); +} + +function foo2() { + (function a() { + a(); + return function () { + var a = wow(); + a.woo(); + }; + })(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/actual.js new file mode 100644 index 000000000..ee72385b3 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/actual.js @@ -0,0 +1,5 @@ +function bar() { + function foo(a, b, c) { + foo(a, b, c); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/expected.js new file mode 100644 index 000000000..1f65f46c5 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/recursion/expected.js @@ -0,0 +1,5 @@ +function bar() { + function d(e, a, b) { + d(e, a, b); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/actual.js new file mode 100644 index 000000000..360776da0 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/actual.js @@ -0,0 +1,250 @@ +function Foo() { + var a, + b, + c, + d, + e, + f, + g, + h, + i, + j, + k, + l, + m, + n, + o, + p, + q, + r, + s, + t, + u, + v, + w, + x, + y, + z; + var A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z; + var $, _; + a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; + A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; + $, _; + function Foo() { + var a, + b, + c, + d, + e, + f, + g, + i, + j, + k, + l, + m, + n, + o, + p, + q, + r, + s, + t, + u, + v, + w, + x, + y, + z; + var A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z; + var $, _; + a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z; + $, _; + function Foo() { + var a, + b, + c, + d, + e, + f, + g, + h, + i, + j, + k, + l, + m, + n, + o, + p, + q, + r, + s, + t, + u, + v, + w, + x, + y, + z; + var A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z; + var $, _; + a, + b, + c, + d, + e, + f, + g, + h, + i, + j, + k, + l, + m, + n, + o, + p, + q, + r, + s, + t, + u, + v, + w, + x, + y, + z; + A, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z; + $, _; + } + Foo(); + } + Foo(); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/expected.js new file mode 100644 index 000000000..d9bdcc365 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/reuse/expected.js @@ -0,0 +1,26 @@ +function Foo() { + var ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + var Z, $; + ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + Z, $; + function aa() { + var aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + var Z, $; + aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + Z, $; + function h() { + var aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + var Z, $; + aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; + z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; + Z, $; + } + h(); + } + aa(); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/actual.js new file mode 100644 index 000000000..870bdb448 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/actual.js @@ -0,0 +1,27 @@ +function a(a) { + for (a = 0; ; ); + for (a of x); + for (x of a); + for (a in x); + for (x in a); + for (; ; a++); + for (; ; a = 1); + + for (let b; ; ); + for (let b of x); + for (const b of x); + for (let b in x); + for (const b in x); + for (let [b, c] of x); + for (const [b, c] of x); + for (let [b, c] in x); + for (const [b, c] in x); + for (let { c: { b: { a } } } = x; ; ); + for ( + ; + ; + () => { + let a = 1; + } + ); +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/expected.js new file mode 100644 index 000000000..24c938f3f --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-2/expected.js @@ -0,0 +1,23 @@ +function a(b) { + for (b = 0;;); + for (b of x); + for (x of b); + for (b in x); + for (x in b); + for (;; b++); + for (;; b = 1); + + for (let a;;); + for (let a of x); + for (const a of x); + for (let a in x); + for (const a in x); + for (let [a, d] of x); + for (const [a, d] of x); + for (let [a, d] in x); + for (const [a, d] in x); + for (let { c: { b: { a: c } } } = x;;); + for (;; () => { + let b = 1; + }); +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/actual.js new file mode 100644 index 000000000..deb27cb99 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/actual.js @@ -0,0 +1,27 @@ +var a = function(a) { + for (a = 0; ; ); + for (a of x); + for (x of a); + for (a in x); + for (x in a); + for (; ; a++); + for (; ; a = 1); + + for (let b; ; ); + for (let b of x); + for (const b of x); + for (let b in x); + for (const b in x); + for (let [b, c] of x); + for (const [b, c] of x); + for (let [b, c] in x); + for (const [b, c] in x); + for (let { c: { b: { a } } } = x; ; ); + for ( + ; + ; + () => { + let a = 1; + } + ); +}; diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/expected.js new file mode 100644 index 000000000..55bba4313 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops-3/expected.js @@ -0,0 +1,23 @@ +var a = function (b) { + for (b = 0;;); + for (b of x); + for (x of b); + for (b in x); + for (x in b); + for (;; b++); + for (;; b = 1); + + for (let a;;); + for (let a of x); + for (const a of x); + for (let a in x); + for (const a in x); + for (let [a, d] of x); + for (const [a, d] of x); + for (let [a, d] in x); + for (const [a, d] in x); + for (let { c: { b: { a: c } } } = x;;); + for (;; () => { + let b = 1; + }); +}; \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/README.md b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/README.md new file mode 100644 index 000000000..0a6454659 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/README.md @@ -0,0 +1,5 @@ +Safari raises a syntax error for a `let` or `const` declaration in a `for` loop initialization that shadows a parent function's parameter. + ++ https://github.com/babel/minify/issues/559 ++ https://bugs.webkit.org/show_bug.cgi?id=171041 ++ https://trac.webkit.org/changeset/217200/webkit/trunk/Source diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/actual.js new file mode 100644 index 000000000..f04c6e4ee --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/actual.js @@ -0,0 +1,29 @@ +function a(a) { + { + for (a = 0; ; ); + for (a of x); + for (x of a); + for (a in x); + for (x in a); + for (; ; a++); + for (; ; a = 1); + + for (let a; ; ); + for (let a of x); + for (const a of x); + for (let a in x); + for (const a in x); + for (let [a, b] of x); + for (const [a, b] of x); + for (let [a, b] in x); + for (const [a, b] in x); + for (let { c: { b: { a } } } = x; ; ); + for ( + ; + ; + () => { + let a = 1; + } + ); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/expected.js new file mode 100644 index 000000000..81d69b1f3 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-shadowing-loops/expected.js @@ -0,0 +1,25 @@ +function a(b) { + { + for (b = 0;;); + for (b of x); + for (x of b); + for (b in x); + for (x in b); + for (;; b++); + for (;; b = 1); + + for (let b;;); + for (let b of x); + for (const b of x); + for (let b in x); + for (const b in x); + for (let [c, a] of x); + for (const [c, a] of x); + for (let [c, a] in x); + for (const [c, a] in x); + for (let { c: { b: { a: b } } } = x;;); + for (;; () => { + let b = 1; + }); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/actual.js new file mode 100644 index 000000000..3668628f6 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/actual.js @@ -0,0 +1,27 @@ +var a; + +for (a = 0; ; ); +for (a of x); +for (x of a); +for (a in x); +for (x in a); +for (; ; a++); +for (; ; a = 1); + +for (let b; ; ); +for (let b of x); +for (const b of x); +for (let b in x); +for (const b in x); +for (let [b, c] of x); +for (const [b, c] of x); +for (let [b, c] in x); +for (const [b, c] in x); +for (let { c: { b: { a } } } = x; ; ); +for ( + ; + ; + () => { + let a = 1; + } +); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/expected.js new file mode 100644 index 000000000..ba893cb32 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/safari-toplevel-loops/expected.js @@ -0,0 +1,23 @@ +var a; + +for (a = 0;;); +for (a of x); +for (x of a); +for (a in x); +for (x in a); +for (;; a++); +for (;; a = 1); + +for (let a;;); +for (let a of x); +for (const a of x); +for (let a in x); +for (const a in x); +for (let [a, b] of x); +for (const [a, b] of x); +for (let [a, b] in x); +for (const [a, b] in x); +for (let { c: { b: { a: b } } } = x;;); +for (;; () => { + let b = 1; +}); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/actual.js new file mode 100644 index 000000000..e0a89a050 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/actual.js @@ -0,0 +1,6 @@ +function bar() { + function foo(a, b, c) { + lol(a, b, c); + } + function lol() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/expected.js new file mode 100644 index 000000000..afdf5efd5 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadow-outer/expected.js @@ -0,0 +1,6 @@ +function bar() { + function a(e, a, b) { + d(e, a, b); + } + function d() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/actual.js new file mode 100644 index 000000000..836a81d5f --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/actual.js @@ -0,0 +1,8 @@ +function foo() { + function xx(bar, baz) { + return function(boo, foo) { + bar(boo, foo); + }; + } + function yy() {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/expected.js new file mode 100644 index 000000000..6a50e18ed --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing-2/expected.js @@ -0,0 +1,8 @@ +function foo() { + function a(a, b) { + return function (b, c) { + a(b, c); + }; + } + function b() {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/actual.js new file mode 100644 index 000000000..754820574 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/actual.js @@ -0,0 +1,7 @@ +var a = 1; +function foo() { + var xxx = 1; + if (xxx) { + console.log(xxx); + } +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/expected.js new file mode 100644 index 000000000..2a3994a70 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/shadowing/expected.js @@ -0,0 +1,7 @@ +var a = 1; +function foo() { + var a = 1; + if (a) { + console.log(a); + } +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/actual.js new file mode 100644 index 000000000..14079c89a --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/actual.js @@ -0,0 +1,4 @@ +function foo() { + var bar = 1; + var baz = 2; +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/expected.js new file mode 100644 index 000000000..e5dcdfded --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/expected.js @@ -0,0 +1,4 @@ +function a() { + var bar = 1; + var a = 2; +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/options.json new file mode 100644 index 000000000..f80655455 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel-and-exclude/options.json @@ -0,0 +1,7 @@ +{ + "exclude": { + "foo": false, + "bar": true + }, + "topLevel": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/actual.js new file mode 100644 index 000000000..b391b67ce --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/actual.js @@ -0,0 +1,14 @@ +function foo() { + if (FOO_ENV === "production") { + HELLO_WORLD.call(); + } +} +const FOO_ENV = "production"; +var HELLO_WORLD = function bar() { + new AbstractClass({ + [FOO_ENV]: "foo", + a: foo(HELLO_WORLD) + }); +}; +class AbstractClass {} +foo(); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/expected.js new file mode 100644 index 000000000..1067b4207 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/expected.js @@ -0,0 +1,14 @@ +function a() { + if (b === "production") { + c.call(); + } +} +const b = "production"; +var c = function e() { + new d({ + [b]: "foo", + a: a(c) + }); +}; +class d {} +a(); \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/options.json b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/options.json new file mode 100644 index 000000000..b66891133 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/toplevel/options.json @@ -0,0 +1,3 @@ +{ + "topLevel": true +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/actual.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/actual.js new file mode 100644 index 000000000..211194d27 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/actual.js @@ -0,0 +1,5 @@ +function xoo() { + var e; + try { + } catch (e) {} +} diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/expected.js b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/expected.js new file mode 100644 index 000000000..58cec1a38 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/fixtures/try-catch/expected.js @@ -0,0 +1,4 @@ +function xoo() { + var a; + try {} catch (a) {} +} \ No newline at end of file diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/index.js b/packages/babel-plugin-minify-mangle-names/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-minify-mangle-names/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js index 008ca2451..f543dffb3 100644 --- a/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js +++ b/packages/babel-plugin-minify-mangle-names/__tests__/mangle-names-test.js @@ -5,766 +5,33 @@ const thePlugin = require("test-transform")(mangler); describe("mangle-names", () => { thePlugin( - "should handle name collisions", + "should NOT mangle name arguments", ` - function foo() { - var x = 2; - var xxx = 1; - if (xxx) { - console.log(xxx + x); - } - } - `, - ` - function foo() { - var a = 2; - var b = 1; - if (b) { - console.log(b + a); - } - } - ` - ); - - thePlugin( - "should handle shadowing properly", - ` - var a = 1; - function foo() { - var xxx = 1; - if (xxx) { - console.log(xxx); - } - } - `, - ` - var a = 1; - function foo() { - var a = 1; - if (a) { - console.log(a); - } - } - ` - ); - - thePlugin( - "should not shadow outer references", - ` - function bar() { - function foo(a, b, c) { - lol(a,b,c); - } - function lol() {} - } - `, - ` - function bar() { - function a(e, a, b) { - d(e, a, b); - } - function d() {} - } - ` - ); - - thePlugin( - "should mangle args", - ` - function foo(xxx) { - if (xxx) { - console.log(xxx); - } - } - `, - ` - function foo(a) { - if (a) { - console.log(a); - } - } - ` - ); - - thePlugin( - "should not mangle labels", - ` - function foo() { - meh: for (;;) { - continue meh; - } - } - `, - ` - function foo() { - meh: for (;;) { - continue meh; - } - } - ` - ); - - thePlugin( - "should mangle variables with the same name as labels", - ` - function foo() { - meh: for (;;) { - var meh; - break meh; - } - } - `, - ` - function foo() { - meh: for (;;) { - var a; - break meh; - } - } - ` - ); - - // https://phabricator.babeljs.io/T6957 - thePlugin( - "labels should not shadow bindings", - ` - function foo() { - var meh; - meh: for (;;) { - break meh; - } - return meh; - } - - function f(a) { - try { - a: { - console.log(a); - } - } catch ($a) { } - } - `, - ` - function foo() { - var a; - meh: for (;;) { - break meh; - } - return a; - } - - function f(b) { - try { - a: { - console.log(b); - } - } catch (a) {} - } - ` - ); - - thePlugin( - "should be order independent", - ` - function foo() { - function bar(aaa, bbb, ccc) { - baz(aaa, bbb, ccc); - } - function baz() { - var baz = who(); - baz.bam(); - } - bar(); - } - - function foo2() { - (function bar() { - bar(); - return function() { - var bar = wow(); - bar.woo(); - }; - })(); - } - `, - ` - function foo() { - function a(a, c, d) { - b(a, c, d); - } - function b() { - var a = who(); - a.bam(); - } - a(); - } - - function foo2() { - (function a() { - a(); - return function () { - var a = wow(); - a.woo(); - }; - })(); - } - ` - ); - - thePlugin( - "should handle only thunk in function scopes", - ` - function foo() { - function xx(bar, baz) { - if (1) { - yy(bar, baz); - } - } - function yy(){} - } - `, - ` - function foo() { - function a(a, c) { - if (1) { - b(a, c); - } - } - function b() {} - } - ` - ); - - thePlugin( - "should be fine with shadowing 2", - ` - function foo() { - function xx(bar, baz) { - return function(boo, foo) { - bar(boo, foo); - }; - } - function yy(){} - } - `, - ` - function foo() { - function a(a, b) { - return function (b, c) { - a(b, c); - }; - } - function b() {} - } - ` - ); - - thePlugin( - "should not be confused by scopes", - ` - function foo() { - function bar() { - var baz; - if (baz) { - bam(); - } - } - function bam() {} - } - `, - ` - function foo() { - function a() { - var a; - if (a) { - b(); - } - } - function b() {} - } - ` - ); - - thePlugin( - "should not be confused by scopes (closures)", - ` - function foo() { - function bar(baz) { - return function() { - bam(); - }; - } - function bam() {} - } - `, - ` - function foo() { - function a(a) { - return function () { - b(); - }; - } - function b() {} - } - ` - ); - - thePlugin( - "should handle recursion", - ` - function bar() { - function foo(a, b, c) { - foo(a,b,c); - } - } - `, - ` - function bar() { - function d(e, a, b) { - d(e, a, b); - } - } - ` - ); - - thePlugin( - "should handle global name conflicts", - ` - function e() { - function foo() { - b = bar(); - } - function bar() {} - } - `, - ` - function e() { - function a() { - b = c(); - } - function c() {} - } - ` - ); - - thePlugin( - "should handle global names", - ` - function foo() { - var bar = 1; - var baz = 2; - } - `, - ` - function a() { - var bar = 1; - var a = 2; - } - `, - { - plugins: [ - [ - mangler, - { - exclude: { foo: false, bar: true }, - topLevel: true - } - ] - ] - } - ); - - thePlugin( - "should handle deeply nested paths with no bindings", - ` - function xoo() { - function foo(zz, xx, yy) { - function bar(zip, zap, zop) { - return function(bar) { - zap(); - return function() { - zip(); - } - } - } - } - } - `, - ` - function xoo() { - function a(a, b, c) { - function d(a, b, c) { - return function (c) { - b(); - return function () { - a(); - }; - }; - } - } - } - ` - ); - - thePlugin( - "should handle try...catch statements", - ` - function xoo() { - var e; - try {} catch (e) { - - } - } - `, - ` - function xoo() { - var a; - try {} catch (a) {} - } - ` - ); - - thePlugin( - "should not mangle vars in scope with eval", - ` - function foo() { - var inScopeOuter = 1; (function () { - var inScopeInner = 2; - eval("inScopeInner + inScopeOuter"); + var arguments = void 0; (function () { - var outOfScope = 1; - })(); + console.log(arguments); + })("argument"); })(); - } - `, ` - function foo() { - var inScopeOuter = 1; - (function () { - var inScopeInner = 2; - eval("inScopeInner + inScopeOuter"); - (function () { - var a = 1; - })(); - })(); - } - ` ); thePlugin( - "should mangle names with local eval bindings", - ` - function eval() {} - function foo() { - var bar = 1; - eval('...'); - } - `, + "should handle eval scopes", ` - function eval() {} - function foo() { - var a = 1; - eval('...'); - } - ` - ); - - thePlugin( - "should mangle names with option eval = true", - ` - function foo() { - var inScopeOuter = 1; - (function () { - var inScopeInner = 2; - eval("..."); - (function () { - var outOfScope = 1; - })(); - })(); - } - `, - ` - function foo() { - var a = 1; - (function () { - var a = 2; - eval("..."); - (function () { - var a = 1; - })(); - })(); - } - `, - { - plugins: [[mangler, { eval: true }]] - } - ); - - thePlugin( - "should keep mangled named consistent across scopes when defined later on", - ` - (function() { + function eval() {} function foo() { - { - var baz = true; - - { - bar(); - } - } - } - - function bar() {} - }()); - `, - ` - (function () { - function a() { - { - var a = true; - - { - b(); - } - } - } - - function b() {} - })(); - ` - ); - - thePlugin( - "should correctly mangle in nested loops", - ` - (function () { - for (let x in foo) { - for (let y in foo[x]) { - alert(foo[x][y]); - } - } - })(); - `, - ` - (function () { - for (let a in foo) { - for (let b in foo[a]) { - alert(foo[a][b]); - } - } - })(); - ` - ); - - thePlugin( - "should NOT mangle functions when keepFnName is true", - ` - (function() { - var foo = function foo() { - foo(); - } - function bar() { - foo(); - } - bar(); - var baz = foo; - baz(); - })(); - `, - ` - (function () { - var a = function foo() { - foo(); - }; - function bar() { - a(); - } - bar(); - var b = a; - b(); - })(); - `, - { - plugins: [[mangler, { keepFnName: true }]] - } - ); - - thePlugin( - "should NOT mangle classes when keepClassName is true", - ` - (function() { - class Foo {} - const Bar = class Bar extends Foo {} - var foo = class Baz {} - function bar() { - new foo(); - } - bar(); - })(); - `, - ` - (function () { - class Foo {} - const b = class Bar extends Foo {}; - var c = class Baz {}; - function a() { - new c(); + var bar = 1; + eval("..."); } - a(); - })(); - `, - { - plugins: [[mangler, { keepClassName: true }]] - } - ); - - thePlugin( - "should mangle variable re-declaration / K violations", - ` - !function () { - var foo = 1; - foo++; - var foo = 2; - foo++; - } - `, - ` - !function () { - var a = 1; - a++; - var a = 2; - a++; - }; - ` - ); - - thePlugin( - "should handle K violations - 2", + `, ` - !function () { - var bar = 1; - bar--; - var bar = 10; - foo(bar) + function eval() {} function foo() { - var foo = 10; - foo++; - var foo = 20; - foo(foo); - } - } - `, - ` - !function () { - var b = 1; - b--; - var b = 10; - a(b); - function a() { - var a = 10; - a++; - var a = 20; - a(a); - } - }; - ` - ); - - thePlugin( - "should work with redefinitions", - ` - (function () { - var x = y; - x = z; - x; - })(); - `, - ` - (function () { - var a = y; - a = z; - a; - })(); - ` - ); - - thePlugin( - "should reuse removed vars", - ` - function Foo() { - var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - var A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - var $, _; - a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - $, _; - function Foo() { - var a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - var A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - var $, _; - a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - $, _; - function Foo() { - var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - var A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - var $, _; - a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z; - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z; - $, _; - } - Foo(); - } - Foo(); - } - `, - ` - function Foo() { - var ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - var Z, $; - ba, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - Z, $; - function aa() { - var aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - var Z, $; - aa, a, b, c, d, e, f, g, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - Z, $; - function h() { - var aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - var z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - var Z, $; - aa, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y; - z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y; - Z, $; - } - h(); + var a = 1; + eval("..."); } - aa(); - } - ` - ); - - thePlugin( - "should mangle both referenced and binding identifiers with K violations", - ` - (function () { - var foo = bar, - foo = baz; - foo; - })(); - `, ` - (function () { - var a = bar, - a = baz; - a; - })(); - ` ); thePlugin( @@ -800,64 +67,6 @@ describe("mangle-names", () => { } ); - thePlugin( - "should find global scope properly", - ` - class A {} - class B extends A {} - (function () { - class C { - constructor() { - new A(); - new B(); - C; - } - } - })(); - `, - ` - class A {} - class B extends A {} - (function () { - class a { - constructor() { - new A(); - new B(); - a; - } - } - })(); - ` - ); - - thePlugin( - "should mangle classes properly", - ` - class A {} - class B {} - new A(); - new B(); - function a() { - class A {} - class B {} - new A(); - new B(); - } - `, - ` - class A {} - class B {} - new A(); - new B(); - function a() { - class a {} - class b {} - new a(); - new b(); - } - ` - ); - // https://github.com/babel/minify/issues/138 thePlugin( "should handle class exports in modules - issue#138", @@ -869,174 +78,6 @@ describe("mangle-names", () => { } ); - thePlugin( - "should not mangle the `arguments` variable", - ` - (function () { - var arguments = void 0; - (function () { - console.log(arguments); - })("argument"); - })(); - ` - ); - - thePlugin( - "should mangle top-level variables when topLevel option is true", - ` - function foo() { - if (FOO_ENV === "production") { - HELLO_WORLD.call(); - } - } - const FOO_ENV = "production"; - var HELLO_WORLD = function bar() { - new AbstractClass({ - [FOO_ENV]: "foo", - a: foo(HELLO_WORLD) - }); - }; - class AbstractClass {} - foo(); - `, - ` - function a() { - if (b === "production") { - c.call(); - } - } - const b = "production"; - var c = function e() { - new d({ - [b]: "foo", - a: a(c) - }); - }; - class d {} - a(); - `, - { - plugins: [[mangler, { topLevel: true }]] - } - ); - - thePlugin( - "should fix #326, #369 - destructuring", - ` - // issue#326 - function a() { - let foo, bar, baz; - ({foo, bar, baz} = {}); - return {foo, bar, baz}; - } - // issue#369 - function decodeMessage(message){ - let namespace; - let name; - let value = null; - - [, namespace, name, value] = message.split(',') || []; - console.log(name); - } - `, - ` - // issue#326 - function a() { - let a, b, c; - ({ foo: a, bar: b, baz: c } = {}); - return { foo: a, bar: b, baz: c }; - } - // issue#369 - function decodeMessage(a) { - let b; - let c; - let d = null; - - [, b, c, d] = a.split(',') || []; - console.log(c); - } - ` - ); - - thePlugin( - "should rename binding.identifier - issue#411", - ` - !function () { - function e(e) { - foo(e); - } - return function () { - return e(); - }; - }(); - `, - ` - !function () { - function a(a) { - foo(a); - } - return function () { - return a(); - }; - }(); - ` - ); - - thePlugin( - "should fix issue#365 - classDeclaration with unsafe parent scope", - ` - function foo() { - eval(""); - class A {} - class B {} - } - ` - ); - - thePlugin( - "should fix classDeclaration with unsafe program scope", - ` - class A {} - class B {} - eval(""); - `, - { - plugins: [[mangler, { topLevel: true }]] - } - ); - - thePlugin( - "should handle constant violations across multiple blocks", - ` - function foo() { - var x;x;x; - { - var x;x;x; - function y() { - var x;x;x; - { - var x;x;x; - } - } - } - } - `, - ` - function foo() { - var a;a;a; - { - var a;a;a; - function b() { - var a;a;a; - { - var a;a;a; - } - } - } - } - ` - ); - thePlugin( "should work with if_return optimization changing function scope", ` @@ -1103,343 +144,4 @@ describe("mangle-names", () => { plugins: [[mangler, { topLevel: true }]] } ); - - // Safari raises a syntax error for a `let` or `const` declaration in a `for` - // loop initialization that shadows a parent function's parameter. - // https://github.com/babel/minify/issues/559 - // https://bugs.webkit.org/show_bug.cgi?id=171041 - // https://trac.webkit.org/changeset/217200/webkit/trunk/Source - describe("Safari for loop lexical scope workaround", () => { - thePlugin( - "should permit shadowing in top-level for loops", - ` - var a; - - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [b, c] of x); - for (const [b, c] of x); - for (let [b, c] in x); - for (const [b, c] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - `, - ` - var a; - - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, b] of x); - for (const [a, b] of x); - for (let [a, b] in x); - for (const [a, b] in x); - for (let { c: { b: { a: b } } } = x;;); - for (;; () => { - let b = 1; - }); - ` - ); - - thePlugin( - "should permit shadowing in nested for loops", - ` - function a(a) { - { - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, b] of x); - for (const [a, b] of x); - for (let [a, b] in x); - for (const [a, b] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - } - } - `, - ` - function a(b) { - { - for (b = 0;;); - for (b of x); - for (x of b); - for (b in x); - for (x in b); - for (;; b++); - for (;; b = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [c, a] of x); - for (const [c, a] of x); - for (let [c, a] in x); - for (const [c, a] in x); - for (let { c: { b: { a: b } } } = x;;); - for (;; () => { - let b = 1; - }); - } - } - ` - ); - - thePlugin( - "should not shadow params in function declaration top-level for loops", - ` - function a(a) { - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [b, c] of x); - for (const [b, c] of x); - for (let [b, c] in x); - for (const [b, c] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - } - `, - ` - function a(b) { - for (b = 0;;); - for (b of x); - for (x of b); - for (b in x); - for (x in b); - for (;; b++); - for (;; b = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, d] of x); - for (const [a, d] of x); - for (let [a, d] in x); - for (const [a, d] in x); - for (let { c: { b: { a: c } } } = x;;); - for (;; () => { - let b = 1; - }); - } - ` - ); - - thePlugin( - "should not shadow params in function expression top-level for loops", - ` - var a = function (a) { - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [b, c] of x); - for (const [b, c] of x); - for (let [b, c] in x); - for (const [b, c] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - }; - `, - ` - var a = function (b) { - for (b = 0;;); - for (b of x); - for (x of b); - for (b in x); - for (x in b); - for (;; b++); - for (;; b = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, d] of x); - for (const [a, d] of x); - for (let [a, d] in x); - for (const [a, d] in x); - for (let { c: { b: { a: c } } } = x;;); - for (;; () => { - let b = 1; - }); - }; - ` - ); - - thePlugin( - "should not shadow params in arrow function top-level for loops", - ` - var a = (a) => { - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [b, c] of x); - for (const [b, c] of x); - for (let [b, c] in x); - for (const [b, c] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - }; - `, - ` - var a = (b) => { - for (b = 0;;); - for (b of x); - for (x of b); - for (b in x); - for (x in b); - for (;; b++); - for (;; b = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, d] of x); - for (const [a, d] of x); - for (let [a, d] in x); - for (const [a, d] in x); - for (let { c: { b: { a: c } } } = x;;); - for (;; () => { - let b = 1; - }); - }; - ` - ); - - thePlugin( - "should not shadow params in class method top-level for loops", - ` - class a { - a(a) { - for (a = 0;;); - for (a of x); - for (x of a); - for (a in x); - for (x in a); - for (;; a++); - for (;; a = 1); - - for (let b;;); - for (let b of x); - for (const b of x); - for (let b in x); - for (const b in x); - for (let [b, c] of x); - for (const [b, c] of x); - for (let [b, c] in x); - for (const [b, c] in x); - for (let { c: { b: { a } } } = x;;); - for (;; () => { - let a = 1; - }); - } - } - `, - ` - class a { - a(b) { - for (b = 0;;); - for (b of x); - for (x of b); - for (b in x); - for (x in b); - for (;; b++); - for (;; b = 1); - - for (let a;;); - for (let a of x); - for (const a of x); - for (let a in x); - for (const a in x); - for (let [a, d] of x); - for (const [a, d] of x); - for (let [a, d] in x); - for (const [a, d] in x); - for (let { c: { b: { a: c } } } = x;;); - for (;; () => { - let b = 1; - }); - } - } - ` - ); - }); });