webpro-nl/knip

๐Ÿ› Unexpected unused export when namespace used in array

mlahargou opened this issue ยท 2 comments

Prerequisites

Reproduction url

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

Reproduction access

  • I've made sure the reproduction is publicly accessible

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

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

๐Ÿš€ 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.