diff --git a/crates/oxc_ast/src/ast_kind_impl.rs b/crates/oxc_ast/src/ast_kind_impl.rs index fb5af778c1c4d..781ce3fc5dedf 100644 --- a/crates/oxc_ast/src/ast_kind_impl.rs +++ b/crates/oxc_ast/src/ast_kind_impl.rs @@ -415,6 +415,10 @@ impl AstKind<'_> { Self::JSDocNonNullableType(_) => "JSDocNonNullableType".into(), Self::JSDocUnknownType(_) => "JSDocUnknownType".into(), Self::AssignmentTargetRest(_) => "AssignmentTargetRest".into(), + Self::AssignmentTargetPropertyIdentifier(_) => { + "AssignmentTargetPropertyIdentifier".into() + } + Self::AssignmentTargetPropertyProperty(_) => "AssignmentTargetPropertyProperty".into(), } } } diff --git a/crates/oxc_ast/src/generated/ast_kind.rs b/crates/oxc_ast/src/generated/ast_kind.rs index 3f6ab5e4478e6..a8b5951a6dd78 100644 --- a/crates/oxc_ast/src/generated/ast_kind.rs +++ b/crates/oxc_ast/src/generated/ast_kind.rs @@ -50,159 +50,161 @@ pub enum AstType { ObjectAssignmentTarget = 33, AssignmentTargetRest = 34, AssignmentTargetWithDefault = 35, - SequenceExpression = 36, - Super = 37, - AwaitExpression = 38, - ChainExpression = 39, - ParenthesizedExpression = 40, - Directive = 41, - Hashbang = 42, - BlockStatement = 43, - VariableDeclaration = 44, - VariableDeclarator = 45, - EmptyStatement = 46, - ExpressionStatement = 47, - IfStatement = 48, - DoWhileStatement = 49, - WhileStatement = 50, - ForStatement = 51, - ForInStatement = 52, - ForOfStatement = 53, - ContinueStatement = 54, - BreakStatement = 55, - ReturnStatement = 56, - WithStatement = 57, - SwitchStatement = 58, - SwitchCase = 59, - LabeledStatement = 60, - ThrowStatement = 61, - TryStatement = 62, - CatchClause = 63, - CatchParameter = 64, - DebuggerStatement = 65, - AssignmentPattern = 66, - ObjectPattern = 67, - BindingProperty = 68, - ArrayPattern = 69, - BindingRestElement = 70, - Function = 71, - FormalParameters = 72, - FormalParameter = 73, - FunctionBody = 74, - ArrowFunctionExpression = 75, - YieldExpression = 76, - Class = 77, - ClassBody = 78, - MethodDefinition = 79, - PropertyDefinition = 80, - PrivateIdentifier = 81, - StaticBlock = 82, - ModuleDeclaration = 83, - AccessorProperty = 84, - ImportExpression = 85, - ImportDeclaration = 86, - ImportSpecifier = 87, - ImportDefaultSpecifier = 88, - ImportNamespaceSpecifier = 89, - WithClause = 90, - ImportAttribute = 91, - ExportNamedDeclaration = 92, - ExportDefaultDeclaration = 93, - ExportAllDeclaration = 94, - ExportSpecifier = 95, - V8IntrinsicExpression = 96, - BooleanLiteral = 97, - NullLiteral = 98, - NumericLiteral = 99, - StringLiteral = 100, - BigIntLiteral = 101, - RegExpLiteral = 102, - JSXElement = 103, - JSXOpeningElement = 104, - JSXClosingElement = 105, - JSXFragment = 106, - JSXOpeningFragment = 107, - JSXClosingFragment = 108, - JSXNamespacedName = 109, - JSXMemberExpression = 110, - JSXExpressionContainer = 111, - JSXEmptyExpression = 112, - JSXAttribute = 113, - JSXSpreadAttribute = 114, - JSXIdentifier = 115, - JSXSpreadChild = 116, - JSXText = 117, - TSThisParameter = 118, - TSEnumDeclaration = 119, - TSEnumBody = 120, - TSEnumMember = 121, - TSTypeAnnotation = 122, - TSLiteralType = 123, - TSConditionalType = 124, - TSUnionType = 125, - TSIntersectionType = 126, - TSParenthesizedType = 127, - TSTypeOperator = 128, - TSArrayType = 129, - TSIndexedAccessType = 130, - TSTupleType = 131, - TSNamedTupleMember = 132, - TSOptionalType = 133, - TSRestType = 134, - TSAnyKeyword = 135, - TSStringKeyword = 136, - TSBooleanKeyword = 137, - TSNumberKeyword = 138, - TSNeverKeyword = 139, - TSIntrinsicKeyword = 140, - TSUnknownKeyword = 141, - TSNullKeyword = 142, - TSUndefinedKeyword = 143, - TSVoidKeyword = 144, - TSSymbolKeyword = 145, - TSThisType = 146, - TSObjectKeyword = 147, - TSBigIntKeyword = 148, - TSTypeReference = 149, - TSTypeName = 150, - TSQualifiedName = 151, - TSTypeParameterInstantiation = 152, - TSTypeParameter = 153, - TSTypeParameterDeclaration = 154, - TSTypeAliasDeclaration = 155, - TSClassImplements = 156, - TSInterfaceDeclaration = 157, - TSInterfaceBody = 158, - TSPropertySignature = 159, - TSIndexSignature = 160, - TSCallSignatureDeclaration = 161, - TSMethodSignature = 162, - TSConstructSignatureDeclaration = 163, - TSIndexSignatureName = 164, - TSInterfaceHeritage = 165, - TSTypePredicate = 166, - TSModuleDeclaration = 167, - TSModuleBlock = 168, - TSTypeLiteral = 169, - TSInferType = 170, - TSTypeQuery = 171, - TSImportType = 172, - TSConstructorType = 173, - TSMappedType = 174, - TSTemplateLiteralType = 175, - TSAsExpression = 176, - TSSatisfiesExpression = 177, - TSTypeAssertion = 178, - TSImportEqualsDeclaration = 179, - TSExternalModuleReference = 180, - TSNonNullExpression = 181, - Decorator = 182, - TSExportAssignment = 183, - TSNamespaceExportDeclaration = 184, - TSInstantiationExpression = 185, - JSDocNullableType = 186, - JSDocNonNullableType = 187, - JSDocUnknownType = 188, + AssignmentTargetPropertyIdentifier = 36, + AssignmentTargetPropertyProperty = 37, + SequenceExpression = 38, + Super = 39, + AwaitExpression = 40, + ChainExpression = 41, + ParenthesizedExpression = 42, + Directive = 43, + Hashbang = 44, + BlockStatement = 45, + VariableDeclaration = 46, + VariableDeclarator = 47, + EmptyStatement = 48, + ExpressionStatement = 49, + IfStatement = 50, + DoWhileStatement = 51, + WhileStatement = 52, + ForStatement = 53, + ForInStatement = 54, + ForOfStatement = 55, + ContinueStatement = 56, + BreakStatement = 57, + ReturnStatement = 58, + WithStatement = 59, + SwitchStatement = 60, + SwitchCase = 61, + LabeledStatement = 62, + ThrowStatement = 63, + TryStatement = 64, + CatchClause = 65, + CatchParameter = 66, + DebuggerStatement = 67, + AssignmentPattern = 68, + ObjectPattern = 69, + BindingProperty = 70, + ArrayPattern = 71, + BindingRestElement = 72, + Function = 73, + FormalParameters = 74, + FormalParameter = 75, + FunctionBody = 76, + ArrowFunctionExpression = 77, + YieldExpression = 78, + Class = 79, + ClassBody = 80, + MethodDefinition = 81, + PropertyDefinition = 82, + PrivateIdentifier = 83, + StaticBlock = 84, + ModuleDeclaration = 85, + AccessorProperty = 86, + ImportExpression = 87, + ImportDeclaration = 88, + ImportSpecifier = 89, + ImportDefaultSpecifier = 90, + ImportNamespaceSpecifier = 91, + WithClause = 92, + ImportAttribute = 93, + ExportNamedDeclaration = 94, + ExportDefaultDeclaration = 95, + ExportAllDeclaration = 96, + ExportSpecifier = 97, + V8IntrinsicExpression = 98, + BooleanLiteral = 99, + NullLiteral = 100, + NumericLiteral = 101, + StringLiteral = 102, + BigIntLiteral = 103, + RegExpLiteral = 104, + JSXElement = 105, + JSXOpeningElement = 106, + JSXClosingElement = 107, + JSXFragment = 108, + JSXOpeningFragment = 109, + JSXClosingFragment = 110, + JSXNamespacedName = 111, + JSXMemberExpression = 112, + JSXExpressionContainer = 113, + JSXEmptyExpression = 114, + JSXAttribute = 115, + JSXSpreadAttribute = 116, + JSXIdentifier = 117, + JSXSpreadChild = 118, + JSXText = 119, + TSThisParameter = 120, + TSEnumDeclaration = 121, + TSEnumBody = 122, + TSEnumMember = 123, + TSTypeAnnotation = 124, + TSLiteralType = 125, + TSConditionalType = 126, + TSUnionType = 127, + TSIntersectionType = 128, + TSParenthesizedType = 129, + TSTypeOperator = 130, + TSArrayType = 131, + TSIndexedAccessType = 132, + TSTupleType = 133, + TSNamedTupleMember = 134, + TSOptionalType = 135, + TSRestType = 136, + TSAnyKeyword = 137, + TSStringKeyword = 138, + TSBooleanKeyword = 139, + TSNumberKeyword = 140, + TSNeverKeyword = 141, + TSIntrinsicKeyword = 142, + TSUnknownKeyword = 143, + TSNullKeyword = 144, + TSUndefinedKeyword = 145, + TSVoidKeyword = 146, + TSSymbolKeyword = 147, + TSThisType = 148, + TSObjectKeyword = 149, + TSBigIntKeyword = 150, + TSTypeReference = 151, + TSTypeName = 152, + TSQualifiedName = 153, + TSTypeParameterInstantiation = 154, + TSTypeParameter = 155, + TSTypeParameterDeclaration = 156, + TSTypeAliasDeclaration = 157, + TSClassImplements = 158, + TSInterfaceDeclaration = 159, + TSInterfaceBody = 160, + TSPropertySignature = 161, + TSIndexSignature = 162, + TSCallSignatureDeclaration = 163, + TSMethodSignature = 164, + TSConstructSignatureDeclaration = 165, + TSIndexSignatureName = 166, + TSInterfaceHeritage = 167, + TSTypePredicate = 168, + TSModuleDeclaration = 169, + TSModuleBlock = 170, + TSTypeLiteral = 171, + TSInferType = 172, + TSTypeQuery = 173, + TSImportType = 174, + TSConstructorType = 175, + TSMappedType = 176, + TSTemplateLiteralType = 177, + TSAsExpression = 178, + TSSatisfiesExpression = 179, + TSTypeAssertion = 180, + TSImportEqualsDeclaration = 181, + TSExternalModuleReference = 182, + TSNonNullExpression = 183, + Decorator = 184, + TSExportAssignment = 185, + TSNamespaceExportDeclaration = 186, + TSInstantiationExpression = 187, + JSDocNullableType = 188, + JSDocNonNullableType = 189, + JSDocUnknownType = 190, } /// Untyped AST Node Kind @@ -249,6 +251,10 @@ pub enum AstKind<'a> { AssignmentTargetRest(&'a AssignmentTargetRest<'a>) = AstType::AssignmentTargetRest as u8, AssignmentTargetWithDefault(&'a AssignmentTargetWithDefault<'a>) = AstType::AssignmentTargetWithDefault as u8, + AssignmentTargetPropertyIdentifier(&'a AssignmentTargetPropertyIdentifier<'a>) = + AstType::AssignmentTargetPropertyIdentifier as u8, + AssignmentTargetPropertyProperty(&'a AssignmentTargetPropertyProperty<'a>) = + AstType::AssignmentTargetPropertyProperty as u8, SequenceExpression(&'a SequenceExpression<'a>) = AstType::SequenceExpression as u8, Super(&'a Super) = AstType::Super as u8, AwaitExpression(&'a AwaitExpression<'a>) = AstType::AwaitExpression as u8, @@ -467,6 +473,8 @@ impl GetSpan for AstKind<'_> { Self::ObjectAssignmentTarget(it) => it.span(), Self::AssignmentTargetRest(it) => it.span(), Self::AssignmentTargetWithDefault(it) => it.span(), + Self::AssignmentTargetPropertyIdentifier(it) => it.span(), + Self::AssignmentTargetPropertyProperty(it) => it.span(), Self::SequenceExpression(it) => it.span(), Self::Super(it) => it.span(), Self::AwaitExpression(it) => it.span(), @@ -663,6 +671,8 @@ impl GetAddress for AstKind<'_> { Self::ObjectAssignmentTarget(it) => Address::from_ptr(it), Self::AssignmentTargetRest(it) => Address::from_ptr(it), Self::AssignmentTargetWithDefault(it) => Address::from_ptr(it), + Self::AssignmentTargetPropertyIdentifier(it) => Address::from_ptr(it), + Self::AssignmentTargetPropertyProperty(it) => Address::from_ptr(it), Self::SequenceExpression(it) => Address::from_ptr(it), Self::Super(it) => Address::from_ptr(it), Self::AwaitExpression(it) => Address::from_ptr(it), @@ -1001,6 +1011,20 @@ impl<'a> AstKind<'a> { if let Self::AssignmentTargetWithDefault(v) = self { Some(v) } else { None } } + #[inline] + pub fn as_assignment_target_property_identifier( + self, + ) -> Option<&'a AssignmentTargetPropertyIdentifier<'a>> { + if let Self::AssignmentTargetPropertyIdentifier(v) = self { Some(v) } else { None } + } + + #[inline] + pub fn as_assignment_target_property_property( + self, + ) -> Option<&'a AssignmentTargetPropertyProperty<'a>> { + if let Self::AssignmentTargetPropertyProperty(v) = self { Some(v) } else { None } + } + #[inline] pub fn as_sequence_expression(self) -> Option<&'a SequenceExpression<'a>> { if let Self::SequenceExpression(v) = self { Some(v) } else { None } diff --git a/crates/oxc_ast_visit/src/generated/visit.rs b/crates/oxc_ast_visit/src/generated/visit.rs index f1645f58bd36b..7dd53e1a1ddbf 100644 --- a/crates/oxc_ast_visit/src/generated/visit.rs +++ b/crates/oxc_ast_visit/src/generated/visit.rs @@ -1909,12 +1909,14 @@ pub mod walk { visitor: &mut V, it: &AssignmentTargetPropertyIdentifier<'a>, ) { - // No `AstKind` for this type + let kind = AstKind::AssignmentTargetPropertyIdentifier(visitor.alloc(it)); + visitor.enter_node(kind); visitor.visit_span(&it.span); visitor.visit_identifier_reference(&it.binding); if let Some(init) = &it.init { visitor.visit_expression(init); } + visitor.leave_node(kind); } #[inline] @@ -1922,10 +1924,12 @@ pub mod walk { visitor: &mut V, it: &AssignmentTargetPropertyProperty<'a>, ) { - // No `AstKind` for this type + let kind = AstKind::AssignmentTargetPropertyProperty(visitor.alloc(it)); + visitor.enter_node(kind); visitor.visit_span(&it.span); visitor.visit_property_key(&it.name); visitor.visit_assignment_target_maybe_default(&it.binding); + visitor.leave_node(kind); } #[inline] diff --git a/crates/oxc_ast_visit/src/generated/visit_mut.rs b/crates/oxc_ast_visit/src/generated/visit_mut.rs index 7523ea854c863..1f6050b306773 100644 --- a/crates/oxc_ast_visit/src/generated/visit_mut.rs +++ b/crates/oxc_ast_visit/src/generated/visit_mut.rs @@ -1940,12 +1940,14 @@ pub mod walk_mut { visitor: &mut V, it: &mut AssignmentTargetPropertyIdentifier<'a>, ) { - // No `AstType` for this type + let kind = AstType::AssignmentTargetPropertyIdentifier; + visitor.enter_node(kind); visitor.visit_span(&mut it.span); visitor.visit_identifier_reference(&mut it.binding); if let Some(init) = &mut it.init { visitor.visit_expression(init); } + visitor.leave_node(kind); } #[inline] @@ -1953,10 +1955,12 @@ pub mod walk_mut { visitor: &mut V, it: &mut AssignmentTargetPropertyProperty<'a>, ) { - // No `AstType` for this type + let kind = AstType::AssignmentTargetPropertyProperty; + visitor.enter_node(kind); visitor.visit_span(&mut it.span); visitor.visit_property_key(&mut it.name); visitor.visit_assignment_target_maybe_default(&mut it.binding); + visitor.leave_node(kind); } #[inline] diff --git a/crates/oxc_formatter/src/generated/ast_nodes.rs b/crates/oxc_formatter/src/generated/ast_nodes.rs index 79fab702b5dc7..492480d3ef311 100644 --- a/crates/oxc_formatter/src/generated/ast_nodes.rs +++ b/crates/oxc_formatter/src/generated/ast_nodes.rs @@ -63,6 +63,8 @@ pub enum AstNodes<'a> { ObjectAssignmentTarget(&'a AstNode<'a, ObjectAssignmentTarget<'a>>), AssignmentTargetRest(&'a AstNode<'a, AssignmentTargetRest<'a>>), AssignmentTargetWithDefault(&'a AstNode<'a, AssignmentTargetWithDefault<'a>>), + AssignmentTargetPropertyIdentifier(&'a AstNode<'a, AssignmentTargetPropertyIdentifier<'a>>), + AssignmentTargetPropertyProperty(&'a AstNode<'a, AssignmentTargetPropertyProperty<'a>>), SequenceExpression(&'a AstNode<'a, SequenceExpression<'a>>), Super(&'a AstNode<'a, Super>), AwaitExpression(&'a AstNode<'a, AwaitExpression<'a>>), @@ -2352,6 +2354,8 @@ impl<'a> AstNodes<'a> { Self::ObjectAssignmentTarget(n) => n.span(), Self::AssignmentTargetRest(n) => n.span(), Self::AssignmentTargetWithDefault(n) => n.span(), + Self::AssignmentTargetPropertyIdentifier(n) => n.span(), + Self::AssignmentTargetPropertyProperty(n) => n.span(), Self::SequenceExpression(n) => n.span(), Self::Super(n) => n.span(), Self::AwaitExpression(n) => n.span(), @@ -2547,6 +2551,8 @@ impl<'a> AstNodes<'a> { Self::ObjectAssignmentTarget(n) => n.parent, Self::AssignmentTargetRest(n) => n.parent, Self::AssignmentTargetWithDefault(n) => n.parent, + Self::AssignmentTargetPropertyIdentifier(n) => n.parent, + Self::AssignmentTargetPropertyProperty(n) => n.parent, Self::SequenceExpression(n) => n.parent, Self::Super(n) => n.parent, Self::AwaitExpression(n) => n.parent, @@ -2742,6 +2748,8 @@ impl<'a> AstNodes<'a> { Self::ObjectAssignmentTarget(n) => SiblingNode::from(n.inner), Self::AssignmentTargetRest(n) => SiblingNode::from(n.inner), Self::AssignmentTargetWithDefault(n) => SiblingNode::from(n.inner), + Self::AssignmentTargetPropertyIdentifier(n) => SiblingNode::from(n.inner), + Self::AssignmentTargetPropertyProperty(n) => SiblingNode::from(n.inner), Self::SequenceExpression(n) => SiblingNode::from(n.inner), Self::Super(n) => SiblingNode::from(n.inner), Self::AwaitExpression(n) => SiblingNode::from(n.inner), @@ -2937,6 +2945,8 @@ impl<'a> AstNodes<'a> { Self::ObjectAssignmentTarget(_) => "ObjectAssignmentTarget", Self::AssignmentTargetRest(_) => "AssignmentTargetRest", Self::AssignmentTargetWithDefault(_) => "AssignmentTargetWithDefault", + Self::AssignmentTargetPropertyIdentifier(_) => "AssignmentTargetPropertyIdentifier", + Self::AssignmentTargetPropertyProperty(_) => "AssignmentTargetPropertyProperty", Self::SequenceExpression(_) => "SequenceExpression", Self::Super(_) => "Super", Self::AwaitExpression(_) => "AwaitExpression", @@ -4784,14 +4794,20 @@ impl<'a> AstNode<'a, AssignmentTargetProperty<'a>> { let parent = self.parent; let node = match self.inner { AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(s) => { - panic!( - "No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`" - ) + AstNodes::AssignmentTargetPropertyIdentifier(self.allocator.alloc(AstNode { + inner: s.as_ref(), + parent, + allocator: self.allocator, + following_node: self.following_node, + })) } AssignmentTargetProperty::AssignmentTargetPropertyProperty(s) => { - panic!( - "No kind for current enum variant yet, please see `tasks/ast_tools/src/generators/ast_kind.rs`" - ) + AstNodes::AssignmentTargetPropertyProperty(self.allocator.alloc(AstNode { + inner: s.as_ref(), + parent, + allocator: self.allocator, + following_node: self.following_node, + })) } }; self.allocator.alloc(node) @@ -4818,7 +4834,9 @@ impl<'a> AstNode<'a, AssignmentTargetPropertyIdentifier<'a>> { self.allocator.alloc(AstNode { inner: &self.inner.binding, allocator: self.allocator, - parent: self.parent, + parent: self + .allocator + .alloc(AstNodes::AssignmentTargetPropertyIdentifier(transmute_self(self))), following_node, }) } @@ -4827,11 +4845,15 @@ impl<'a> AstNode<'a, AssignmentTargetPropertyIdentifier<'a>> { pub fn init(&self) -> Option<&AstNode<'a, Expression<'a>>> { let following_node = self.following_node; self.allocator - .alloc(self.inner.init.as_ref().map(|inner| AstNode { - inner, - allocator: self.allocator, - parent: self.parent, - following_node, + .alloc(self.inner.init.as_ref().map(|inner| { + AstNode { + inner, + allocator: self.allocator, + parent: self + .allocator + .alloc(AstNodes::AssignmentTargetPropertyIdentifier(transmute_self(self))), + following_node, + } })) .as_ref() } @@ -4849,7 +4871,9 @@ impl<'a> AstNode<'a, AssignmentTargetPropertyProperty<'a>> { self.allocator.alloc(AstNode { inner: &self.inner.name, allocator: self.allocator, - parent: self.parent, + parent: self + .allocator + .alloc(AstNodes::AssignmentTargetPropertyProperty(transmute_self(self))), following_node, }) } @@ -4860,7 +4884,9 @@ impl<'a> AstNode<'a, AssignmentTargetPropertyProperty<'a>> { self.allocator.alloc(AstNode { inner: &self.inner.binding, allocator: self.allocator, - parent: self.parent, + parent: self + .allocator + .alloc(AstNodes::AssignmentTargetPropertyProperty(transmute_self(self))), following_node, }) } diff --git a/crates/oxc_formatter/src/generated/format.rs b/crates/oxc_formatter/src/generated/format.rs index 230fcab429918..c8978c7e26313 100644 --- a/crates/oxc_formatter/src/generated/format.rs +++ b/crates/oxc_formatter/src/generated/format.rs @@ -629,13 +629,29 @@ impl<'a> Format<'a> for AstNode<'a, AssignmentTargetProperty<'a>> { impl<'a> Format<'a> for AstNode<'a, AssignmentTargetPropertyIdentifier<'a>> { fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> { - self.write(f) + format_leading_comments(self.span).fmt(f)?; + let result = self.write(f); + format_trailing_comments( + &self.parent.as_sibling_node(), + &SiblingNode::from(self.inner), + self.following_node.as_ref(), + ) + .fmt(f)?; + result } } impl<'a> Format<'a> for AstNode<'a, AssignmentTargetPropertyProperty<'a>> { fn fmt(&self, f: &mut Formatter<'_, 'a>) -> FormatResult<()> { - self.write(f) + format_leading_comments(self.span).fmt(f)?; + let result = self.write(f); + format_trailing_comments( + &self.parent.as_sibling_node(), + &SiblingNode::from(self.inner), + self.following_node.as_ref(), + ) + .fmt(f)?; + result } } diff --git a/crates/oxc_linter/src/rules/eslint/func_names.rs b/crates/oxc_linter/src/rules/eslint/func_names.rs index b749cc330eff0..32044894e7648 100644 --- a/crates/oxc_linter/src/rules/eslint/func_names.rs +++ b/crates/oxc_linter/src/rules/eslint/func_names.rs @@ -185,6 +185,9 @@ fn has_inferred_name<'a>(function: &Function<'a>, parent_node: &AstNode<'a>) -> matches!(pattern.left.kind, BindingPatternKind::BindingIdentifier(_)) && is_same_function(&pattern.right, function) } + AstKind::AssignmentTargetPropertyIdentifier(ident) => { + ident.init.as_ref().is_some_and(|expr| is_same_function(expr, function)) + } AstKind::ObjectAssignmentTarget(target) => { for property in &target.properties { let AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(identifier) = diff --git a/crates/oxc_linter/src/rules/eslint/id_length.rs b/crates/oxc_linter/src/rules/eslint/id_length.rs index 0d65424180071..ecbf0d9834c8f 100644 --- a/crates/oxc_linter/src/rules/eslint/id_length.rs +++ b/crates/oxc_linter/src/rules/eslint/id_length.rs @@ -328,7 +328,8 @@ impl IdLength { return; } } - AstKind::ObjectAssignmentTarget(_) => { + AstKind::ObjectAssignmentTarget(_) + | AstKind::AssignmentTargetPropertyProperty(_) => { return; } _ => {} diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs index f66f0f5bf14c6..8665f884ed0cd 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs @@ -132,7 +132,9 @@ fn is_read(current_node_id: NodeId, nodes: &AstNodes) -> bool { | AstKind::AssignmentTarget(_) | AstKind::ObjectAssignmentTarget(_) | AstKind::ArrayAssignmentTarget(_) - | AstKind::AssignmentTargetRest(_), + | AstKind::AssignmentTargetRest(_) + | AstKind::AssignmentTargetPropertyIdentifier(_) + | AstKind::AssignmentTargetPropertyProperty(_), ) | (AstKind::SimpleAssignmentTarget(_), AstKind::AssignmentExpression(_)) => { return false; diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs index 8d4c3131e0075..ba63575492c3f 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs @@ -249,6 +249,8 @@ impl<'a> Symbol<'_, 'a> { match parent { AstKind::IdentifierReference(_) | AstKind::SimpleAssignmentTarget(_) + | AstKind::AssignmentTargetPropertyIdentifier(_) + | AstKind::AssignmentTargetPropertyProperty(_) | AstKind::AssignmentTarget(_) => {} AstKind::AssignmentExpression(assignment) => { return options.is_ignored_assignment_target(self, &assignment.left); diff --git a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs index cb33085b81ba1..45bd2a4440eba 100644 --- a/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs +++ b/crates/oxc_linter/src/rules/unicorn/prefer_dom_node_text_content.rs @@ -67,7 +67,10 @@ impl Rule for PreferDomNodeTextContent { else { return; }; - if matches!(grand_parent_node_kind, AstKind::BindingProperty(_)) { + if matches!( + grand_parent_node_kind, + AstKind::BindingProperty(_) | AstKind::AssignmentTargetPropertyProperty(_) + ) { grand_parent_node_kind = match ancestor_kinds.next() { Some(kind) => kind, None => return, @@ -93,11 +96,13 @@ impl Rule for PreferDomNodeTextContent { } let mut ancestor_kinds = ctx.nodes().ancestor_kinds(node.id()).skip(1); - let (Some(parent_node_kind), Some(grand_parent_node_kind)) = - (ancestor_kinds.next(), ancestor_kinds.next()) - else { - return; - }; + + let Some(mut parent_node_kind) = ancestor_kinds.next() else { return }; + if matches!(parent_node_kind, AstKind::AssignmentTargetPropertyIdentifier(_)) { + let Some(next) = ancestor_kinds.next() else { return }; + parent_node_kind = next; + } + let Some(grand_parent_node_kind) = ancestor_kinds.next() else { return }; if matches!( parent_node_kind, diff --git a/crates/oxc_mangler/src/keep_names.rs b/crates/oxc_mangler/src/keep_names.rs index 93d871c9e2874..d4c4a7a801f2c 100644 --- a/crates/oxc_mangler/src/keep_names.rs +++ b/crates/oxc_mangler/src/keep_names.rs @@ -138,19 +138,14 @@ impl<'a, 'b: 'a> NameSymbolCollector<'a, 'b> { _ => false, } } - AstKind::ObjectAssignmentTarget(assign_target) => { - assign_target.properties.iter().any(|property| { - if let AssignmentTargetProperty::AssignmentTargetPropertyIdentifier(prop_id) = - &property - { - if prop_id.binding.reference_id() == reference_id { - return prop_id.init.as_ref().is_some_and(|init| { - self.is_expression_whose_name_needs_to_be_kept(init) - }); - } - } - false - }) + AstKind::AssignmentTargetPropertyIdentifier(ident) => { + if ident.binding.reference_id() == reference_id { + return ident + .init + .as_ref() + .is_some_and(|init| self.is_expression_whose_name_needs_to_be_kept(init)); + } + false } _ => false, } diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index bb29921eab436..d023cc435bbf7 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -1830,12 +1830,14 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> { &mut self, it: &AssignmentTargetPropertyIdentifier<'a>, ) { - // NOTE: AstKind doesn't exists! + let kind = AstKind::AssignmentTargetPropertyIdentifier(self.alloc(it)); + self.enter_node(kind); self.current_reference_flags = ReferenceFlags::Write; self.visit_identifier_reference(&it.binding); if let Some(init) = &it.init { self.visit_expression(init); } + self.leave_node(kind); } fn visit_export_default_declaration_kind(&mut self, it: &ExportDefaultDeclarationKind<'a>) { diff --git a/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/nested-assignment.snap b/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/nested-assignment.snap index e69364c54af0b..2590d66413d90 100644 --- a/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/nested-assignment.snap +++ b/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/nested-assignment.snap @@ -19,25 +19,25 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/js/assignments/nested-assignm "flags": "ReferenceFlags(Write)", "id": 0, "name": "y", - "node_id": 10 + "node_id": 11 }, { "flags": "ReferenceFlags(Write)", "id": 1, "name": "y", - "node_id": 23 + "node_id": 26 }, { "flags": "ReferenceFlags(Write)", "id": 2, "name": "y", - "node_id": 41 + "node_id": 44 }, { "flags": "ReferenceFlags(Read)", "id": 4, "name": "y", - "node_id": 50 + "node_id": 54 } ] } diff --git a/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.snap b/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.snap index 117c169aaed32..072c75c7787bd 100644 --- a/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.snap +++ b/crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.snap @@ -19,19 +19,19 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.js "flags": "ReferenceFlags(Read)", "id": 1, "name": "read", - "node_id": 15 + "node_id": 16 }, { "flags": "ReferenceFlags(Read)", "id": 5, "name": "read", - "node_id": 32 + "node_id": 37 }, { "flags": "ReferenceFlags(Read)", "id": 6, "name": "read", - "node_id": 33 + "node_id": 38 } ] }, @@ -45,13 +45,13 @@ input_file: crates/oxc_semantic/tests/fixtures/oxc/js/assignments/object.js "flags": "ReferenceFlags(Write)", "id": 2, "name": "write", - "node_id": 20 + "node_id": 22 }, { "flags": "ReferenceFlags(Write)", "id": 3, "name": "write", - "node_id": 30 + "node_id": 34 } ] } diff --git a/crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/object-assignment.snap b/crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/object-assignment.snap index a049800c1c1c9..4f65df0e17c98 100644 --- a/crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/object-assignment.snap +++ b/crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/object-assignment.snap @@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/o "flags": "ReferenceFlags(Read)", "id": 2, "name": "obj", - "node_id": 27 + "node_id": 31 } ] } diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index 2f9e252235c76..06ccf719347cd 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -26,13 +26,7 @@ use super::define_generator; /// Structs to omit creating an `AstKind` for. /// /// Apart from this list, every struct with `#[ast(visit)]` attr gets an `AstKind`. -const STRUCTS_BLACK_LIST: &[&str] = &[ - "AssignmentTargetPropertyIdentifier", - "AssignmentTargetPropertyProperty", - "BindingPattern", - "TSFunctionType", - "Span", -]; +const STRUCTS_BLACK_LIST: &[&str] = &["BindingPattern", "TSFunctionType", "Span"]; /// Enums to create an `AstKind` for. ///