Skip to content

Commit

Permalink
feat(visit): Make kind() accessible without swc_visit (#9382)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 authored Aug 6, 2024
1 parent 27ffc53 commit 021e41d
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 474 deletions.
8 changes: 8 additions & 0 deletions .changeset/ten-books-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
swc_css_visit: patch
swc_ecma_visit: patch
swc_html_visit: patch
swc_xml_visit: patch
---

feat(visit): Make `AstParentNodeRef.kind()` accessible without depending on `swc_visit`
380 changes: 193 additions & 187 deletions crates/swc_css_visit/src/generated.rs

Large diffs are not rendered by default.

492 changes: 249 additions & 243 deletions crates/swc_ecma_visit/src/generated.rs

Large diffs are not rendered by default.

46 changes: 26 additions & 20 deletions crates/swc_html_visit/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12612,8 +12612,33 @@ pub mod fields {
impl<'ast> ::swc_visit::NodeRef for AstParentNodeRef<'ast> {
type ParentKind = AstParentKind;

#[inline]
#[inline(always)]
fn kind(&self) -> AstParentKind {
self.kind()
}

fn set_index(&mut self, index: usize) {
match self {
Self::Attribute(_, __field_kind) => __field_kind.set_index(index),
Self::AttributeToken(_, __field_kind) => __field_kind.set_index(index),
Self::Child(_, __field_kind) => __field_kind.set_index(index),
Self::Comment(_, __field_kind) => __field_kind.set_index(index),
Self::Document(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentFragment(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentMode(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentType(_, __field_kind) => __field_kind.set_index(index),
Self::Element(_, __field_kind) => __field_kind.set_index(index),
Self::Namespace(_, __field_kind) => __field_kind.set_index(index),
Self::Raw(_, __field_kind) => __field_kind.set_index(index),
Self::Text(_, __field_kind) => __field_kind.set_index(index),
Self::Token(_, __field_kind) => __field_kind.set_index(index),
Self::TokenAndSpan(_, __field_kind) => __field_kind.set_index(index),
}
}
}
impl<'ast> AstParentNodeRef<'ast> {
#[inline]
pub fn kind(&self) -> AstParentKind {
match self {
Self::Attribute(_, __field_kind) => AstParentKind::Attribute(*__field_kind),
Self::AttributeToken(_, __field_kind) => {
Expand All @@ -12635,25 +12660,6 @@ pub mod fields {
Self::TokenAndSpan(_, __field_kind) => AstParentKind::TokenAndSpan(*__field_kind),
}
}

fn set_index(&mut self, index: usize) {
match self {
Self::Attribute(_, __field_kind) => __field_kind.set_index(index),
Self::AttributeToken(_, __field_kind) => __field_kind.set_index(index),
Self::Child(_, __field_kind) => __field_kind.set_index(index),
Self::Comment(_, __field_kind) => __field_kind.set_index(index),
Self::Document(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentFragment(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentMode(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentType(_, __field_kind) => __field_kind.set_index(index),
Self::Element(_, __field_kind) => __field_kind.set_index(index),
Self::Namespace(_, __field_kind) => __field_kind.set_index(index),
Self::Raw(_, __field_kind) => __field_kind.set_index(index),
Self::Text(_, __field_kind) => __field_kind.set_index(index),
Self::Token(_, __field_kind) => __field_kind.set_index(index),
Self::TokenAndSpan(_, __field_kind) => __field_kind.set_index(index),
}
}
}
}
#[cfg(any(docsrs, feature = "path"))]
Expand Down
46 changes: 26 additions & 20 deletions crates/swc_xml_visit/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12084,8 +12084,33 @@ pub mod fields {
impl<'ast> ::swc_visit::NodeRef for AstParentNodeRef<'ast> {
type ParentKind = AstParentKind;

#[inline]
#[inline(always)]
fn kind(&self) -> AstParentKind {
self.kind()
}

fn set_index(&mut self, index: usize) {
match self {
Self::Attribute(_, __field_kind) => __field_kind.set_index(index),
Self::AttributeToken(_, __field_kind) => __field_kind.set_index(index),
Self::CdataSection(_, __field_kind) => __field_kind.set_index(index),
Self::Child(_, __field_kind) => __field_kind.set_index(index),
Self::Comment(_, __field_kind) => __field_kind.set_index(index),
Self::Document(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentMode(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentType(_, __field_kind) => __field_kind.set_index(index),
Self::Element(_, __field_kind) => __field_kind.set_index(index),
Self::Namespace(_, __field_kind) => __field_kind.set_index(index),
Self::ProcessingInstruction(_, __field_kind) => __field_kind.set_index(index),
Self::Text(_, __field_kind) => __field_kind.set_index(index),
Self::Token(_, __field_kind) => __field_kind.set_index(index),
Self::TokenAndSpan(_, __field_kind) => __field_kind.set_index(index),
}
}
}
impl<'ast> AstParentNodeRef<'ast> {
#[inline]
pub fn kind(&self) -> AstParentKind {
match self {
Self::Attribute(_, __field_kind) => AstParentKind::Attribute(*__field_kind),
Self::AttributeToken(_, __field_kind) => {
Expand All @@ -12107,25 +12132,6 @@ pub mod fields {
Self::TokenAndSpan(_, __field_kind) => AstParentKind::TokenAndSpan(*__field_kind),
}
}

fn set_index(&mut self, index: usize) {
match self {
Self::Attribute(_, __field_kind) => __field_kind.set_index(index),
Self::AttributeToken(_, __field_kind) => __field_kind.set_index(index),
Self::CdataSection(_, __field_kind) => __field_kind.set_index(index),
Self::Child(_, __field_kind) => __field_kind.set_index(index),
Self::Comment(_, __field_kind) => __field_kind.set_index(index),
Self::Document(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentMode(_, __field_kind) => __field_kind.set_index(index),
Self::DocumentType(_, __field_kind) => __field_kind.set_index(index),
Self::Element(_, __field_kind) => __field_kind.set_index(index),
Self::Namespace(_, __field_kind) => __field_kind.set_index(index),
Self::ProcessingInstruction(_, __field_kind) => __field_kind.set_index(index),
Self::Text(_, __field_kind) => __field_kind.set_index(index),
Self::Token(_, __field_kind) => __field_kind.set_index(index),
Self::TokenAndSpan(_, __field_kind) => __field_kind.set_index(index),
}
}
}
}
#[cfg(any(docsrs, feature = "path"))]
Expand Down
16 changes: 12 additions & 4 deletions tools/generate-code/src/generators/visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,11 +1440,9 @@ fn define_fields(crate_name: &Ident, node_types: &[&Item]) -> Vec<Item> {
impl<'ast> ::swc_visit::NodeRef for AstParentNodeRef<'ast> {
type ParentKind = AstParentKind;

#[inline]
#[inline(always)]
fn kind(&self) -> AstParentKind {
match self {
#(#node_ref_kind_arms)*
}
self.kind()
}

fn set_index(&mut self, index: usize) {
Expand All @@ -1454,6 +1452,16 @@ fn define_fields(crate_name: &Ident, node_types: &[&Item]) -> Vec<Item> {
}
}
));
defs.push(parse_quote!(
impl<'ast> AstParentNodeRef<'ast> {
#[inline]
pub fn kind(&self) -> AstParentKind {
match self {
#(#node_ref_kind_arms)*
}
}
}
));
}

items.push(parse_quote!(
Expand Down

0 comments on commit 021e41d

Please sign in to comment.