@@ -87,9 +87,9 @@ def unreferenced_components(self) -> list[Finding]:
8787 r"\.([a-zA-Z_][\w-]*(?::[\w-]+)*)\s*(?:\{|,|\[)" ,
8888)
8989
90- # import statements
90+ # import statements (handles default, named, type-only, and mixed forms)
9191_IMPORT_PATTERN = re .compile (
92- r"import\s+(?:\ {([^}]+)\}|(\w+))\s+ from\s+['\"]([^'\"]+)['\"]" ,
92+ r"import\s+(?:type\s+)?(?:(\w+))?\s*,?\s*(?:\ {([^}]+)\})?\s* from\s+['\"]([^'\"]+)['\"]" ,
9393)
9494
9595# className="..." or className={...} in JSX
@@ -300,18 +300,26 @@ def _parse_exports(
300300 def _parse_imports (
301301 self , content : str , rel_path : str , imports : dict [str , set [str ]]
302302 ) -> None :
303- """Extract import names from a file."""
303+ """Extract import names from a file.
304+
305+ Handles default, named, type-only, and mixed import forms:
306+ import Foo from '...'
307+ import { Foo, Bar } from '...'
308+ import type { Foo } from '...'
309+ import Foo, { Bar } from '...'
310+ """
304311 for m in _IMPORT_PATTERN .finditer (content ):
305- # Named imports: import { Foo, Bar } from '...'
306- if m .group (1 ):
307- names = [n .strip ().split (" as " )[0 ].strip () for n in m .group (1 ).split ("," )]
312+ default_import = m .group (1 )
313+ named_imports = m .group (2 )
314+ module_path = m .group (3 )
315+
316+ if default_import :
317+ imports .setdefault (default_import , set ()).add (rel_path )
318+ if named_imports :
319+ names = [n .strip ().split (" as " )[0 ].strip () for n in named_imports .split ("," )]
308320 for name in names :
309321 if name :
310322 imports .setdefault (name , set ()).add (rel_path )
311- # Default import: import Foo from '...'
312- elif m .group (2 ):
313- name = m .group (2 )
314- imports .setdefault (name , set ()).add (rel_path )
315323
316324 def _parse_css_classes (
317325 self , content : str , rel_path : str , css_classes : dict [str , list [tuple [str , int ]]]
0 commit comments