mirror of
https://github.com/swc-project/swc.git
synced 2024-10-05 04:39:06 +03:00
fix(es/compat): Fix destructuring
(#3104)
swc_ecma_transforms_compat: - `destructuring`: Handle assignment expressions in rhs of variable declarators correctly. (Closes #2850)
This commit is contained in:
parent
8aff5ae0aa
commit
9f5a8f728a
@ -1,10 +1,9 @@
|
||||
var a, b;
|
||||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
||||
try {
|
||||
var ref, ref1;
|
||||
for(var _iterator = [][Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
||||
var ref2;
|
||||
ref2 = _step.value, ref = 1, b = ref, ref1 = "", a = ref1, ref2;
|
||||
var ref, ref1, ref2;
|
||||
ref = _step.value, ref1 = ref.a, b = ref1 === void 0 ? 1 : ref1, ref2 = ref.b, a = ref2 === void 0 ? "" : ref2, ref;
|
||||
a;
|
||||
b;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
||||
try {
|
||||
for(var _step, _iterator = [][Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_step.value;
|
||||
for(var ref, ref1, ref2, _step, _iterator = [][Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)ref1 = (ref = _step.value).a, void 0 === ref1, ref2 = ref.b, void 0 === ref2;
|
||||
} catch (err) {
|
||||
_didIteratorError = !0, _iteratorError = err;
|
||||
} finally{
|
||||
|
@ -3,26 +3,27 @@ x = "";
|
||||
x; // string
|
||||
x = true;
|
||||
x; // boolean
|
||||
x = "" = 1;
|
||||
var ref;
|
||||
ref = 1, x = ref === void 0 ? "" : ref;
|
||||
x; // string | number
|
||||
x = ({
|
||||
x: true
|
||||
}).x;
|
||||
x; // boolean
|
||||
var ref;
|
||||
ref = {
|
||||
y: 1
|
||||
}, x = ref.y, ref;
|
||||
x; // number
|
||||
var ref1, ref2;
|
||||
var ref1;
|
||||
ref1 = {
|
||||
x: true
|
||||
}, ref2 = ref1.x, x = ref2 === void 0 ? "" : ref2, ref1;
|
||||
x; // string | boolean
|
||||
var ref3;
|
||||
ref3 = {
|
||||
y: 1
|
||||
}, x = /a/ = ref3.y, ref3;
|
||||
}, x = ref1.y, ref1;
|
||||
x; // number
|
||||
var ref2, ref3;
|
||||
ref2 = {
|
||||
x: true
|
||||
}, ref3 = ref2.x, x = ref3 === void 0 ? "" : ref3, ref2;
|
||||
x; // string | boolean
|
||||
var ref4, ref5;
|
||||
ref4 = {
|
||||
y: 1
|
||||
}, ref5 = ref4.y, x = ref5 === void 0 ? /a/ : ref5, ref4;
|
||||
x; // number | RegExp
|
||||
var a;
|
||||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
||||
|
@ -1,9 +1,7 @@
|
||||
x = "" = 1, ref = {
|
||||
y: 1
|
||||
}, x = /a/ = ref.y;
|
||||
"";
|
||||
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
||||
try {
|
||||
for(var x, ref, a, _step, _iterator = a[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_step.value;
|
||||
for(var a, _step, _iterator = a[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_step.value;
|
||||
} catch (err) {
|
||||
_didIteratorError = !0, _iteratorError = err;
|
||||
} finally{
|
||||
|
@ -58,15 +58,15 @@ function f0() {
|
||||
1,
|
||||
"hello"
|
||||
];
|
||||
var ref3 = [
|
||||
var ref1 = [
|
||||
1,
|
||||
"hello"
|
||||
], x = ref3[0];
|
||||
], x = ref1[0];
|
||||
var x = 1, y = "hello";
|
||||
var ref4 = [
|
||||
var ref2 = [
|
||||
1,
|
||||
"hello"
|
||||
], x = ref4[0], y = ref4[1], z = ref4[2];
|
||||
], x = ref2[0], y = ref2[1], z = ref2[2];
|
||||
var x = 2;
|
||||
var x;
|
||||
var y;
|
||||
@ -84,10 +84,10 @@ function f1() {
|
||||
var z;
|
||||
}
|
||||
function f2() {
|
||||
var ref9 = {
|
||||
var ref = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, ref9 = ref9 !== null ? ref9 : _throw(new TypeError("Cannot destructure undefined")); // Error, no x and y in target
|
||||
}, ref = ref !== null ? ref : _throw(new TypeError("Cannot destructure undefined")); // Error, no x and y in target
|
||||
var x = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
@ -96,24 +96,24 @@ function f2() {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}.y; // Error, no x in target
|
||||
var ref3 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, x = ref3.x, y = ref3.y;
|
||||
var x;
|
||||
var y;
|
||||
var ref4 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, a = ref4.x; // Error, no y in target
|
||||
var ref5 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, x = ref5.x, y = ref5.y;
|
||||
var x;
|
||||
var y;
|
||||
}, b = ref5.y; // Error, no x in target
|
||||
var ref6 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, a = ref6.x; // Error, no y in target
|
||||
var ref7 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, b = ref7.y; // Error, no x in target
|
||||
var ref8 = {
|
||||
x: 5,
|
||||
y: "hello"
|
||||
}, a = ref8.x, b = ref8.y;
|
||||
}, a = ref6.x, b = ref6.y;
|
||||
var a;
|
||||
var b;
|
||||
}
|
||||
@ -124,7 +124,7 @@ function f3() {
|
||||
var z;
|
||||
}
|
||||
function f4() {
|
||||
var ref10 = {
|
||||
var ref = {
|
||||
a: 1,
|
||||
b: {
|
||||
a: "hello",
|
||||
@ -132,7 +132,7 @@ function f4() {
|
||||
a: true
|
||||
}
|
||||
}
|
||||
}, x = ref10.a, _b = ref10.b, y = _b.a, _b1 = _b.b, z = _b1.a;
|
||||
}, x = ref.a, _b = ref.b, y = _b.a, _b1 = _b.b, z = _b1.a;
|
||||
var x;
|
||||
var y;
|
||||
var z;
|
||||
@ -148,42 +148,42 @@ function f7() {
|
||||
var y;
|
||||
}
|
||||
function f8() {
|
||||
var ref12 = [], a = ref12[0], b = ref12[1], c = ref12[2]; // Error, [] is an empty tuple
|
||||
var ref11 = [
|
||||
var ref = [], a = ref[0], b = ref[1], c = ref[2]; // Error, [] is an empty tuple
|
||||
var ref7 = [
|
||||
1
|
||||
], d = ref11[0], e = ref11[1], f = ref11[2]; // Error, [1] is a tuple
|
||||
], d = ref7[0], e = ref7[1], f = ref7[2]; // Error, [1] is a tuple
|
||||
}
|
||||
function f9() {
|
||||
var ref14 = _slicedToArray({
|
||||
}, 2), a = ref14[0], b = ref14[1]; // Error, not array type
|
||||
var ref13 = _slicedToArray({
|
||||
var ref = _slicedToArray({
|
||||
}, 2), a = ref[0], b = ref[1]; // Error, not array type
|
||||
var ref8 = _slicedToArray({
|
||||
0: 10,
|
||||
1: 20
|
||||
}, 2), c = ref13[0], d = ref13[1]; // Error, not array type
|
||||
}, 2), c = ref8[0], d = ref8[1]; // Error, not array type
|
||||
var e = 10, f = 20;
|
||||
}
|
||||
function f10() {
|
||||
var ref16 = {
|
||||
}, a = ref16.a, b = ref16.b; // Error
|
||||
var ref15 = [], a = ref15.a, b = ref15.b; // Error
|
||||
var ref = {
|
||||
}, a = ref.a, b = ref.b; // Error
|
||||
var ref9 = [], a = ref9.a, b = ref9.b; // Error
|
||||
}
|
||||
function f11() {
|
||||
var ref20 = {
|
||||
var ref = {
|
||||
x: 10,
|
||||
y: "hello"
|
||||
}, a = ref20.x, b = ref20.y;
|
||||
var ref17 = {
|
||||
}, a = ref.x, b = ref.y;
|
||||
var ref10 = {
|
||||
0: 10,
|
||||
1: "hello"
|
||||
}, a = ref17[0], b = ref17[1];
|
||||
var ref18 = {
|
||||
}, a = ref10[0], b = ref10[1];
|
||||
var ref11 = {
|
||||
"<": 10,
|
||||
">": "hello"
|
||||
}, a = ref18["<"], b = ref18[">"];
|
||||
var ref19 = [
|
||||
}, a = ref11["<"], b = ref11[">"];
|
||||
var ref12 = [
|
||||
10,
|
||||
"hello"
|
||||
], a = ref19[0], b = ref19[1];
|
||||
], a = ref12[0], b = ref12[1];
|
||||
var a;
|
||||
var b;
|
||||
}
|
||||
@ -194,13 +194,13 @@ function f12() {
|
||||
x: 5,
|
||||
y: true
|
||||
}
|
||||
], ref22 = _slicedToArray(tmp === void 0 ? [
|
||||
], ref = _slicedToArray(tmp === void 0 ? [
|
||||
"abc",
|
||||
{
|
||||
x: 10,
|
||||
y: false
|
||||
}
|
||||
] : tmp, 2), b = ref22[0], ref21 = ref22[1], x = ref21.x, c = ref21.y;
|
||||
] : tmp, 2), b = ref[0], ref13 = ref[1], x = ref13.x, c = ref13.y;
|
||||
var a;
|
||||
var b;
|
||||
var x;
|
||||
@ -208,7 +208,7 @@ function f12() {
|
||||
}
|
||||
function f13() {
|
||||
var x = 1, y = "hello";
|
||||
var ref23 = [
|
||||
var ref = [
|
||||
[
|
||||
x,
|
||||
y
|
||||
@ -217,10 +217,10 @@ function f13() {
|
||||
x: x,
|
||||
y: y
|
||||
}
|
||||
], a = ref23[0], b = ref23[1];
|
||||
], a = ref[0], b = ref[1];
|
||||
}
|
||||
function f14(param) {
|
||||
var _param = _slicedToArray(param, 2), tmp = _param[0], a = tmp === void 0 ? 1 : tmp, ref25 = _slicedToArray(_param[1], 2), tmp3 = ref25[0], b = tmp3 === void 0 ? "hello" : tmp3, ref24 = ref25[1], x = ref24.x, tmp4 = ref24.y, c = tmp4 === void 0 ? false : tmp4;
|
||||
var _param = _slicedToArray(param, 2), tmp = _param[0], a = tmp === void 0 ? 1 : tmp, ref = _slicedToArray(_param[1], 2), tmp3 = ref[0], b = tmp3 === void 0 ? "hello" : tmp3, ref14 = ref[1], x = ref14.x, tmp4 = ref14.y, c = tmp4 === void 0 ? false : tmp4;
|
||||
var a;
|
||||
var b;
|
||||
var c;
|
||||
@ -269,7 +269,7 @@ function f15() {
|
||||
};
|
||||
}
|
||||
function f16() {
|
||||
var ref26 = f15(), a = ref26.a, b = ref26.b, c = ref26.c;
|
||||
var ref = f15(), a = ref.a, b = ref.b, c = ref.c;
|
||||
}
|
||||
function f17(param) {
|
||||
var _a = param.a, a = _a === void 0 ? "" : _a, _b = param.b, b = _b === void 0 ? 0 : _b, _c = param.c, c = _c === void 0 ? false : _c;
|
||||
@ -283,56 +283,59 @@ f17({
|
||||
c: true
|
||||
});
|
||||
f17(f15());
|
||||
var ref, ref1;
|
||||
function f18() {
|
||||
var a;
|
||||
var b;
|
||||
var aa;
|
||||
var ref30;
|
||||
ref30 = {
|
||||
var ref;
|
||||
ref = {
|
||||
a: a,
|
||||
b: b
|
||||
}, a = ref30.a, b = ref30.b, ref30;
|
||||
var ref27;
|
||||
ref27 = {
|
||||
}, a = ref.a, b = ref.b, ref;
|
||||
var ref15;
|
||||
ref15 = {
|
||||
b: b,
|
||||
a: a
|
||||
}, a = ref27.a, b = ref27.b, ref27;
|
||||
var ref28;
|
||||
ref28 = [
|
||||
}, a = ref15.a, b = ref15.b, ref15;
|
||||
var ref16;
|
||||
ref16 = [
|
||||
a,
|
||||
b
|
||||
], aa[0] = ref28[0], b = ref28[1], ref28;
|
||||
var ref29;
|
||||
ref29 = [
|
||||
], aa[0] = ref16[0], b = ref16[1], ref16;
|
||||
var ref17;
|
||||
ref17 = [
|
||||
b,
|
||||
a
|
||||
], a = ref29[0], b = ref29[1], ref29; // Error
|
||||
ref = 1, a = ref, ref1 = "abc", b = ref1;
|
||||
], a = ref17[0], b = ref17[1], ref17; // Error
|
||||
var ref18, ref19;
|
||||
ref18 = 2, a = ref18 === void 0 ? 1 : ref18, ref19 = "def", b = ref19 === void 0 ? "abc" : ref19;
|
||||
}
|
||||
var ref2;
|
||||
function f19() {
|
||||
var a, b;
|
||||
a = 1, b = 2;
|
||||
var ref33;
|
||||
ref33 = [
|
||||
var ref;
|
||||
ref = [
|
||||
b,
|
||||
a
|
||||
], a = ref33[0], b = ref33[1], ref33;
|
||||
var ref31;
|
||||
ref31 = {
|
||||
], a = ref[0], b = ref[1], ref;
|
||||
var ref20;
|
||||
ref20 = {
|
||||
b: b,
|
||||
a: a
|
||||
}, a = ref31.a, b = ref31.b, ref31;
|
||||
ref2 = [
|
||||
}, a = ref20.a, b = ref20.b, ref20;
|
||||
var ref21, ref22;
|
||||
ref21 = [
|
||||
2,
|
||||
3
|
||||
], ref22 = _slicedToArray(ref21 === void 0 ? [
|
||||
1,
|
||||
2
|
||||
], [a, b] = ref2;
|
||||
var ref32;
|
||||
var x = (ref32 = [
|
||||
] : ref21, 2), a = ref22[0], b = ref22[1], ref22;
|
||||
var ref23;
|
||||
var x = (ref23 = [
|
||||
1,
|
||||
2
|
||||
], a = ref32[0], b = ref32[1], ref32);
|
||||
], a = ref23[0], b = ref23[1], ref23);
|
||||
}
|
||||
function f20(v) {
|
||||
var x;
|
||||
@ -346,14 +349,14 @@ function f20(v) {
|
||||
var _v1 = _toArray(v), x = _v1[0], a2 = _v1.slice(1);
|
||||
var _v2 = _toArray(v), x = _v2[0], y = _v2[1], a1 = _v2.slice(2);
|
||||
var _v3 = _toArray(v), x = _v3[0], y = _v3[1], z = _v3[2], a0 = _v3.slice(3);
|
||||
var ref37;
|
||||
ref37 = _toArray(v), a3 = ref37.slice(0), ref37;
|
||||
var ref34;
|
||||
ref34 = _toArray(v), x = ref34[0], a2 = ref34.slice(1), ref34;
|
||||
var ref35;
|
||||
ref35 = _toArray(v), x = ref35[0], y = ref35[1], a1 = ref35.slice(2), ref35;
|
||||
var ref36;
|
||||
ref36 = _toArray(v), x = ref36[0], y = ref36[1], z = ref36[2], a0 = ref36.slice(3), ref36;
|
||||
var ref;
|
||||
ref = _toArray(v), a3 = ref.slice(0), ref;
|
||||
var ref24;
|
||||
ref24 = _toArray(v), x = ref24[0], a2 = ref24.slice(1), ref24;
|
||||
var ref25;
|
||||
ref25 = _toArray(v), x = ref25[0], y = ref25[1], a1 = ref25.slice(2), ref25;
|
||||
var ref26;
|
||||
ref26 = _toArray(v), x = ref26[0], y = ref26[1], z = ref26[2], a0 = ref26.slice(3), ref26;
|
||||
}
|
||||
function f21(v) {
|
||||
var x;
|
||||
@ -367,12 +370,12 @@ function f21(v) {
|
||||
var _v4 = _toArray(v), x = _v4[0], a1 = _v4.slice(1);
|
||||
var _v5 = _toArray(v), x = _v5[0], y = _v5[1], a2 = _v5.slice(2);
|
||||
var _v6 = _toArray(v), x = _v6[0], y = _v6[1], z = _v6[2], a3 = _v6.slice(3);
|
||||
var ref41;
|
||||
ref41 = _toArray(v), a0 = ref41.slice(0), ref41;
|
||||
var ref38;
|
||||
ref38 = _toArray(v), x = ref38[0], a1 = ref38.slice(1), ref38;
|
||||
var ref39;
|
||||
ref39 = _toArray(v), x = ref39[0], y = ref39[1], a2 = ref39.slice(2), ref39;
|
||||
var ref40;
|
||||
ref40 = _toArray(v), x = ref40[0], y = ref40[1], z = ref40[2], a3 = ref40.slice(3), ref40;
|
||||
var ref;
|
||||
ref = _toArray(v), a0 = ref.slice(0), ref;
|
||||
var ref27;
|
||||
ref27 = _toArray(v), x = ref27[0], a1 = ref27.slice(1), ref27;
|
||||
var ref28;
|
||||
ref28 = _toArray(v), x = ref28[0], y = ref28[1], a2 = ref28.slice(2), ref28;
|
||||
var ref29;
|
||||
ref29 = _toArray(v), x = ref29[0], y = ref29[1], z = ref29[2], a3 = ref29.slice(3), ref29;
|
||||
}
|
||||
|
@ -40,4 +40,4 @@ var _c;
|
||||
var ref;
|
||||
_c = c, b = _objectWithoutProperties(_c.x, [
|
||||
"a"
|
||||
]), ref = _c, { a } = d = ref.x, ref, _c;
|
||||
]), ref = _c, d = ref.x, a = (d === void 0 ? d : d).a, ref, _c;
|
||||
|
@ -1,4 +1,4 @@
|
||||
var _c, ref, a, d;
|
||||
var _c;
|
||||
(function(source, excluded) {
|
||||
if (null == source) return {
|
||||
};
|
||||
@ -21,4 +21,4 @@ var _c, ref, a, d;
|
||||
}
|
||||
}).x, [
|
||||
"a"
|
||||
]), ref = _c, { a } = d = ref.x;
|
||||
]), (void 0 === _c.x, _c.x).a;
|
||||
|
@ -13,10 +13,9 @@ var E;
|
||||
}));
|
||||
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
||||
try {
|
||||
var ref;
|
||||
for(var _iterator = array[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
||||
var ref1;
|
||||
ref1 = _step.value, x = ref1.x, ref = E.x, y = ref, ref1;
|
||||
var ref, ref1;
|
||||
ref = _step.value, x = ref.x, ref1 = ref.y, y = ref1 === void 0 ? E.x : ref1, ref;
|
||||
x;
|
||||
y;
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ var E;
|
||||
}))[E.x = 0] = "x";
|
||||
var _iteratorNormalCompletion = !0, _didIteratorError = !1, _iteratorError = void 0;
|
||||
try {
|
||||
for(var E, _step, _iterator = [
|
||||
for(var E, ref, ref1, _step, _iterator = [
|
||||
{
|
||||
x: "",
|
||||
y: !0
|
||||
}
|
||||
][Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)_step.value.x, E.x;
|
||||
][Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = !0)(ref = _step.value).x, ref1 = ref.y, void 0 === ref1 && E.x;
|
||||
} catch (err) {
|
||||
_didIteratorError = !0, _iteratorError = err;
|
||||
} finally{
|
||||
|
@ -3,38 +3,37 @@ function _throw(e) {
|
||||
}
|
||||
// Missing properties
|
||||
function f1() {
|
||||
var ref7 = {
|
||||
}, x = ref7.x, y = ref7.y;
|
||||
var ref4 = {
|
||||
}, _x = ref4.x, x = _x === void 0 ? 1 : _x, y = ref4.y;
|
||||
var ref5 = {
|
||||
}, x = ref5.x, _y = ref5.y, y = _y === void 0 ? 1 : _y;
|
||||
var ref6 = {
|
||||
}, _x1 = ref6.x, x = _x1 === void 0 ? 1 : _x1, _y1 = ref6.y, y = _y1 === void 0 ? 1 : _y1;
|
||||
var ref = {
|
||||
}, x = ref.x, y = ref.y;
|
||||
var ref1 = {
|
||||
}, _x = ref1.x, x = _x === void 0 ? 1 : _x, y = ref1.y;
|
||||
var ref2 = {
|
||||
}, x = ref2.x, _y = ref2.y, y = _y === void 0 ? 1 : _y;
|
||||
var ref3 = {
|
||||
}, _x1 = ref3.x, x = _x1 === void 0 ? 1 : _x1, _y1 = ref3.y, y = _y1 === void 0 ? 1 : _y1;
|
||||
}
|
||||
var ref, ref1, ref2, ref3;
|
||||
// Missing properties
|
||||
function f2() {
|
||||
var x, y;
|
||||
var ref11;
|
||||
ref11 = {
|
||||
}, x = ref11.x, y = ref11.y, ref11;
|
||||
var ref8;
|
||||
var ref;
|
||||
ref = {
|
||||
}, x = ref.x, y = ref.y, ref;
|
||||
var ref4, ref5;
|
||||
ref4 = {
|
||||
}, ref5 = ref4.x, x = ref5 === void 0 ? 1 : ref5, y = ref4.y, ref4;
|
||||
var ref6, ref7;
|
||||
ref6 = {
|
||||
}, x = ref6.x, ref7 = ref6.y, y = ref7 === void 0 ? 1 : ref7, ref6;
|
||||
var ref8, ref9, ref10;
|
||||
ref8 = {
|
||||
}, ref = 1, x = ref, y = ref8.y, ref8;
|
||||
var ref9;
|
||||
ref9 = {
|
||||
}, x = ref9.x, ref1 = 1, y = ref1, ref9;
|
||||
var ref10;
|
||||
ref10 = {
|
||||
}, ref2 = 1, x = ref2, ref3 = 1, y = ref3, ref10;
|
||||
}, ref9 = ref8.x, x = ref9 === void 0 ? 1 : ref9, ref10 = ref8.y, y = ref10 === void 0 ? 1 : ref10, ref8;
|
||||
}
|
||||
// Excess properties
|
||||
function f3() {
|
||||
var ref13 = {
|
||||
var ref = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}, ref13 = ref13 !== null ? ref13 : _throw(new TypeError("Cannot destructure undefined"));
|
||||
}, ref = ref !== null ? ref : _throw(new TypeError("Cannot destructure undefined"));
|
||||
var x = {
|
||||
x: 0,
|
||||
y: 0
|
||||
@ -43,19 +42,19 @@ function f3() {
|
||||
x: 0,
|
||||
y: 0
|
||||
}.y;
|
||||
var ref12 = {
|
||||
var ref11 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}, x = ref12.x, y = ref12.y;
|
||||
}, x = ref11.x, y = ref11.y;
|
||||
}
|
||||
// Excess properties
|
||||
function f4() {
|
||||
var x, y;
|
||||
var ref15;
|
||||
ref15 = {
|
||||
var ref;
|
||||
ref = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}, ref15;
|
||||
}, ref;
|
||||
x = ({
|
||||
x: 0,
|
||||
y: 0
|
||||
@ -64,9 +63,9 @@ function f4() {
|
||||
x: 0,
|
||||
y: 0
|
||||
}).y;
|
||||
var ref14;
|
||||
ref14 = {
|
||||
var ref12;
|
||||
ref12 = {
|
||||
x: 0,
|
||||
y: 0
|
||||
}, x = ref14.x, y = ref14.y, ref14;
|
||||
}, x = ref12.x, y = ref12.y, ref12;
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ _complex = complex, nested = _objectWithoutProperties(_complex.x, [
|
||||
]), rest = _objectWithoutProperties(_complex, [
|
||||
"x",
|
||||
"y"
|
||||
]), ref = _complex, ({ ka } = ref.x), other = ref.y, ref, _complex;
|
||||
]), ref = _complex, ka = ref.x.ka, other = ref.y, ref, _complex;
|
||||
// should be:
|
||||
var overEmit;
|
||||
// var _g = overEmit.a, [_h, ...y] = _g, nested2 = __rest(_h, []), _j = overEmit.b, { z } = _j, c = __rest(_j, ["z"]), rest2 = __rest(overEmit, ["a", "b"]);
|
||||
@ -95,11 +95,11 @@ var _a = _toArray(overEmit.a), ref1 = _a[0], ref1 = ref1 !== null ? ref1 : _thro
|
||||
"b"
|
||||
]);
|
||||
var _overEmit;
|
||||
var ref2;
|
||||
var ref2, ref3, ref4;
|
||||
_overEmit = overEmit, nested2 = _extends({
|
||||
}, _overEmit.a[0]), c = _objectWithoutProperties(_overEmit.b, [
|
||||
"z"
|
||||
]), rest2 = _objectWithoutProperties(_overEmit, [
|
||||
"a",
|
||||
"b"
|
||||
]), ref2 = _overEmit, [{}, ...y] = ref2.a, ({ z } = ref2.b), ref2, _overEmit;
|
||||
]), ref2 = _overEmit, ref3 = _toArray(ref2.a), ref4 = ref3[0], ref4, y = ref3.slice(1), ref3, z = ref2.b.z, ref2, _overEmit;
|
||||
|
@ -30,29 +30,33 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
||||
for(i = 0; i < sourceKeys.length; i++)key = sourceKeys[i], excluded.indexOf(key) >= 0 || (target[key] = source[key]);
|
||||
return target;
|
||||
}
|
||||
_objectWithoutProperties((_complex = complex).x, [
|
||||
"ka"
|
||||
]), _objectWithoutProperties(_complex, [
|
||||
"x",
|
||||
"y"
|
||||
]), ref = _complex, { ka } = ref.x;
|
||||
var arr, ka, complex, _complex, ref, overEmit, _overEmit, ref1, _a = function(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
}(arr = overEmit.a) || function(iter) {
|
||||
if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
|
||||
}(arr) || function(o, minLen) {
|
||||
function _toArray(arr) {
|
||||
return (function(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
})(arr) || (function(iter) {
|
||||
if ("undefined" != typeof Symbol && null != iter[Symbol.iterator] || null != iter["@@iterator"]) return Array.from(iter);
|
||||
})(arr) || _unsupportedIterableToArray(arr, i) || (function() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
})();
|
||||
}
|
||||
function _unsupportedIterableToArray(o, minLen) {
|
||||
if (o) {
|
||||
if ("string" == typeof o) return _arrayLikeToArray(o, minLen);
|
||||
var n = Object.prototype.toString.call(o).slice(8, -1);
|
||||
if ("Object" === n && o.constructor && (n = o.constructor.name), "Map" === n || "Set" === n) return Array.from(n);
|
||||
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
||||
}
|
||||
}(arr, i) || function() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
}(), ref2 = _a[0], ref2 = null !== ref2 ? ref2 : function(e) {
|
||||
}
|
||||
_objectWithoutProperties((_complex = complex).x, [
|
||||
"ka"
|
||||
]), _objectWithoutProperties(_complex, [
|
||||
"x",
|
||||
"y"
|
||||
]), _complex.x.ka;
|
||||
var complex, _complex, overEmit, _overEmit, ref, ref1, _a = _toArray(overEmit.a), ref2 = _a[0], ref2 = null !== ref2 ? ref2 : function(e) {
|
||||
throw e;
|
||||
}(new TypeError("Cannot destructure undefined")), y = _a.slice(1), z = overEmit.b.z;
|
||||
_extends({
|
||||
}(new TypeError("Cannot destructure undefined"));
|
||||
_a.slice(1), overEmit.b.z, _extends({
|
||||
}, overEmit.a[0]), _objectWithoutProperties(overEmit.b, [
|
||||
"z"
|
||||
]), _objectWithoutProperties(overEmit, [
|
||||
@ -64,4 +68,4 @@ _extends({
|
||||
]), _objectWithoutProperties(_overEmit, [
|
||||
"a",
|
||||
"b"
|
||||
]), ref1 = _overEmit, [{}, ...y] = ref1.a, { z } = ref1.b;
|
||||
]), (ref1 = _toArray((ref = _overEmit).a))[0], ref1.slice(1), ref.b.z;
|
||||
|
@ -128,7 +128,7 @@ _complex = complex, nested = _objectWithoutProperties(_complex.x, [
|
||||
]), rest = _objectWithoutProperties(_complex, [
|
||||
"x",
|
||||
"y"
|
||||
]), ref = _complex, ({ ka } = ref.x), other = ref.y, ref, _complex;
|
||||
]), ref = _complex, ka = ref.x.ka, other = ref.y, ref, _complex;
|
||||
var _ref = {
|
||||
x: 1,
|
||||
y: 2
|
||||
|
@ -77,9 +77,7 @@ _n1.y, _n1.n2.z, _extends({
|
||||
}, nestedrest.n1.n2.n3), _objectWithoutProperties(nestedrest, [
|
||||
"x",
|
||||
"n1"
|
||||
]);
|
||||
var ka = complex.x.ka;
|
||||
complex.y, _objectWithoutProperties(complex.x, [
|
||||
]), complex.x.ka, complex.y, _objectWithoutProperties(complex.x, [
|
||||
"ka"
|
||||
]), _objectWithoutProperties(complex, [
|
||||
"x",
|
||||
@ -89,7 +87,7 @@ complex.y, _objectWithoutProperties(complex.x, [
|
||||
]), _objectWithoutProperties(_complex, [
|
||||
"x",
|
||||
"y"
|
||||
]), ref = _complex, ({ ka } = ref.x), ref.y;
|
||||
]), (ref = _complex).x.ka, ref.y;
|
||||
var _ref = {
|
||||
x: 1,
|
||||
y: 2
|
||||
|
@ -28,5 +28,5 @@ var tuple = [
|
||||
"",
|
||||
1
|
||||
];
|
||||
var ref, ref1;
|
||||
ref = _toArray(tuple), ref1 = ref.slice(0), a = "" = ref1[0], b = ref1.b, ref1, ref;
|
||||
var ref, ref1, ref2;
|
||||
ref = _toArray(tuple), ref1 = ref.slice(0), ref2 = ref1[0], a = ref2 === void 0 ? "" : ref2, b = ref1.b, ref1, ref;
|
||||
|
@ -1,10 +1,10 @@
|
||||
var a, ref, arr;
|
||||
var ref, arr;
|
||||
function _arrayLikeToArray(arr, len) {
|
||||
(null == len || len > arr.length) && (len = arr.length);
|
||||
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
||||
return arr2;
|
||||
}
|
||||
ref = ((function(arr) {
|
||||
void 0 === (ref = ((function(arr) {
|
||||
if (Array.isArray(arr)) return arr;
|
||||
})(arr = [
|
||||
"",
|
||||
@ -20,4 +20,4 @@ ref = ((function(arr) {
|
||||
}
|
||||
})(arr, i) || (function() {
|
||||
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
||||
})()).slice(0), a = "" = ref[0], ref.b;
|
||||
})()).slice(0))[0], ref.b;
|
||||
|
@ -622,7 +622,9 @@ impl VisitMut for AssignFolder {
|
||||
if is_literal(right) && ignore_return_value {
|
||||
match &mut **right {
|
||||
Expr::Array(arr)
|
||||
if elems.len() == arr.elems.len() || has_rest_pat(elems) =>
|
||||
if elems.len() == arr.elems.len()
|
||||
|| (elems.len() < arr.elems.len()
|
||||
&& has_rest_pat(elems)) =>
|
||||
{
|
||||
let mut arr_elems = Some(arr.elems.take().into_iter());
|
||||
elems.into_iter().for_each(|p| match p {
|
||||
@ -652,15 +654,25 @@ impl VisitMut for AssignFolder {
|
||||
e.expr
|
||||
})
|
||||
.unwrap_or_else(|| undefined(p.span()));
|
||||
exprs.push(Box::new(Expr::Assign(AssignExpr {
|
||||
|
||||
let mut expr = Expr::Assign(AssignExpr {
|
||||
span: p.span(),
|
||||
left: PatOrExpr::Pat(Box::new(p.take())),
|
||||
left: Box::new(p.take()).into(),
|
||||
op: op!("="),
|
||||
right,
|
||||
})));
|
||||
});
|
||||
|
||||
self.visit_mut_expr(&mut expr);
|
||||
|
||||
exprs.push(Box::new(expr));
|
||||
}
|
||||
|
||||
None => {}
|
||||
None => {
|
||||
arr_elems
|
||||
.as_mut()
|
||||
.expect("pattern after rest element?")
|
||||
.next();
|
||||
}
|
||||
});
|
||||
*expr = SeqExpr { span: *span, exprs }.into();
|
||||
return;
|
||||
@ -855,7 +867,7 @@ impl VisitMut for AssignFolder {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
exprs.push(Box::new(Expr::Assign(AssignExpr {
|
||||
let mut expr = Expr::Assign(AssignExpr {
|
||||
span,
|
||||
left: PatOrExpr::Pat(value.take()),
|
||||
op: op!("="),
|
||||
@ -864,7 +876,10 @@ impl VisitMut for AssignFolder {
|
||||
Box::new(prop_name_to_expr(key.take())),
|
||||
computed,
|
||||
)),
|
||||
})));
|
||||
});
|
||||
|
||||
expr.visit_mut_with(self);
|
||||
exprs.push(Box::new(expr));
|
||||
}
|
||||
ObjectPatProp::Assign(AssignPatProp { key, value, .. }) => {
|
||||
let computed = false;
|
||||
@ -931,23 +946,33 @@ impl VisitMut for AssignFolder {
|
||||
});
|
||||
}
|
||||
Pat::Assign(pat) => {
|
||||
let ref_ident = make_ref_ident(self.c, &mut self.vars, None);
|
||||
let ref_ident = match *pat.right {
|
||||
Expr::Ident(ref i) => i.clone(),
|
||||
|
||||
_ => make_ref_ident(self.c, &mut self.vars, None),
|
||||
};
|
||||
|
||||
let mut exprs = vec![];
|
||||
|
||||
exprs.push(Box::new(Expr::Assign(AssignExpr {
|
||||
span: *span,
|
||||
left: PatOrExpr::Pat(Box::new(Pat::Ident(ref_ident.clone().into()))),
|
||||
op: op!("="),
|
||||
right: pat.right.take(),
|
||||
})));
|
||||
exprs.push(Box::new(
|
||||
AssignExpr {
|
||||
span: *span,
|
||||
left: Box::new(Pat::Ident(ref_ident.clone().into())).into(),
|
||||
op: op!("="),
|
||||
right: right.take(),
|
||||
}
|
||||
.into(),
|
||||
));
|
||||
|
||||
exprs.push(Box::new(Expr::Assign(AssignExpr {
|
||||
let mut assign_cond_expr = Expr::Assign(AssignExpr {
|
||||
span: *span,
|
||||
left: PatOrExpr::Pat(pat.left.take()),
|
||||
left: pat.left.take().into(),
|
||||
op: op!("="),
|
||||
right: Box::new(Expr::Ident(ref_ident)),
|
||||
})));
|
||||
right: Box::new(make_cond_expr(ref_ident, pat.right.take())),
|
||||
});
|
||||
|
||||
assign_cond_expr.visit_mut_with(self);
|
||||
exprs.push(Box::new(assign_cond_expr));
|
||||
|
||||
*expr = Expr::Seq(SeqExpr {
|
||||
span: DUMMY_SP,
|
||||
|
@ -18,7 +18,7 @@ fn syntax() -> Syntax {
|
||||
}
|
||||
|
||||
fn tr() -> impl Fold {
|
||||
destructuring(Config { loose: true })
|
||||
chain!(resolver(), destructuring(Config { loose: true }))
|
||||
}
|
||||
|
||||
test!(
|
||||
@ -180,12 +180,105 @@ test!(
|
||||
ref = [], ref1 = ref[0], code = ref1 === void 0 ? 1 : ref1, ref;"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding,
|
||||
"[code = 1] = [1]",
|
||||
"
|
||||
var ref;
|
||||
ref = 1,
|
||||
code = ref === void 0 ? 1 : ref;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_2,
|
||||
"[foo = 1, bar = 2] = [3];",
|
||||
"
|
||||
var ref, ref1, ref2;
|
||||
ref = [3],
|
||||
ref1 = ref[0],
|
||||
foo = ref1 === void 0 ? 1 : ref1,
|
||||
ref2 = ref[1],
|
||||
bar = ref2 === void 0 ? 2 : ref2,
|
||||
ref;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_3,
|
||||
"[foo = 1, bar = 2] = [3, 4];",
|
||||
"
|
||||
var ref, ref1;
|
||||
ref = 3,
|
||||
foo = ref === void 0 ? 1 : ref,
|
||||
ref1 = 4,
|
||||
bar = ref1 === void 0 ? 2 : ref1;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_4,
|
||||
"const [foo = 1] = [2];",
|
||||
"const tmp = 2, foo = tmp === void 0 ? 1 : tmp;"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_5,
|
||||
"const [foo = 1, bar] = [2, 3];",
|
||||
"
|
||||
const tmp = 2,
|
||||
foo = tmp === void 0 ? 1 : tmp,
|
||||
bar = 3;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_6,
|
||||
"const [foo = 1] = [];",
|
||||
"
|
||||
const ref = [],
|
||||
tmp = ref[0],
|
||||
foo = tmp === void 0 ? 1 : tmp;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
array_pat_assign_prop_binding_7,
|
||||
"const [foo = 1] = [1, 2];",
|
||||
"
|
||||
const ref = [1, 2],
|
||||
tmp = ref[0],
|
||||
foo = tmp === void 0 ? 1 : tmp;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
issue_260_02,
|
||||
"[code = 1, ...rest] = [];",
|
||||
"code = 1 = void 0, rest = [];",
|
||||
"
|
||||
var ref, ref1;
|
||||
ref = [],
|
||||
ref1 = ref[0],
|
||||
code = ref1 === void 0 ? 1 : ref1,
|
||||
rest = ref.slice(1),
|
||||
ref;
|
||||
",
|
||||
ok_if_code_eq
|
||||
);
|
||||
|
||||
@ -198,6 +291,95 @@ test!(
|
||||
ref = {}, ref1 = ref.code, code = ref1 === void 0 ? 1 : ref1, ref;"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_2,
|
||||
"const {code = 1} = {}",
|
||||
"
|
||||
const ref = {},
|
||||
_code = ref.code,
|
||||
code = _code === void 0 ? 1 : _code;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_binding,
|
||||
"({foo: bar = 1} = {})",
|
||||
"
|
||||
var ref, ref1;
|
||||
ref = {}, ref1 = ref.foo, bar = ref1 === void 0 ? 1 : ref1, ref;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_binding_2,
|
||||
"const {foo: bar = 1} = {}",
|
||||
"
|
||||
const ref = {},
|
||||
tmp = ref.foo,
|
||||
bar = tmp === void 0 ? 1 : tmp;
|
||||
"
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_binding_3,
|
||||
r#"
|
||||
let foo = 1;
|
||||
let bar = 2;
|
||||
let x;
|
||||
let y;
|
||||
({ [++foo]: x = "c", [++bar]: y = "d" } = { 2: "a" });
|
||||
|
||||
expect(foo).toBe(2);
|
||||
expect(bar).toBe(3);
|
||||
expect(x).toBe("a");
|
||||
expect(y).toBe("d");
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_binding_isseu_2850,
|
||||
"const obj = { foo = 123, bar: x = 123 } = { foo: 24, bar: 45 };",
|
||||
"
|
||||
var ref, ref1, ref2;
|
||||
const obj =(
|
||||
ref = {
|
||||
foo: 24,
|
||||
bar: 45
|
||||
},
|
||||
ref1 = ref.foo,
|
||||
foo = ref1 === void 0 ? 123 : ref1,
|
||||
(
|
||||
ref2 = ref.bar,
|
||||
x = ref2 === void 0 ? 123 : ref2
|
||||
),
|
||||
ref
|
||||
);
|
||||
"
|
||||
);
|
||||
|
||||
test_exec!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
object_pat_assign_prop_binding_isseu_2850_exec,
|
||||
r#"
|
||||
const obj = { foo = 123, bar: x = 123 } = { foo: 24, bar: 45 };
|
||||
|
||||
expect(obj).toEqual({ foo: 24, bar: 45 });
|
||||
expect(foo).toBe(24);
|
||||
expect(x).toBe(45);
|
||||
"#
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
@ -230,7 +412,15 @@ test!(
|
||||
|_| tr(),
|
||||
array2,
|
||||
r#"[a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];"#,
|
||||
r#"a = 'hello', [b] = [', ', 'junk'], [c] = ['world'];
|
||||
r#"
|
||||
var ref, ref1;
|
||||
a = "hello",
|
||||
ref = [", ", "junk"],
|
||||
b = ref[0],
|
||||
ref,
|
||||
ref1 = ["world"],
|
||||
c = ref1[0],
|
||||
ref1;
|
||||
"#
|
||||
);
|
||||
|
||||
@ -554,13 +744,13 @@ var x = z[0],
|
||||
y = z.slice(1);"#
|
||||
);
|
||||
|
||||
//test!(
|
||||
// syntax(),
|
||||
// |_| tr(),
|
||||
// member_expr,
|
||||
// r#"[foo.foo, foo.bar] = [1, 2];"#,
|
||||
// r#"foo.foo = 1, foo.bar = 2;"#
|
||||
//);
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
member_expr,
|
||||
r#"[foo.foo, foo.bar] = [1, 2];"#,
|
||||
r#"foo.foo = 1, foo.bar = 2;"#
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
@ -686,8 +876,8 @@ test!(
|
||||
}",
|
||||
"
|
||||
function foo(bar) {
|
||||
const foo = bar.foo;
|
||||
return foo;
|
||||
const foo1 = bar.foo;
|
||||
return foo1;
|
||||
}"
|
||||
);
|
||||
|
||||
@ -1474,9 +1664,18 @@ var [a, [b], [c]] = ["hello", [", ", "junk"], ["world"]];
|
||||
|
||||
"#,
|
||||
r#"
|
||||
var a = 'hello', ref = [', ', 'junk'], b = ref[0], c = 'world';
|
||||
a = 'hello', [b] = [', ', 'junk'], [c] = ['world'];
|
||||
|
||||
var a = "hello",
|
||||
ref = [", ", "junk"],
|
||||
b = ref[0],
|
||||
c = "world";
|
||||
var ref1, ref2;
|
||||
a = "hello",
|
||||
ref1 = [", ", "junk"],
|
||||
b = ref1[0],
|
||||
ref1,
|
||||
ref2 = ["world"],
|
||||
c = ref2[0],
|
||||
ref2;
|
||||
"#
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user