-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix(es/fixer): Wrap in
expr in for-in head
#9209
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2012a9b
fix(es/base): Wrap `in` expr in for-in head
magic-akari 81b0d11
fix
magic-akari 5293ea0
refactor
magic-akari 35a7bda
chore: clean code
magic-akari 5d4f47f
chore: clean code
magic-akari d33b0ed
fix
magic-akari 7cda378
fix
magic-akari fae3309
chore: add comments
magic-akari 05d28a6
chore: update test cases
magic-akari a50f036
Merge branch 'main' into fix/issue-9200
kdy1 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
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,20 @@ | ||
{ | ||
"jsc": { | ||
"parser": { | ||
"syntax": "typescript", | ||
"tsx": true, | ||
"decorators": true | ||
}, | ||
"loose": false, | ||
"minify": { | ||
"compress": false, | ||
"mangle": false | ||
}, | ||
"target": "es2022" | ||
}, | ||
"module": { | ||
"type": "es6" | ||
}, | ||
"minify": false, | ||
"isModule": false | ||
} |
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 @@ | ||
let count = 0; | ||
for (var a = 1 || (2 in {}) in { x: 1 }) count++; | ||
console.log(count); |
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,47 @@ | ||
for (var a = (b in c) in {}); | ||
for (var a = 1 || (b in c) in {}); | ||
for (var a = 1 + (2 || (b in c)) in {}); | ||
for (var a = (() => b in c) in {}); | ||
for (var a = 1 || (() => b in c) in {}); | ||
for (var a = (() => { b in c; }) in {}); | ||
for (var a = [b in c] in {}); | ||
for (var a = {b: b in c} in {}); | ||
for (var a = (x = b in c) => {} in {}); | ||
for (var a = class extends (b in c) {} in {}); | ||
for (var a = function (x = b in c) {} in {}); | ||
|
||
for (var a = (b in c);;); | ||
for (var a = 1 || (b in c);;); | ||
for (var a = 1 + (2 || (b in c));;); | ||
for (var a = (() => b in c);;); | ||
for (var a = 1 || (() => b in c);;); | ||
for (var a = (() => { b in c; });;); | ||
for (var a = [b in c];;); | ||
for (var a = {b: b in c};;); | ||
for (var a = (x = b in c) => {};;); | ||
for (var a = class extends (b in c) {};;); | ||
for (var a = function (x = b in c) {};;); | ||
|
||
for (var a in (b in c)); | ||
for (var a in 1 || (b in c)); | ||
for (var a in 1 + (2 || (b in c))); | ||
for (var a in (() => b in c)); | ||
for (var a in 1 || (() => b in c)); | ||
for (var a in (() => { b in c; })); | ||
for (var a in [b in c]); | ||
for (var a in {b: b in c}); | ||
for (var a in (x = b in c) => {}); | ||
for (var a in class extends (b in c) {}); | ||
for (var a in function (x = b in c) {}); | ||
|
||
for (;a = (b in c);); | ||
for (;a = 1 || (b in c);); | ||
for (;a = 1 + (2 || (b in c));); | ||
for (;a = (() => b in c);); | ||
for (;a = 1 || (() => b in c);); | ||
for (;a = (() => { b in c; });); | ||
for (;a = [b in c];); | ||
for (;a = {b: b in c};); | ||
for (;a = (x = b in c) => {};); | ||
for (;a = class extends (b in c) {};); | ||
for (;a = function (x = b in c) {};); |
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 @@ | ||
let count = 0; | ||
for(var a = 1 || (2 in {}) in { | ||
x: 1 | ||
})count++; | ||
console.log(count); |
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,72 @@ | ||
for(var a = (b in c) in {}); | ||
for(var a = 1 || (b in c) in {}); | ||
for(var a = 1 + (2 || (b in c)) in {}); | ||
for(var a = ()=>(b in c) in {}); | ||
for(var a = 1 || (()=>(b in c)) in {}); | ||
for(var a = ()=>{ | ||
b in c; | ||
} in {}); | ||
for(var a = [ | ||
b in c | ||
] in {}); | ||
for(var a = { | ||
b: b in c | ||
} in {}); | ||
for(var a = (x = b in c)=>{} in {}); | ||
for(var a = class extends (b in c) { | ||
} in {}); | ||
for(var a = function(x = b in c) {} in {}); | ||
for(var a = (b in c);;); | ||
for(var a = 1 || (b in c);;); | ||
for(var a = 1 + (2 || (b in c));;); | ||
for(var a = ()=>(b in c);;); | ||
for(var a = 1 || (()=>(b in c));;); | ||
for(var a = ()=>{ | ||
b in c; | ||
};;); | ||
for(var a = [ | ||
b in c | ||
];;); | ||
for(var a = { | ||
b: b in c | ||
};;); | ||
for(var a = (x = b in c)=>{};;); | ||
for(var a = class extends (b in c) { | ||
};;); | ||
for(var a = function(x = b in c) {};;); | ||
for(var a in b in c); | ||
for(var a in 1 || b in c); | ||
for(var a in 1 + (2 || b in c)); | ||
for(var a in ()=>b in c); | ||
for(var a in 1 || (()=>b in c)); | ||
for(var a in ()=>{ | ||
b in c; | ||
}); | ||
for(var a in [ | ||
b in c | ||
]); | ||
for(var a in { | ||
b: b in c | ||
}); | ||
for(var a in (x = b in c)=>{}); | ||
for(var a in class extends (b in c) { | ||
}); | ||
for(var a in function(x = b in c) {}); | ||
for(; a = b in c;); | ||
for(; a = 1 || b in c;); | ||
for(; a = 1 + (2 || b in c);); | ||
for(; a = ()=>b in c;); | ||
for(; a = 1 || (()=>b in c);); | ||
for(; a = ()=>{ | ||
b in c; | ||
};); | ||
for(; a = [ | ||
b in c | ||
];); | ||
for(; a = { | ||
b: b in c | ||
};); | ||
for(; a = (x = b in c)=>{};); | ||
for(; a = class extends (b in c) { | ||
};); | ||
for(; a = function(x = b in c) {};); |
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
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
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
Oops, something went wrong.
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.
We have some false positives. It is no longer necessary to add parentheses around the
in
expression that is already in parentheses.We need to check the
in
expressions from the outside in. But currently, thewrap
calls are from the inside out, which cannot be completed in a single pass.Do you have any thoughts? @kdy1
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.
Can we proceed with some false positives for now and refactor them outside? If you prefer, rewriting the fixer to work outside in is also fine.
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.
I plan to leave a TODO for now, as this is a very rare edge case and has no negative impact.