diff --git a/packages/docs/src/content/docs/guides/namespace-imports.md b/packages/docs/src/content/docs/guides/namespace-imports.md index 9cc06392c..c3e9e8029 100644 --- a/packages/docs/src/content/docs/guides/namespace-imports.md +++ b/packages/docs/src/content/docs/guides/namespace-imports.md @@ -79,6 +79,8 @@ const shorthand = { NS }; const assignment = NS; +const item = [NS]; + type TypeOf = typeof NS; export { NS }; diff --git a/packages/knip/fixtures/imports-namespace/index.ts b/packages/knip/fixtures/imports-namespace/index.ts index 409007ec0..f48fa6f4d 100644 --- a/packages/knip/fixtures/imports-namespace/index.ts +++ b/packages/knip/fixtures/imports-namespace/index.ts @@ -5,6 +5,8 @@ import * as NS3 from './namespace3'; import * as NS4 from './namespace4'; import * as NS5 from './namespace5'; import * as NS6 from './namespace6'; +import * as NS7 from './namespace7'; +import * as NS8 from './namespace8'; import fn from 'external'; NS.identifier15; @@ -24,3 +26,7 @@ fn(NS4); const spread = { ...NS5 }; const assign = NS6; + +fn([NS7]); + +fn({ NS8 }); diff --git a/packages/knip/fixtures/imports-namespace/namespace7.ts b/packages/knip/fixtures/imports-namespace/namespace7.ts new file mode 100644 index 000000000..f4054b4e1 --- /dev/null +++ b/packages/knip/fixtures/imports-namespace/namespace7.ts @@ -0,0 +1,2 @@ +export const identifier39 = 39; +export const identifier40 = 40; diff --git a/packages/knip/fixtures/imports-namespace/namespace8.ts b/packages/knip/fixtures/imports-namespace/namespace8.ts new file mode 100644 index 000000000..cedd9205d --- /dev/null +++ b/packages/knip/fixtures/imports-namespace/namespace8.ts @@ -0,0 +1,2 @@ +export const identifier41 = 41; +export const identifier42 = 42; diff --git a/packages/knip/src/typescript/ast-helpers.ts b/packages/knip/src/typescript/ast-helpers.ts index abd79ca65..0ca284c81 100644 --- a/packages/knip/src/typescript/ast-helpers.ts +++ b/packages/knip/src/typescript/ast-helpers.ts @@ -173,6 +173,7 @@ export const isConsiderReferencedNS = (node: ts.Identifier) => ts.isShorthandPropertyAssignment(node.parent) || (ts.isCallExpression(node.parent) && node.parent.arguments.includes(node)) || ts.isSpreadAssignment(node.parent) || + ts.isArrayLiteralExpression(node.parent) || ts.isExportAssignment(node.parent) || (ts.isVariableDeclaration(node.parent) && node.parent.initializer === node) || ts.isTypeQueryNode(node.parent); diff --git a/packages/knip/test/imports-namespace.test.ts b/packages/knip/test/imports-namespace.test.ts index 717fd89f5..9cd1abe93 100644 --- a/packages/knip/test/imports-namespace.test.ts +++ b/packages/knip/test/imports-namespace.test.ts @@ -16,7 +16,7 @@ test('Ignore namespace re-export by entry file', async () => { assert.deepEqual(counters, { ...baseCounters, unlisted: 1, - processed: 8, - total: 8, + processed: 10, + total: 10, }); });