@@ -12,6 +12,33 @@ use grit_pattern_matcher::pattern::{
1212use grit_util:: error:: GritResult ;
1313use grit_util:: { AnalysisLogs , Language } ;
1414
15+ /// Check if two syntax kinds are compatible for import pattern matching
16+ fn are_import_kinds_compatible (
17+ pattern_kind : GritTargetSyntaxKind ,
18+ node_kind : GritTargetSyntaxKind ,
19+ ) -> bool {
20+ let Some ( pattern_js_kind) = pattern_kind. as_js_kind ( ) else {
21+ return false ;
22+ } ;
23+ let Some ( node_js_kind) = node_kind. as_js_kind ( ) else {
24+ return false ;
25+ } ;
26+
27+ use biome_js_syntax:: JsSyntaxKind :: * ;
28+
29+ // Only allow specific import transformations to avoid over-matching
30+ match ( pattern_js_kind, node_js_kind) {
31+ // Default import pattern can match named import
32+ ( JS_IMPORT_DEFAULT_CLAUSE , JS_IMPORT_NAMED_CLAUSE ) => true ,
33+ // Named import pattern can match default import
34+ ( JS_IMPORT_NAMED_CLAUSE , JS_IMPORT_DEFAULT_CLAUSE ) => true ,
35+ // Default import specifier can match named import specifiers
36+ ( JS_DEFAULT_IMPORT_SPECIFIER , JS_NAMED_IMPORT_SPECIFIERS ) => true ,
37+ ( JS_NAMED_IMPORT_SPECIFIERS , JS_DEFAULT_IMPORT_SPECIFIER ) => true ,
38+ _ => false ,
39+ }
40+ }
41+
1542#[ derive( Clone , Debug ) ]
1643pub struct GritNodePattern {
1744 pub kind : GritTargetSyntaxKind ,
@@ -59,7 +86,7 @@ impl Matcher<GritQueryContext> for GritNodePattern {
5986 ) ;
6087 }
6188
62- if node. kind ( ) != self . kind {
89+ if node. kind ( ) != self . kind && ! are_import_kinds_compatible ( self . kind , node . kind ( ) ) {
6390 return Ok ( false ) ;
6491 }
6592 if self . args . is_empty ( ) {
0 commit comments