From d79ed0fc925fd9c5dc721fad46f923c8736cef38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 11 Apr 2022 15:35:27 -0400 Subject: [PATCH] test: more stringent ordering test --- .../src/util.ts | 1 + .../array-pattern-with-rest/exec.js | 24 ++++++++++----- .../ordering--es2015/array-pattern/exec.js | 20 ++++++++----- .../object-pattern-with-rest/exec.js | 24 ++++++++------- .../ordering--es2015/object-pattern/exec.js | 20 ++++++++----- .../fixtures/ordering--es2015/options.json | 1 + .../exec.js | 29 +++++++++++++++++++ .../ordering/array-pattern-with-rest/exec.js | 24 ++++++++++----- .../fixtures/ordering/array-pattern/exec.js | 20 ++++++++----- .../ordering/object-pattern-with-rest/exec.js | 24 ++++++++------- .../fixtures/ordering/object-pattern/exec.js | 20 ++++++++----- 11 files changed, 137 insertions(+), 70 deletions(-) create mode 100644 packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/.array-pattern-side-effect-iterable/exec.js diff --git a/packages/babel-plugin-proposal-destructuring-private/src/util.ts b/packages/babel-plugin-proposal-destructuring-private/src/util.ts index e7b13fafe105..a8bf9ba89c75 100644 --- a/packages/babel-plugin-proposal-destructuring-private/src/util.ts +++ b/packages/babel-plugin-proposal-destructuring-private/src/util.ts @@ -430,6 +430,7 @@ export function* transformPrivateKeyDestructuring( // in RHS. Otherwise we have to pause the iterable and interleave // the expressions. // See also https://gist.github.com/nicolo-ribaudo/f8ac7916f89450f2ead77d99855b2098 + // and ordering/array-pattern-side-effect-iterable test const leftElements = left.elements; const leftElementsAfterIndex = leftElements.splice(index); const { elements, transformed } = buildAssignmentsFromPatternList( diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern-with-rest/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern-with-rest/exec.js index 42b2f89bd467..38bf12b34320 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern-with-rest/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern-with-rest/exec.js @@ -2,17 +2,25 @@ var log = []; function push(x, y = x) { log.push(x); return y; } +var log = []; + +function push(x, y = x) { log.push(x); return y; } + class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var [{ [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) }, ...{ [push(10)]: e = push(11), ...f }] = [C]; + var [{ [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) }, ...{ [push(15)]: e = push(16), ...f }] = [C]; } } -var nums = Array.from({ length: 12 }, (_, i) => i); +var nums = Array.from({ length: 17 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern/exec.js index 280a7a1a424e..f459199da656 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/array-pattern/exec.js @@ -3,16 +3,20 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var [{ [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) }, e = push(10)] = [C]; + var [{ [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) }, e = push(15)] = [C]; } } -var nums = Array.from({ length: 11 }, (_, i) => i); +var nums = Array.from({ length: 16 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern-with-rest/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern-with-rest/exec.js index 46e9cfe5b3f6..47b7210eb0eb 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern-with-rest/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern-with-rest/exec.js @@ -3,19 +3,21 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; + static get #z() { push(15) } static { - var { [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7), - #x: x = push(8), - [push(9)]: d = push(10), - ...e - } = push(2, C), [push(11)]: d = push(12), #y: z = push(13), ...f } = C; + var { [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14), #z: z = push(16), ...f } = C; } } -var nums = Array.from({ length: 14 }, (_, i) => i); +var nums = Array.from({ length: 17 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern/exec.js index bf9aedfe8ca0..e7a7d9d08e11 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/object-pattern/exec.js @@ -3,16 +3,20 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var { [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) } = C; + var { [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) } = C; } } -var nums = Array.from({ length: 10 }, (_, i) => i); +var nums = Array.from({ length: 15 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/options.json b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/options.json index 8099cdd9d774..e1c5858604ed 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/options.json +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering--es2015/options.json @@ -3,6 +3,7 @@ "proposal-destructuring-private", "proposal-class-static-block", "proposal-class-properties", + "proposal-private-methods", ["proposal-object-rest-spread", { "useBuiltIns": true }] ] } diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/.array-pattern-side-effect-iterable/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/.array-pattern-side-effect-iterable/exec.js new file mode 100644 index 000000000000..d2b79d1a537d --- /dev/null +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/.array-pattern-side-effect-iterable/exec.js @@ -0,0 +1,29 @@ +var log = []; + +function push(x, y = x) { log.push(x); return y; } + +class C { + static get a() { push(2) } + static get b() { push(7) } + static get c() { push(11) } + static get d() { push(15) } + static get #x() { push(4) }; + static get #y() { return push(9, C) }; + static { + function *iterator() { + push(0); + yield C; + push(13); + yield C; + } + + var [{ [push(1, "a")]: a = push(3), #x: { + [push(6, "b")]: b = push(8), + #y: y = push(-1), + [push(10, "c")]: c = push(12) + } = push(5, C) }, { [push(14, "d")]: d = push(16) }] = iterator(); + } +} + +var nums = Array.from({ length: 16 }, (_, i) => i); +expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern-with-rest/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern-with-rest/exec.js index 42b2f89bd467..38bf12b34320 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern-with-rest/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern-with-rest/exec.js @@ -2,17 +2,25 @@ var log = []; function push(x, y = x) { log.push(x); return y; } +var log = []; + +function push(x, y = x) { log.push(x); return y; } + class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var [{ [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) }, ...{ [push(10)]: e = push(11), ...f }] = [C]; + var [{ [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) }, ...{ [push(15)]: e = push(16), ...f }] = [C]; } } -var nums = Array.from({ length: 12 }, (_, i) => i); +var nums = Array.from({ length: 17 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern/exec.js index 280a7a1a424e..f459199da656 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/array-pattern/exec.js @@ -3,16 +3,20 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var [{ [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) }, e = push(10)] = [C]; + var [{ [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) }, e = push(15)] = [C]; } } -var nums = Array.from({ length: 11 }, (_, i) => i); +var nums = Array.from({ length: 16 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern-with-rest/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern-with-rest/exec.js index 46e9cfe5b3f6..47b7210eb0eb 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern-with-rest/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern-with-rest/exec.js @@ -3,19 +3,21 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; + static get #z() { push(15) } static { - var { [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7), - #x: x = push(8), - [push(9)]: d = push(10), - ...e - } = push(2, C), [push(11)]: d = push(12), #y: z = push(13), ...f } = C; + var { [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14), #z: z = push(16), ...f } = C; } } -var nums = Array.from({ length: 14 }, (_, i) => i); +var nums = Array.from({ length: 17 }, (_, i) => i); expect(log).toStrictEqual(nums); diff --git a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern/exec.js b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern/exec.js index bf9aedfe8ca0..e7a7d9d08e11 100644 --- a/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern/exec.js +++ b/packages/babel-plugin-proposal-destructuring-private/test/fixtures/ordering/object-pattern/exec.js @@ -3,16 +3,20 @@ var log = []; function push(x, y = x) { log.push(x); return y; } class C { - static #x; - static #y; + static get a() { push(1) } + static get b() { push(6) } + static get c() { push(10) } + static get d() { push(13) } + static get #x() { push(3) }; + static get #y() { return push(8, C) }; static { - var { [push(0)]: a = push(1), #x: { - [push(3)]: b = push(4), - #y: y = push(5), - [push(6)]: c = push(7) - } = push(2, C), [push(8)]: d = push(9) } = C; + var { [push(0, "a")]: a = push(2), #x: { + [push(5, "b")]: b = push(7), + #y: y = push(-1), + [push(9, "c")]: c = push(11) + } = push(4, C), [push(12, "d")]: d = push(14) } = C; } } -var nums = Array.from({ length: 10 }, (_, i) => i); +var nums = Array.from({ length: 15 }, (_, i) => i); expect(log).toStrictEqual(nums);