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
7.06k stars 177 forks source link

🐛 Unexpected unused export when namespace used in array #844

Closed mlahargou closed 5 days ago

mlahargou commented 5 days ago

Prerequisites

Reproduction url

https://stackblitz.com/edit/stackblitz-starters-evsylk?file=index.js

Reproduction access

Description of the issue

I have a use case where I import a namespace. I then add that namespace to an array and pass it to a function. Knip is marking the namespace exports as unused. I've ensured that nsExports is not included.

Repro:

// namespace.js
export const foo = 'foo';
export const bar = 'bar';
// index.js
import * as NS from './namespace.js';

// This does throw errors
console.log([NS]);

// This doesn't throw errors
// console.log(NS);

Output:

> npm exec knip
Unused exports (2)
foo  NS  unknown  namespace.js:1:14
bar  NS  unknown  namespace.js:2:14
webpro commented 5 days ago

Thanks for the report @mlahargou, fix will be in the next one!

webpro commented 4 days ago

:rocket: This issue has been resolved in v5.37.2. See Release 5.37.2 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.