ITADN

Deduplication offset when some imports are disabled

#505Open8ctavio 创建于 2026-03-12
bug
8
8ctaviocommented
### Environment node: v20.19.1 unimport: v6.0.1 ### Reproduction https://stackblitz.com/edit/stackblitz-starters-tzuzsfbw?file=index.js&view=editor ```sh pnpm install && node index.js ``` See input and output of `getImports()`; duplicates are not correctly deduplicated. ### Describe the bug The `dedupeImports` function manages a `Set` of imports array indexes that need to be removed (deduplicated). However, [`imports` is first filtered](https://github.com/unjs/unimport/blob/v6.0.1/src/utils.ts#L119) to remove disabled imports, which could cause an offset of collected indexes from the original `imports` array. For instance, for the imports: ```js [{ name: 'disabled', from: 'anywhere.js', disabled: true, },{ name: 'foo', from: 'somewhere.js', },{ name: 'foo', from: 'elsewhere.js', }] ``` the index `1` should be removed, but since the filtered array does not have the disabled import, index `0` will be marked for removal, which ultimately causes the disabled import to be removed instead of the duplicated import. I am planning to submit a PR to fix this. ### Additional context _No response_ ### Logs ```sh Duplicated imports "foo", the one from "anywhere.js" has been ignored and "elsewhere.js" is used [ { name: 'foo', from: 'somewhere.js', as: 'foo' }, { name: 'foo', from: 'elsewhere.js', as: 'foo' } ] ```
0 条评论