-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correctly preserve reference to array in for-of loop #9697
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to move this inside the
for
head?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes i actually did that, but it changes a lot of tests. Would do it separate.