Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "allowArrayLike" option to the destructuring and spread transforms
When enabled, this option makes Babel treat array-like objects as if they were iterables. This makes it possible to avoid a Symbol polyfill when spreading or destructuring DOM lists in browsers without Symbol.iterator support.
- Loading branch information
1 parent
b1a589f
commit 1eda6df
Showing
20 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/holes/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
6 changes: 6 additions & 0 deletions
6
...ages/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/holes/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-destructuring", { "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
.../babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/length-cropped/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]); |
6 changes: 6 additions & 0 deletions
6
...l-plugin-transform-destructuring/test/fixtures/allowArrayLike/length-cropped/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-destructuring", { "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/simple/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"]); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/simple/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var [first, ...rest] = o; |
6 changes: 6 additions & 0 deletions
6
...ges/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/simple/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-destructuring", { "allowArrayLike": true }] | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-plugin-transform-destructuring/test/fixtures/allowArrayLike/simple/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
var _o = o, | ||
_o2 = babelHelpers.maybeArrayLike(babelHelpers.toArray, _o), | ||
first = _o2[0], | ||
rest = _o2.slice(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/holes/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
var p2 = { 0: "a", 2: "c", length: 3 }; | ||
|
||
var arr = [...p2, "d"]; | ||
|
||
expect(arr).toEqual(["a", undefined, "c", "d"]); | ||
expect(1 in arr).toBe(true); // Not holey |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/holes/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-spread", { "allowArrayLike": true }] | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/length-cropped/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var p2 = { 0: "b", 1: "c", 2: "d", length: 2 }; | ||
|
||
var arr = ["a", ...p2, "e"]; | ||
|
||
expect(arr).toEqual(["a", "b", "c", "e"]); |
6 changes: 6 additions & 0 deletions
6
...es/babel-plugin-transform-spread/test/fixtures/allowArrayLike/length-cropped/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-spread", { "allowArrayLike": true }] | ||
] | ||
} |
5 changes: 5 additions & 0 deletions
5
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/simple/exec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var p2 = { 0: "b", 1: "c", 2: "d", length: 3 }; | ||
|
||
var arr = ["a", ...p2, "e"]; | ||
|
||
expect(arr).toEqual(["a", "b", "c", "d", "e"]); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/simple/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var arr = ["a", ...p2, "e"]; |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/simple/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"plugins": [ | ||
["external-helpers", { "helperVersion": "7.100.0" }], | ||
["transform-spread", { "allowArrayLike": true }] | ||
] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-spread/test/fixtures/allowArrayLike/simple/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
var arr = ["a"].concat(babelHelpers.maybeArrayLike(babelHelpers.toConsumableArray, p2), ["e"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters