Skip to content

Commit

Permalink
Fix issue with ignoreLocallyUsed (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
DLeyland authored May 24, 2024
1 parent 85ec00c commit 2de1973
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
23 changes: 23 additions & 0 deletions features/ignore-locally-used.feature
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,26 @@ Scenario: ignoreLocallyUsed works with more complex file extensions
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

Scenario: ignoreLocallyUsed works with template literals
Given file "local.test.ts" is
"""
export const a = 1;
const b = `text ${a} some more text`;
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

Scenario: ignoreLocallyUsed works with objects
Given file "local.test.ts" is
"""
export const a = 1;
export const b = 2;
const c = {
a
};
c['b'] = b;
"""
When running ts-unused-exports "tsconfig.json" --ignoreLocallyUsed
Then the CLI result at status is 0

7 changes: 1 addition & 6 deletions src/parser/nodeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,7 @@ export const processNode = (
addImportsFromNamespace(node, imports, addImport);
}

if (
extraOptions?.ignoreLocallyUsed &&
kind === ts.SyntaxKind.Identifier &&
node.parent.kind !== ts.SyntaxKind.VariableDeclaration &&
node.parent.kind !== ts.SyntaxKind.FunctionDeclaration
) {
if (extraOptions?.ignoreLocallyUsed && kind === ts.SyntaxKind.Identifier) {
addImport({
from: removeTsFileExtension(node.getSourceFile().fileName),
what: [node.getText()],
Expand Down

0 comments on commit 2de1973

Please sign in to comment.