@@ -55,92 +55,91 @@ const REFLECT_MUTATION_METHODS: [&str; 4] =
5555
5656impl Rule for NoImportAssign {
5757 fn run < ' a > ( & self , node : & AstNode < ' a > , ctx : & LintContext < ' a > ) {
58- if let AstKind :: ImportDeclaration ( import_decl) = node. kind ( ) {
59- let symbol_table = ctx. scoping ( ) ;
60- if let Some ( specifiers) = & import_decl. specifiers {
61- for specifier in specifiers {
62- let symbol_id = specifier. local ( ) . symbol_id ( ) ;
63- let is_namespace_specifier = matches ! (
64- specifier,
65- oxc_ast:: ast:: ImportDeclarationSpecifier :: ImportNamespaceSpecifier ( _)
66- ) ;
67- for reference in symbol_table. get_resolved_references ( symbol_id) {
68- if is_namespace_specifier {
69- let parent_node = ctx. nodes ( ) . parent_node ( reference. node_id ( ) ) ;
70- if parent_node. kind ( ) . is_member_expression_kind ( ) {
71- let expr = parent_node. kind ( ) ;
72- let parent_parent_node = ctx. nodes ( ) . parent_node ( parent_node. id ( ) ) ;
73- let is_unary_expression_with_delete_operator = |kind| {
74- matches ! (
75- kind,
76- AstKind :: UnaryExpression ( expr)
77- if expr. operator == UnaryOperator :: Delete
78- )
79- } ;
80- let parent_parent_kind = parent_parent_node. kind ( ) ;
81- if ( matches ! ( parent_parent_kind, AstKind :: IdentifierReference ( _) )
82- || is_unary_expression_with_delete_operator ( parent_parent_kind)
83- || matches ! ( parent_parent_kind, AstKind :: ChainExpression ( _) if is_unary_expression_with_delete_operator( ctx. nodes( ) . parent_kind( parent_parent_node. id( ) ) ) ) )
84- && let Some ( ( span, _) ) = match expr {
85- AstKind :: StaticMemberExpression ( expr) => {
86- Some ( expr. static_property_info ( ) )
87- }
88- AstKind :: ComputedMemberExpression ( expr) => {
89- expr. static_property_info ( )
90- }
91- _ => return ,
92- }
93- && span != ctx. semantic ( ) . reference_span ( reference)
94- {
95- return ctx
96- . diagnostic ( no_import_assign_diagnostic ( expr. span ( ) ) ) ;
97- }
98- // Check for assignment to namespace property
99- match expr {
100- AstKind :: StaticMemberExpression ( member_expr) => {
101- let condition_met = is_assignment_condition_met (
102- & parent_parent_kind,
103- parent_node. span ( ) ,
104- true , // is_static
105- ) ;
106- check_namespace_member_assignment (
107- & member_expr. object ,
108- parent_node,
109- reference,
110- ctx,
111- condition_met,
112- ) ;
58+ let AstKind :: ImportDeclaration ( import_decl) = node. kind ( ) else { return } ;
59+
60+ let symbol_table = ctx. scoping ( ) ;
61+ if let Some ( specifiers) = & import_decl. specifiers {
62+ for specifier in specifiers {
63+ let symbol_id = specifier. local ( ) . symbol_id ( ) ;
64+ let is_namespace_specifier = matches ! (
65+ specifier,
66+ oxc_ast:: ast:: ImportDeclarationSpecifier :: ImportNamespaceSpecifier ( _)
67+ ) ;
68+ for reference in symbol_table. get_resolved_references ( symbol_id) {
69+ if is_namespace_specifier {
70+ let parent_node = ctx. nodes ( ) . parent_node ( reference. node_id ( ) ) ;
71+ if parent_node. kind ( ) . is_member_expression_kind ( ) {
72+ let expr = parent_node. kind ( ) ;
73+ let parent_parent_node = ctx. nodes ( ) . parent_node ( parent_node. id ( ) ) ;
74+ let is_unary_expression_with_delete_operator = |kind| {
75+ matches ! (
76+ kind,
77+ AstKind :: UnaryExpression ( expr)
78+ if expr. operator == UnaryOperator :: Delete
79+ )
80+ } ;
81+ let parent_parent_kind = parent_parent_node. kind ( ) ;
82+ if ( matches ! ( parent_parent_kind, AstKind :: IdentifierReference ( _) )
83+ || is_unary_expression_with_delete_operator ( parent_parent_kind)
84+ || matches ! ( parent_parent_kind, AstKind :: ChainExpression ( _) if is_unary_expression_with_delete_operator( ctx. nodes( ) . parent_kind( parent_parent_node. id( ) ) ) ) )
85+ && let Some ( ( span, _) ) = match expr {
86+ AstKind :: StaticMemberExpression ( expr) => {
87+ Some ( expr. static_property_info ( ) )
11388 }
114- AstKind :: ComputedMemberExpression ( member_expr) => {
115- let condition_met = is_assignment_condition_met (
116- & parent_parent_kind,
117- parent_node. span ( ) ,
118- false , // is_static
119- ) ;
120- check_namespace_member_assignment (
121- & member_expr. object ,
122- parent_node,
123- reference,
124- ctx,
125- condition_met,
126- ) ;
89+ AstKind :: ComputedMemberExpression ( expr) => {
90+ expr. static_property_info ( )
12791 }
128- _ => { }
92+ _ => return ,
93+ }
94+ && span != ctx. semantic ( ) . reference_span ( reference)
95+ {
96+ return ctx. diagnostic ( no_import_assign_diagnostic ( expr. span ( ) ) ) ;
97+ }
98+ // Check for assignment to namespace property
99+ match expr {
100+ AstKind :: StaticMemberExpression ( member_expr) => {
101+ let condition_met = is_assignment_condition_met (
102+ & parent_parent_kind,
103+ parent_node. span ( ) ,
104+ true , // is_static
105+ ) ;
106+ check_namespace_member_assignment (
107+ & member_expr. object ,
108+ parent_node,
109+ reference,
110+ ctx,
111+ condition_met,
112+ ) ;
113+ }
114+ AstKind :: ComputedMemberExpression ( member_expr) => {
115+ let condition_met = is_assignment_condition_met (
116+ & parent_parent_kind,
117+ parent_node. span ( ) ,
118+ false , // is_static
119+ ) ;
120+ check_namespace_member_assignment (
121+ & member_expr. object ,
122+ parent_node,
123+ reference,
124+ ctx,
125+ condition_met,
126+ ) ;
129127 }
128+ _ => { }
130129 }
131130 }
131+ }
132132
133- if reference. is_write ( )
134- || ( is_namespace_specifier
135- && is_argument_of_well_known_mutation_function (
136- reference. node_id ( ) ,
137- ctx,
138- ) )
139- {
140- ctx. diagnostic ( no_import_assign_diagnostic (
141- ctx. semantic ( ) . reference_span ( reference) ,
142- ) ) ;
143- }
133+ if reference. is_write ( )
134+ || ( is_namespace_specifier
135+ && is_argument_of_well_known_mutation_function (
136+ reference. node_id ( ) ,
137+ ctx,
138+ ) )
139+ {
140+ ctx. diagnostic ( no_import_assign_diagnostic (
141+ ctx. semantic ( ) . reference_span ( reference) ,
142+ ) ) ;
144143 }
145144 }
146145 }
0 commit comments