Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ast): add AstKind::AssignmentTargetPattern, AstKind::ArrayAssignmentTarget and AstKind::ObjectAssignmentTarget #4456

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ impl<'a> AstKind<'a> {
Self::ArrayExpressionElement(_) => "ArrayExpressionElement".into(),
Self::AssignmentTarget(_) => "AssignmentTarget".into(),
Self::SimpleAssignmentTarget(_) => "SimpleAssignmentTarget".into(),
Self::AssignmentTargetPattern(_) => "AssignmentTargetPattern".into(),
Self::ArrayAssignmentTarget(_) => "ArrayAssignmentTarget".into(),
Self::ObjectAssignmentTarget(_) => "ObjectAssignmentTarget".into(),
Self::AssignmentTargetWithDefault(_) => "AssignmentTargetWithDefault".into(),
Self::SpreadElement(_) => "SpreadElement".into(),
Self::Elision(_) => "Elision".into(),
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_ast/src/generated/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub enum AstType {
AssignmentExpression,
AssignmentTarget,
SimpleAssignmentTarget,
AssignmentTargetPattern,
ArrayAssignmentTarget,
ObjectAssignmentTarget,
AssignmentTargetWithDefault,
SequenceExpression,
Super,
Expand Down Expand Up @@ -211,6 +214,9 @@ pub enum AstKind<'a> {
AssignmentExpression(&'a AssignmentExpression<'a>),
AssignmentTarget(&'a AssignmentTarget<'a>),
SimpleAssignmentTarget(&'a SimpleAssignmentTarget<'a>),
AssignmentTargetPattern(&'a AssignmentTargetPattern<'a>),
ArrayAssignmentTarget(&'a ArrayAssignmentTarget<'a>),
ObjectAssignmentTarget(&'a ObjectAssignmentTarget<'a>),
AssignmentTargetWithDefault(&'a AssignmentTargetWithDefault<'a>),
SequenceExpression(&'a SequenceExpression<'a>),
Super(&'a Super),
Expand Down Expand Up @@ -382,6 +388,9 @@ impl<'a> GetSpan for AstKind<'a> {
Self::AssignmentExpression(it) => it.span(),
Self::AssignmentTarget(it) => it.span(),
Self::SimpleAssignmentTarget(it) => it.span(),
Self::AssignmentTargetPattern(it) => it.span(),
Self::ArrayAssignmentTarget(it) => it.span(),
Self::ObjectAssignmentTarget(it) => it.span(),
Self::AssignmentTargetWithDefault(it) => it.span(),
Self::SequenceExpression(it) => it.span(),
Self::Super(it) => it.span(),
Expand Down
11 changes: 9 additions & 2 deletions crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,8 @@ pub mod walk {
visitor: &mut V,
it: &AssignmentTargetPattern<'a>,
) {
let kind = AstKind::AssignmentTargetPattern(visitor.alloc(it));
visitor.enter_node(kind);
match it {
AssignmentTargetPattern::ArrayAssignmentTarget(it) => {
visitor.visit_array_assignment_target(it)
Expand All @@ -2758,20 +2760,23 @@ pub mod walk {
visitor.visit_object_assignment_target(it)
}
}
visitor.leave_node(kind);
}

#[inline]
pub fn walk_array_assignment_target<'a, V: Visit<'a>>(
visitor: &mut V,
it: &ArrayAssignmentTarget<'a>,
) {
// NOTE: AstKind doesn't exists!
let kind = AstKind::ArrayAssignmentTarget(visitor.alloc(it));
visitor.enter_node(kind);
for elements in it.elements.iter().flatten() {
visitor.visit_assignment_target_maybe_default(elements);
}
if let Some(rest) = &it.rest {
visitor.visit_assignment_target_rest(rest);
}
visitor.leave_node(kind);
}

#[inline]
Expand Down Expand Up @@ -2815,11 +2820,13 @@ pub mod walk {
visitor: &mut V,
it: &ObjectAssignmentTarget<'a>,
) {
// NOTE: AstKind doesn't exists!
let kind = AstKind::ObjectAssignmentTarget(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_assignment_target_properties(&it.properties);
if let Some(rest) = &it.rest {
visitor.visit_assignment_target_rest(rest);
}
visitor.leave_node(kind);
}

#[inline]
Expand Down
11 changes: 9 additions & 2 deletions crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2868,6 +2868,8 @@ pub mod walk_mut {
visitor: &mut V,
it: &mut AssignmentTargetPattern<'a>,
) {
let kind = AstType::AssignmentTargetPattern;
visitor.enter_node(kind);
match it {
AssignmentTargetPattern::ArrayAssignmentTarget(it) => {
visitor.visit_array_assignment_target(it)
Expand All @@ -2876,20 +2878,23 @@ pub mod walk_mut {
visitor.visit_object_assignment_target(it)
}
}
visitor.leave_node(kind);
}

#[inline]
pub fn walk_array_assignment_target<'a, V: VisitMut<'a>>(
visitor: &mut V,
it: &mut ArrayAssignmentTarget<'a>,
) {
// NOTE: AstType doesn't exists!
let kind = AstType::ArrayAssignmentTarget;
visitor.enter_node(kind);
for elements in it.elements.iter_mut().flatten() {
visitor.visit_assignment_target_maybe_default(elements);
}
if let Some(rest) = &mut it.rest {
visitor.visit_assignment_target_rest(rest);
}
visitor.leave_node(kind);
}

#[inline]
Expand Down Expand Up @@ -2933,11 +2938,13 @@ pub mod walk_mut {
visitor: &mut V,
it: &mut ObjectAssignmentTarget<'a>,
) {
// NOTE: AstType doesn't exists!
let kind = AstType::ObjectAssignmentTarget;
visitor.enter_node(kind);
visitor.visit_assignment_target_properties(&mut it.properties);
if let Some(rest) = &mut it.rest {
visitor.visit_assignment_target_rest(rest);
}
visitor.leave_node(kind);
}

#[inline]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ fn is_read(current_node_id: AstNodeId, nodes: &AstNodes) -> bool {
AstKind::ForInStatement(_)
| AstKind::ForOfStatement(_)
| AstKind::AssignmentTargetWithDefault(_)
| AstKind::AssignmentTarget(_),
| AstKind::AssignmentTarget(_)
| AstKind::ObjectAssignmentTarget(_)
| AstKind::ArrayAssignmentTarget(_),
)
| (AstKind::SimpleAssignmentTarget(_), AstKind::AssignmentExpression(_)) => {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ impl Rule for PreferDomNodeTextContent {
if identifier.name == "innerText"
&& matches!(parent_node_kind, AstKind::PropertyKey(_))
&& (matches!(grand_parent_node_kind, AstKind::ObjectPattern(_))
|| matches!(grand_parent_node_kind, AstKind::AssignmentTarget(_)))
|| matches!(
grand_parent_node_kind,
AstKind::ObjectAssignmentTarget(_)
| AstKind::SimpleAssignmentTarget(_)
| AstKind::AssignmentTarget(_)
))
{
ctx.diagnostic(prefer_dom_node_text_content_diagnostic(identifier.span));
return;
Expand All @@ -77,8 +82,13 @@ impl Rule for PreferDomNodeTextContent {
// `({innerText} = node)`
if let AstKind::IdentifierReference(identifier_ref) = node.kind() {
if identifier_ref.name == "innerText"
&& matches!(parent_node_kind, AstKind::AssignmentTarget(_))
&& matches!(grand_parent_node_kind, AstKind::AssignmentExpression(_))
&& matches!(
parent_node_kind,
AstKind::ObjectAssignmentTarget(_)
| AstKind::AssignmentTarget(_)
| AstKind::SimpleAssignmentTarget(_)
)
&& matches!(grand_parent_node_kind, AstKind::AssignmentTargetPattern(_))
{
ctx.diagnostic(prefer_dom_node_text_content_diagnostic(identifier_ref.span));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/a
"flag": "ReferenceFlag(Read)",
"id": 0,
"name": "obj",
"node_id": 16
"node_id": 18
}
]
},
Expand All @@ -33,7 +33,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/a
"flag": "ReferenceFlag(Write)",
"id": 1,
"name": "b",
"node_id": 20
"node_id": 22
}
]
},
Expand All @@ -47,7 +47,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/a
"flag": "ReferenceFlag(Write)",
"id": 2,
"name": "c",
"node_id": 24
"node_id": 28
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ input_file: crates/oxc_semantic/tests/fixtures/typescript-eslint/destructuring/o
"flag": "ReferenceFlag(Read)",
"id": 2,
"name": "obj",
"node_id": 23
"node_id": 27
}
]
}
Expand Down
5 changes: 1 addition & 4 deletions tasks/ast_codegen/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ use super::generated_header;

pub struct AstKindGenerator;

pub const BLACK_LIST: [&str; 65] = [
pub const BLACK_LIST: [&str; 62] = [
"Expression",
"ObjectPropertyKind",
"TemplateElement",
"ComputedMemberExpression",
"StaticMemberExpression",
"PrivateFieldExpression",
"AssignmentTargetPattern",
"ArrayAssignmentTarget",
"ObjectAssignmentTarget",
"AssignmentTargetRest",
"AssignmentTargetMaybeDefault",
"AssignmentTargetProperty",
Expand Down