Environment
unimport@5.5.0
node@22.21.1
Reproduction
https://github.com/dword-design/demo-unimport-for-loop-destructured
Describe the bug
If there is an array destructuring in a for loop and is followed by some other array declaration, the local variable detection regex will expand until that next closing array and swallow all potential auto imports. The same applies for object destructurings. Example:
for (const [index] of [1,2,3].entries()) {
console.log(`.${AUTO_IMPORTED}`);
const a = [];
}
https://regex101.com/r/nSu02A/1

Result is that the auto imported variable is not initialized.
I think the root cause is that the local variable detection assumes that there is an assignment going on after the variable but this is not the case for for loops.