@@ -404,25 +404,33 @@ export function importExtractor(node: Node): ImportInfo | null {
404404 moduleNode ?. text ?? "" ,
405405 )
406406
407- // Aliased imports (e.g., "router as users_router")
408- const aliasedImports = getNodesByType ( node ) . get ( "aliased_import" ) ?? [ ]
409- for ( const aliased of aliasedImports ) {
410- const nameNode = aliased . childForFieldName ( "name" )
411- const aliasNode = aliased . childForFieldName ( "alias" )
412- if ( nameNode ) {
413- const alias = aliasNode ?. text ?? null
414- names . push ( alias ?? nameNode . text )
415- namedImports . push ( { name : nameNode . text , alias } )
407+ // Collect imported names: everything after the "import" keyword.
408+ let afterImport = false
409+ for ( let i = 0 ; i < node . childCount ; i ++ ) {
410+ const child = node . child ( i )
411+ if ( ! child ) continue
412+
413+ // Phase 1: scan forward looking for the "import" keyword
414+ if ( ! afterImport ) {
415+ if ( child . type === "import" ) afterImport = true
416+ continue // skip this child either way (module path or the keyword itself)
416417 }
417- }
418418
419- // Non-aliased imports (skip first dotted_name which is the module path)
420- const nameNodes = getNodesByType ( node ) . get ( "dotted_name" ) ?? [ ]
421- for ( let i = 1 ; i < nameNodes . length ; i ++ ) {
422- const nameNode = nameNodes [ i ]
423- if ( ! hasAncestor ( nameNode , "aliased_import" ) ) {
424- names . push ( nameNode . text )
425- namedImports . push ( { name : nameNode . text , alias : null } )
419+ // Phase 2: we're past "import", so each child is an imported name
420+ // (commas and other punctuation are silently skipped by the else branch)
421+ if ( child . type === "aliased_import" ) {
422+ // e.g. "router as users_router"
423+ const nameNode = child . childForFieldName ( "name" )
424+ const aliasNode = child . childForFieldName ( "alias" )
425+ if ( nameNode ) {
426+ const alias = aliasNode ?. text ?? null
427+ names . push ( alias ?? nameNode . text )
428+ namedImports . push ( { name : nameNode . text , alias } )
429+ }
430+ } else if ( child . type === "dotted_name" ) {
431+ // e.g. "users"
432+ names . push ( child . text )
433+ namedImports . push ( { name : child . text , alias : null } )
426434 }
427435 }
428436
0 commit comments