From 322d608246cbef622e0b34b440ae3d65475cd2cd Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Mon, 13 Nov 2017 17:25:42 +0100 Subject: [PATCH] refactor(tests): Tests to fixtures - inlineConsecutiveAdds --- .../fixtures/array-non-int-index-2/actual.js | 2 + .../array-non-int-index-2/expected.js | 1 + .../fixtures/array-non-int-index/actual.js | 5 + .../fixtures/array-non-int-index/expected.js | 5 + .../fixtures/array-out-of-bounds/actual.js | 3 + .../fixtures/array-out-of-bounds/expected.js | 3 + .../fixtures/array-overwrites/actual.js | 2 + .../fixtures/array-overwrites/expected.js | 2 + .../array-property-assignments-2/actual.js | 2 + .../array-property-assignments-2/expected.js | 2 + .../array-property-assignments/actual.js | 4 + .../array-property-assignments/expected.js | 1 + .../__tests__/fixtures/array-push/actual.js | 3 + .../__tests__/fixtures/array-push/expected.js | 1 + .../__tests__/fixtures/basic/actual.js | 10 + .../__tests__/fixtures/basic/expected.js | 13 + .../circular-references-array/actual.js | 2 + .../circular-references-array/expected.js | 2 + .../circular-references-set/actual.js | 2 + .../circular-references-set/expected.js | 2 + .../fixtures/circular-references/actual.js | 2 + .../fixtures/circular-references/expected.js | 2 + .../fixtures/computed-properties-2/actual.js | 6 + .../computed-properties-2/expected.js | 6 + .../fixtures/computed-properties/actual.js | 6 + .../fixtures/computed-properties/expected.js | 8 + .../fixtures/dependent-properties/actual.js | 5 + .../fixtures/dependent-properties/expected.js | 7 + .../indirect-dependent-properties-2/actual.js | 19 + .../expected.js | 21 ++ .../indirect-dependent-properties/actual.js | 10 + .../indirect-dependent-properties/expected.js | 12 + .../fixtures/last-expr-stmt/actual.js | 3 + .../fixtures/last-expr-stmt/expected.js | 5 + .../fixtures/non-collapsable-lval/actual.js | 9 + .../fixtures/non-collapsable-lval/expected.js | 9 + .../__tests__/fixtures/set-add/actual.js | 6 + .../__tests__/fixtures/set-add/expected.js | 4 + .../__tests__/index.js | 2 + .../transform-inline-consecutive-adds-test.js | 324 ------------------ 40 files changed, 209 insertions(+), 324 deletions(-) create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/actual.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/expected.js create mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/index.js delete mode 100644 packages/babel-plugin-transform-inline-consecutive-adds/__tests__/transform-inline-consecutive-adds-test.js diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/actual.js new file mode 100644 index 000000000..309961460 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/actual.js @@ -0,0 +1,2 @@ +var foo = []; +foo["2"] = "blah"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/expected.js new file mode 100644 index 000000000..b8ccd7d6b --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index-2/expected.js @@ -0,0 +1 @@ +var foo = [,, "blah"]; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/actual.js new file mode 100644 index 000000000..72dc74eef --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/actual.js @@ -0,0 +1,5 @@ +var foo = []; +foo[2.1] = "blah"; + +var bar = []; +bar["2.1"] = "blah"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/expected.js new file mode 100644 index 000000000..d0cfce008 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-non-int-index/expected.js @@ -0,0 +1,5 @@ +var foo = []; +foo[2.1] = "blah"; + +var bar = []; +bar["2.1"] = "blah"; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/actual.js new file mode 100644 index 000000000..503a4b894 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/actual.js @@ -0,0 +1,3 @@ +var foo = [1, 2]; +foo[2] = "blah"; +foo[2] = "ok"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/expected.js new file mode 100644 index 000000000..e75d5c6bd --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-out-of-bounds/expected.js @@ -0,0 +1,3 @@ +var foo = [1, 2]; +foo[2] = "blah"; +foo[2] = "ok"; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/actual.js new file mode 100644 index 000000000..4325bfd5b --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/actual.js @@ -0,0 +1,2 @@ +var foo = [1, 2, 3]; +foo[2] = "blah"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/expected.js new file mode 100644 index 000000000..8240d3eb8 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-overwrites/expected.js @@ -0,0 +1,2 @@ +var foo = [1, 2, 3]; +foo[2] = "blah"; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/actual.js new file mode 100644 index 000000000..e0d1a87d8 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/actual.js @@ -0,0 +1,2 @@ +var foo = []; +foo[10] = "blah"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/expected.js new file mode 100644 index 000000000..e0acc1b96 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments-2/expected.js @@ -0,0 +1,2 @@ +var foo = []; +foo[10] = "blah"; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/actual.js new file mode 100644 index 000000000..15e6f87bc --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/actual.js @@ -0,0 +1,4 @@ +var foo = []; +foo[5] = "blah"; +foo[3] = "blah"; +foo[7] = "blah"; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/expected.js new file mode 100644 index 000000000..9e68fe011 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-property-assignments/expected.js @@ -0,0 +1 @@ +var foo = [,,, "blah",, "blah",, "blah"]; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/actual.js new file mode 100644 index 000000000..c477fe31d --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/actual.js @@ -0,0 +1,3 @@ +var foo = [1, 2]; +foo.push(3, 4), foo.push(5); +foo.push(6); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/expected.js new file mode 100644 index 000000000..6fde07ace --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/array-push/expected.js @@ -0,0 +1 @@ +var foo = [1, 2, 3, 4, 5, 6]; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/actual.js new file mode 100644 index 000000000..ca7834d5b --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/actual.js @@ -0,0 +1,10 @@ +const foo = { + z: 3.0 +}; +foo.a = 42; +foo.b = ["hi"]; +foo.c = bar(); +foo.d = "str"; + +var bar = {}; +(bar.a = 0), (bar.b = 2); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/expected.js new file mode 100644 index 000000000..c4336c78a --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/basic/expected.js @@ -0,0 +1,13 @@ +const foo = { + z: 3.0, + a: 42, + b: ["hi"], + c: bar(), + d: "str" +}; + + +var bar = { + a: 0, + b: 2 +}; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/actual.js new file mode 100644 index 000000000..68e8ff741 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/actual.js @@ -0,0 +1,2 @@ +var foo = []; +foo[2] = foo; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/expected.js new file mode 100644 index 000000000..252848846 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-array/expected.js @@ -0,0 +1,2 @@ +var foo = []; +foo[2] = foo; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/actual.js new file mode 100644 index 000000000..c1f105ea6 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/actual.js @@ -0,0 +1,2 @@ +var foo = new Set([1, 2]); +foo.add(foo); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/expected.js new file mode 100644 index 000000000..3eea963db --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references-set/expected.js @@ -0,0 +1,2 @@ +var foo = new Set([1, 2]); +foo.add(foo); \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/actual.js new file mode 100644 index 000000000..e9c45a3b1 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/actual.js @@ -0,0 +1,2 @@ +var foo = {}; +foo.bar = foo; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/expected.js new file mode 100644 index 000000000..b7a414230 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/circular-references/expected.js @@ -0,0 +1,2 @@ +var foo = {}; +foo.bar = foo; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/actual.js new file mode 100644 index 000000000..f3e295bb4 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/actual.js @@ -0,0 +1,6 @@ +var foo = {}; +foo[bar()] = 0; +function bar() { + console.log(foo); + return 0; +} diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/expected.js new file mode 100644 index 000000000..5efc01a6a --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties-2/expected.js @@ -0,0 +1,6 @@ +var foo = {}; +foo[bar()] = 0; +function bar() { + console.log(foo); + return 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/actual.js new file mode 100644 index 000000000..0f9b5e1d4 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/actual.js @@ -0,0 +1,6 @@ +var foo = {}; +foo["a"] = 0; +foo[4] = 1; + +var bar = {}; +bar[global] = 0; diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/expected.js new file mode 100644 index 000000000..ba32353b5 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/computed-properties/expected.js @@ -0,0 +1,8 @@ +var foo = { + "a": 0, + 4: 1 +}; + + +var bar = {}; +bar[global] = 0; \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/actual.js new file mode 100644 index 000000000..53df93cbf --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/actual.js @@ -0,0 +1,5 @@ +const foo = {}; +foo.a = function() { + console.log(3); +}; +foo.b = foo.a(); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/expected.js new file mode 100644 index 000000000..7715f605e --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/dependent-properties/expected.js @@ -0,0 +1,7 @@ +const foo = { + a: function () { + console.log(3); + } +}; + +foo.b = foo.a(); \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/actual.js new file mode 100644 index 000000000..27bdc9353 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/actual.js @@ -0,0 +1,19 @@ +var foo = {}; +foo.a = 4; +foo.b = cat(); +function cat() { + return bar(); + function bar() { + console.log(foo); + return 0; + } +} + +function baz() { + var foo = {}; + (foo.a = 0), (foo.b = bar()); + function bar() { + console.log(foo); + return 0; + } +} diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/expected.js new file mode 100644 index 000000000..0665956aa --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties-2/expected.js @@ -0,0 +1,21 @@ +var foo = { + a: 4 +}; + +foo.b = cat(); +function cat() { + return bar(); + function bar() { + console.log(foo); + return 0; + } +} + +function baz() { + var foo = {}; + foo.a = 0, foo.b = bar(); + function bar() { + console.log(foo); + return 0; + } +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/actual.js new file mode 100644 index 000000000..200c262ae --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/actual.js @@ -0,0 +1,10 @@ +var foo = {}; +foo.a = 4; +foo.b = cat(); +function cat() { + return bar(); +} +function bar() { + console.log(foo); + return 0; +} diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/expected.js new file mode 100644 index 000000000..6a3b96c8c --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/indirect-dependent-properties/expected.js @@ -0,0 +1,12 @@ +var foo = { + a: 4 +}; + +foo.b = cat(); +function cat() { + return bar(); +} +function bar() { + console.log(foo); + return 0; +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/actual.js new file mode 100644 index 000000000..d3efab78f --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/actual.js @@ -0,0 +1,3 @@ +const foo = {}; +foo.a = 42; +console.log(foo); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/expected.js new file mode 100644 index 000000000..706cbb07c --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/last-expr-stmt/expected.js @@ -0,0 +1,5 @@ +const foo = { + a: 42 +}; + +console.log(foo); \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/actual.js new file mode 100644 index 000000000..87a3997d8 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/actual.js @@ -0,0 +1,9 @@ +function a() { + const foo = {}; + foo.bar.a = 42; +} + +function b() { + const foo = {}; + bar.a = 42; +} diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/expected.js new file mode 100644 index 000000000..aca2b3403 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/non-collapsable-lval/expected.js @@ -0,0 +1,9 @@ +function a() { + const foo = {}; + foo.bar.a = 42; +} + +function b() { + const foo = {}; + bar.a = 42; +} \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/actual.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/actual.js new file mode 100644 index 000000000..472192585 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/actual.js @@ -0,0 +1,6 @@ +var foo = new Set(); +foo.add(1), foo.add(2); +foo.add(3); + +var bar = new Set([1, 2]); +bar.add(3); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/expected.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/expected.js new file mode 100644 index 000000000..c6d0ad546 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/fixtures/set-add/expected.js @@ -0,0 +1,4 @@ +var foo = new Set([1, 2, 3]); + + +var bar = new Set([1, 2, 3]); \ No newline at end of file diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/index.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/index.js new file mode 100644 index 000000000..d7c81a111 --- /dev/null +++ b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/index.js @@ -0,0 +1,2 @@ +const runner = require("test-runner"); +runner(__dirname); diff --git a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/transform-inline-consecutive-adds-test.js b/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/transform-inline-consecutive-adds-test.js deleted file mode 100644 index d8d8b2c90..000000000 --- a/packages/babel-plugin-transform-inline-consecutive-adds/__tests__/transform-inline-consecutive-adds-test.js +++ /dev/null @@ -1,324 +0,0 @@ -jest.autoMockOff(); - -const thePlugin = require("test-transform")(require("../src/index")); - -describe("transform-inline-consecutive-adds-plugin", () => { - thePlugin( - "should collapse simple consecutive assignments", - ` - const foo = { - z: 3.0 - }; - foo.a = 42; - foo.b = ["hi"]; - foo.c = bar(); - foo.d = "str"; - `, - ` - const foo = { - z: 3.0, - a: 42, - b: ["hi"], - c: bar(), - d: "str" - }; - ` - ); - - thePlugin( - "should collapse only up to the last ExpressionStatement", - ` - const foo = {}; - foo.a = 42; - console.log(foo); - `, - ` - const foo = { - a: 42 - }; - - console.log(foo); - ` - ); - - thePlugin( - "should not collapse if the lval is a nested MemberExpression", - ` - const foo = {}; - foo.bar.a = 42; - ` - ); - - thePlugin( - "should not collapse if the lval is different from the one in hte previous line", - ` - const foo = {}; - bar.a = 42; - ` - ); - - thePlugin( - "should not collapse if the property directly depends on another property", - ` - const foo = {}; - foo.a = function () { - console.log(3); - }; - foo.b = foo.a(); - `, - ` - const foo = { - a: function () { - console.log(3); - } - }; - - foo.b = foo.a(); - ` - ); - - thePlugin( - "should not collapse if the property indirectly depends on another property", - ` - var foo = {}; - foo.a = 4; - foo.b = cat(); - function cat() { - return bar(); - } - function bar() { - console.log(foo); - return 0; - } - `, - ` - var foo = { - a: 4 - }; - - foo.b = cat(); - function cat() { - return bar(); - } - function bar() { - console.log(foo); - return 0; - } - ` - ); - - thePlugin( - "should not collapse if the property indirectly depends on another property inside a nested function", - ` - var foo = {}; - foo.a = 4; - foo.b = cat(); - function cat() { - return bar(); - function bar() { - console.log(foo); - return 0; - } - } - `, - ` - var foo = { - a: 4 - }; - - foo.b = cat(); - function cat() { - return bar(); - function bar() { - console.log(foo); - return 0; - } - } - ` - ); - - thePlugin( - "should collapse computed properties if they are literals", - ` - var foo = {}; - foo["a"] = 0; - foo[4] = 1; - `, - ` - var foo = { - "a": 0, - 4: 1 - }; - ` - ); - - thePlugin( - "should not collapse computed properties otherwise", - ` - var foo = {}; - foo[global] = 0; - ` - ); - - thePlugin( - "should not collapse computed properties whose key depends on the object", - ` - var foo = {}; - foo[bar()] = 0; - function bar() { - console.log(foo); - return 0; - } - ` - ); - - thePlugin( - "should not collapse computed properties with circular references", - ` - var foo = {}; - foo.bar = foo; - ` - ); - - thePlugin( - "should collapse statements with multiple assignments", - ` - var foo = {}; - foo.a = 0, foo.b = 2; - `, - ` - var foo = { - a: 0, - b: 2 - }; - ` - ); - - thePlugin( - "should not collapse statements with multiple assignments and dependency issues", - ` - var foo = {}; - foo.a = 0, foo.b = bar(); - function bar() { - console.log(foo); - return 0; - } - ` - ); - - thePlugin( - "should collapse `Array#push` calls", - ` - var foo = [1, 2]; - foo.push(3, 4), foo.push(5); - foo.push(6); - `, - ` - var foo = [1, 2, 3, 4, 5, 6]; - ` - ); - - thePlugin( - "should collapse `Set#add` calls", - ` - var foo = new Set(); - foo.add(1), foo.add(2); - foo.add(3); - `, - ` - var foo = new Set([1, 2, 3]); - ` - ); - - thePlugin( - "should collapse `Set#add` calls with array-initialized sets", - ` - var foo = new Set([1, 2]); - foo.add(3); - `, - ` - var foo = new Set([1, 2, 3]); - ` - ); - - thePlugin( - "should not collapse statements for array-initialized sets with circular references", - ` - var foo = new Set([1, 2]); - foo.add(foo); - ` - ); - - thePlugin( - "should collapse array property assignments", - ` - var foo = []; - foo[5] = 'blah'; - foo[3] = 'blah'; - foo[7] = 'blah'; - `, - ` - var foo = [,,, 'blah',, 'blah',, 'blah']; - ` - ); - - thePlugin( - "should not collapse array property assignments if it doesn’t make the code shorter", - ` - var foo = []; - foo[10] = 'blah'; - ` - ); - - thePlugin( - "should not collapse array property assignments if they override properties assigned in the inital declaration", - ` - var foo = [1, 2, 3]; - foo[2] = 'blah'; - ` - ); - - thePlugin( - "should not collapse array property assignments if they override properties assigned outside of the initial declaration", - ` - var foo = [1, 2]; - foo[2] = 'blah'; - foo[2] = 'ok'; - ` - ); - - thePlugin( - "should not collapse array property assignments if the index is a float", - ` - var foo = []; - foo[2.1] = 'blah'; - ` - ); - - thePlugin( - "should not collapse array property assignments if index is a float written as a string", - ` - var foo = []; - foo['2.1'] = 'blah'; - ` - ); - - thePlugin( - "should collapse array property assignments if index is an integer written as string", - ` - var foo = []; - foo['2'] = 'blah'; - `, - ` - var foo = [,, 'blah']; - ` - ); - - thePlugin( - "should not collapse array property assignments if the rval is a circular reference", - ` - var foo = []; - foo[2] = foo; - ` - ); -});