Add "allowArrayLike" opt to destructuring and spread transforms (#11265)

This commit is contained in:
Nicolò Ribaudo
2020-05-24 23:00:06 +02:00
committed by GitHub
parent 28231e1be6
commit 93978267ec
20 changed files with 110 additions and 5 deletions

View File

@@ -0,0 +1,6 @@
var o = { 0: "a", 2: "c", length: 3 };
var [...rest] = o;
expect(rest).toEqual(["a", undefined, "c"]);
expect(1 in rest).toBe(true); // Not holey

View File

@@ -0,0 +1,6 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
["transform-destructuring", { "allowArrayLike": true }]
]
}

View File

@@ -0,0 +1,6 @@
var o = { 0: "a", 1: "b", 2: "c", length: 2 };
var [first, ...rest] = o;
expect(first).toBe("a");
expect(rest).toEqual(["b"]);

View File

@@ -0,0 +1,6 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
["transform-destructuring", { "allowArrayLike": true }]
]
}

View File

@@ -0,0 +1,6 @@
var o = { 0: "a", 1: "b", 2: "c", length: 3 };
var [first, ...rest] = o;
expect(first).toBe("a");
expect(rest).toEqual(["b", "c"]);

View File

@@ -0,0 +1 @@
var [first, ...rest] = o;

View File

@@ -0,0 +1,6 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
["transform-destructuring", { "allowArrayLike": true }]
]
}

View File

@@ -0,0 +1,4 @@
var _o = o,
_o2 = babelHelpers.maybeArrayLike(babelHelpers.toArray, _o),
first = _o2[0],
rest = _o2.slice(1);