-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly preserve reference to array in for-of loop (#9697)
* Correctly preserve reference to array in for-of loop * Add more tests
- Loading branch information
Showing
10 changed files
with
60 additions
and
18 deletions.
There are no files selected for viewing
5 changes: 3 additions & 2 deletions
5
packages/babel-core/test/fixtures/transformation/misc/regression-1169/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
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
3 changes: 3 additions & 0 deletions
3
...ges/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-of-redeclare/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,3 @@ | ||
for (let o of arr) { | ||
const arr = o; | ||
} |
4 changes: 4 additions & 0 deletions
4
...es/babel-plugin-transform-for-of/test/fixtures/for-of-as-array/for-of-redeclare/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 (let _i = 0, _arr = arr; _i < _arr.length; _i++) { | ||
let o = _arr[_i]; | ||
const arr = o; | ||
} |
10 changes: 6 additions & 4 deletions
10
packages/babel-plugin-transform-for-of/test/fixtures/opt/array-binding/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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
const x = []; | ||
var _arr = x; | ||
|
||
for (var _i = 0; _i < x.length; _i++) { | ||
const y = x[_i]; | ||
for (var _i = 0; _i < _arr.length; _i++) { | ||
const y = _arr[_i]; | ||
} | ||
|
||
const arr = Object.entries(x); | ||
var _arr2 = arr; | ||
|
||
for (var _i2 = 0; _i2 < arr.length; _i2++) { | ||
const y = arr[_i2]; | ||
for (var _i2 = 0; _i2 < _arr2.length; _i2++) { | ||
const y = _arr2[_i2]; | ||
} |
5 changes: 5 additions & 0 deletions
5
...ages/babel-plugin-transform-for-of/test/fixtures/regression/redeclare-array-8913/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,5 @@ | ||
function f(...t) { | ||
for (let o of t) { | ||
const t = o; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...ges/babel-plugin-transform-for-of/test/fixtures/regression/redeclare-array-8913/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,8 @@ | ||
function f(...t) { | ||
var _arr = t; | ||
|
||
for (var _i = 0; _i < _arr.length; _i++) { | ||
let o = _arr[_i]; | ||
const t = o; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/babel-plugin-transform-for-of/test/fixtures/regression/scope-9696/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,9 @@ | ||
var arr = [1, 2, 3]; | ||
var results = []; | ||
|
||
for (let v of arr) { | ||
results.push(v); | ||
arr = null; | ||
} | ||
|
||
expect(results).toEqual([1, 2, 3]); |
6 changes: 6 additions & 0 deletions
6
packages/babel-plugin-transform-for-of/test/fixtures/regression/scope-9696/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,6 @@ | ||
var arr = [1,2,3] | ||
|
||
for (let v of arr) { | ||
console.log(v) | ||
arr = null | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/babel-plugin-transform-for-of/test/fixtures/regression/scope-9696/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,8 @@ | ||
var arr = [1, 2, 3]; | ||
var _arr = arr; | ||
|
||
for (var _i = 0; _i < _arr.length; _i++) { | ||
let v = _arr[_i]; | ||
console.log(v); | ||
arr = null; | ||
} |