ITADN

Local var detection swallows auto imports after for loop destructuring

#487Closeddword-design 创建于 2025-12-16
bug
D
dword-designcommented
### 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: ```ts for (const [index] of [1,2,3].entries()) { console.log(`.${AUTO_IMPORTED}`); const a = []; } ``` https://regex101.com/r/nSu02A/1 <img width="969" height="221" alt="Image" src="https://github.com/user-attachments/assets/d0b833f7-0384-429e-9964-5d9ec739120d" /> 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.
关闭于 2026-04-13 0 条评论