webpro-nl / knip

✂️ Find unused files, dependencies and exports in your JavaScript and TypeScript projects. Knip it before you ship it!
https://knip.dev
ISC License
6.14k stars 140 forks source link

Exports previously legitimately reported as unused are no longer reported #708

Open neelmraman opened 2 weeks ago

neelmraman commented 2 weeks ago

Hi, after seeing that #697 was closed, I updated knip in the repro for that issue (here) to verify.

The behavior on v5.23.0 was that a, b, c, and d were reported as unused while the other two exports that used multiline exports were not reported (even though they were also unused). The new behavior on v5.23.1 is that none of the exports are reported as unused.

webpro commented 2 weeks ago

There's a few things to this one. We're only talking about the combination of:

Unfortunately, internally when using the TypeScript AST nodes there's a big difference between these notations:

export const id = 1;
const id = 1;
export { id };

With the latter syntax, I couldn't find a reliable way to detect whether id was used more often or not within the same module. That's why I've opted for the stability of assuming export { id } is referenced (which technically could be argued it is, but it could be only the declaration, not other usage).

So this is the situation now, until we've found a reliable way to do it better.

Additional notes: