Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "allowArrayLike" support to the for-of transform
- Loading branch information
1 parent
2e6f958
commit 2811336
Showing
19 changed files
with
125 additions
and
12 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
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-for-of/test/fixtures/loose-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,7 @@ | ||
var p2 = { 0: "a", 2: "c", length: 3 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["a", undefined, "c"]); | ||
expect(1 in arr).toBe(true); // Not holey |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/loose-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-for-of", { "loose": true, "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
...s/babel-plugin-transform-for-of/test/fixtures/loose-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 p2 = { 0: "b", 1: "c", 2: "d", length: 2 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["b", "c"]); |
6 changes: 6 additions & 0 deletions
6
...el-plugin-transform-for-of/test/fixtures/loose-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-for-of", { "loose": true, "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/loose-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 p2 = { 0: "b", 1: "c", 2: "d", length: 3 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["b", "c", "d"]); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-for-of/test/fixtures/loose-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 @@ | ||
for (var x of p2) arr.push(x); |
6 changes: 6 additions & 0 deletions
6
...ages/babel-plugin-transform-for-of/test/fixtures/loose-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-for-of", { "loose": true, "allowArrayLike": true }] | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/babel-plugin-transform-for-of/test/fixtures/loose-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 @@ | ||
for (var _iterator = babelHelpers.createForOfIteratorHelperLoose(p2, true), _step; !(_step = _iterator()).done;) { | ||
var x = _step.value; | ||
arr.push(x); | ||
} |
7 changes: 7 additions & 0 deletions
7
packages/babel-plugin-transform-for-of/test/fixtures/spec-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,7 @@ | ||
var p2 = { 0: "a", 2: "c", length: 3 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["a", undefined, "c"]); | ||
expect(1 in arr).toBe(true); // Not holey |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/spec-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-for-of", { "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
...es/babel-plugin-transform-for-of/test/fixtures/spec-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 p2 = { 0: "b", 1: "c", 2: "d", length: 2 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["b", "c"]); |
6 changes: 6 additions & 0 deletions
6
...bel-plugin-transform-for-of/test/fixtures/spec-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-for-of", { "allowArrayLike": true }] | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/spec-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 p2 = { 0: "b", 1: "c", 2: "d", length: 3 }; | ||
|
||
var arr = []; | ||
for (var x of p2) arr.push(x); | ||
|
||
expect(arr).toEqual(["b", "c", "d"]); |
1 change: 1 addition & 0 deletions
1
packages/babel-plugin-transform-for-of/test/fixtures/spec-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 @@ | ||
for (var x of p2) arr.push(x); |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/spec-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-for-of", { "allowArrayLike": true }] | ||
] | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/babel-plugin-transform-for-of/test/fixtures/spec-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,13 @@ | ||
var _iterator = babelHelpers.createForOfIteratorHelper(p2, true), | ||
_step; | ||
|
||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var x = _step.value; | ||
arr.push(x); | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} |
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