diff --git a/src/rules/namespace.ts b/src/rules/namespace.ts index 0d880a96e..c1e29c6b4 100644 --- a/src/rules/namespace.ts +++ b/src/rules/namespace.ts @@ -151,7 +151,10 @@ export = createRule<[Options], MessageId>({ // same as above, but does not add names to local map ExportNamespaceSpecifier(namespace) { - const declaration = importDeclaration(context, namespace) + const declaration = importDeclaration( + context, + namespace as TSESTree.ImportDefaultSpecifier, + ) const imports = ExportMap.get(declaration.source.value, context) if (imports == null) { diff --git a/src/utils/import-declaration.ts b/src/utils/import-declaration.ts index f2fda55c4..40cc3edab 100644 --- a/src/utils/import-declaration.ts +++ b/src/utils/import-declaration.ts @@ -1,11 +1,15 @@ +import { AST_NODE_TYPES } from '@typescript-eslint/utils' import type { TSESTree } from '@typescript-eslint/utils' import type { RuleContext } from '../types' export const importDeclaration = ( context: RuleContext, - node: TSESTree.Node, + node: TSESTree.ImportDefaultSpecifier, ) => { + if (node.parent && node.parent.type === AST_NODE_TYPES.ImportDeclaration) { + return node.parent + } const ancestors = context.sourceCode.getAncestors(node) return ancestors[ancestors.length - 1] as TSESTree.ImportDeclaration } diff --git a/src/utils/resolve.ts b/src/utils/resolve.ts index 805bd7758..3401e3be9 100644 --- a/src/utils/resolve.ts +++ b/src/utils/resolve.ts @@ -125,10 +125,6 @@ function fullResolve( return { found: true, path: cachedPath } } - function cache(resolvedPath: string | null) { - fileExistsCache.set(cacheKey, resolvedPath) - } - function withResolver(resolver: Resolver, config: unknown) { if (resolver.interfaceVersion === 2) { return resolver.resolve(modulePath, sourceFile, config) @@ -170,7 +166,7 @@ function fullResolve( } // else, counts - cache(resolved.path as string | null) + fileExistsCache.set(cacheKey, resolved.path as string | null) return resolved }