From 5f1c7ecad778fd428dc7a892fe7264e490ff5adc Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Sat, 20 Jul 2024 12:02:25 +0000 Subject: [PATCH] refactor(ast): rename the `visited_node` marker to `ast`. (#4289) closes #4282 I went with `#[ast(visit)]` but we can change it to 2 separate markers as suggested by @overlookmotel in the issue. --- crates/oxc_ast/src/ast/js.rs | 236 +++++++++++----------- crates/oxc_ast/src/ast/jsx.rs | 42 ++-- crates/oxc_ast/src/ast/literal.rs | 14 +- crates/oxc_ast/src/ast/ts.rs | 170 ++++++++-------- crates/oxc_ast/src/ast_impl/js.rs | 3 - crates/oxc_ast/src/ast_impl/literal.rs | 3 - crates/oxc_ast/src/ast_impl/ts.rs | 3 - crates/oxc_ast_macros/src/lib.rs | 14 +- crates/oxc_traverse/scripts/lib/parse.mjs | 5 +- crates/oxc_traverse/scripts/lib/walk.mjs | 2 +- tasks/ast_codegen/src/main.rs | 4 +- tasks/ast_codegen/src/schema.rs | 73 +++++-- tasks/ast_codegen/src/util.rs | 13 ++ 13 files changed, 317 insertions(+), 265 deletions(-) diff --git a/crates/oxc_ast/src/ast/js.rs b/crates/oxc_ast/src/ast/js.rs index 101ff788ec644..4c516b71391b8 100644 --- a/crates/oxc_ast/src/ast/js.rs +++ b/crates/oxc_ast/src/ast/js.rs @@ -8,7 +8,7 @@ use std::cell::Cell; use oxc_allocator::{Box, Vec}; -use oxc_ast_macros::visited_node; +use oxc_ast_macros::ast; use oxc_span::{Atom, SourceType, Span}; use oxc_syntax::{ operator::{ @@ -27,7 +27,7 @@ use serde::Serialize; #[cfg(feature = "serialize")] use tsify::Tsify; -#[visited_node] +#[ast(visit)] #[scope( flags(ScopeFlags::Top), strict_if(self.source_type.is_strict() || self.directives.iter().any(Directive::is_use_strict)), @@ -51,7 +51,7 @@ inherit_variants! { /// Inherits variants from [`MemberExpression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -160,7 +160,7 @@ macro_rules! match_expression { pub use match_expression; /// Identifier Name -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "Identifier"))] @@ -171,7 +171,7 @@ pub struct IdentifierName<'a> { } /// Identifier Reference -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "Identifier"))] @@ -186,7 +186,7 @@ pub struct IdentifierReference<'a> { } /// Binding Identifier -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "Identifier"))] @@ -199,7 +199,7 @@ pub struct BindingIdentifier<'a> { } /// Label Identifier -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "Identifier"))] @@ -210,7 +210,7 @@ pub struct LabelIdentifier<'a> { } /// This Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -220,7 +220,7 @@ pub struct ThisExpression { } /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -241,7 +241,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] @@ -259,14 +259,14 @@ pub enum ArrayExpressionElement<'a> { /// Array Expression Elision Element /// Serialized as `null` in JSON AST. See `serialize.rs`. -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] pub struct Elision { pub span: Span, } /// Object Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -278,7 +278,7 @@ pub struct ObjectExpression<'a> { pub trailing_comma: Option, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -287,7 +287,7 @@ pub enum ObjectPropertyKind<'a> { SpreadProperty(Box<'a, SpreadElement<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -309,7 +309,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -334,7 +334,7 @@ pub enum PropertyKind { /// Template Literal /// /// This is interpreted by interleaving the expression elements in between the quasi elements. -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -345,7 +345,7 @@ pub struct TemplateLiteral<'a> { pub expressions: Vec<'a, Expression<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -357,7 +357,7 @@ pub struct TaggedTemplateExpression<'a> { pub type_parameters: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -384,7 +384,7 @@ pub struct TemplateElementValue<'a> { } /// -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -410,7 +410,7 @@ macro_rules! match_member_expression { pub use match_member_expression; /// `MemberExpression[?Yield, ?Await] [ Expression[+In, ?Yield, ?Await] ]` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -423,7 +423,7 @@ pub struct ComputedMemberExpression<'a> { } /// `MemberExpression[?Yield, ?Await] . IdentifierName` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -436,7 +436,7 @@ pub struct StaticMemberExpression<'a> { } /// `MemberExpression[?Yield, ?Await] . PrivateIdentifier` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -449,7 +449,7 @@ pub struct PrivateFieldExpression<'a> { } /// Call Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -463,7 +463,7 @@ pub struct CallExpression<'a> { } /// New Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -476,7 +476,7 @@ pub struct NewExpression<'a> { } /// Meta Property `new.target` | `import.meta` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -488,7 +488,7 @@ pub struct MetaProperty<'a> { } /// Spread Element -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -504,7 +504,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -517,7 +517,7 @@ pub enum Argument<'a> { } /// Update Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -530,7 +530,7 @@ pub struct UpdateExpression<'a> { } /// Unary Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -542,7 +542,7 @@ pub struct UnaryExpression<'a> { } /// Binary Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -555,7 +555,7 @@ pub struct BinaryExpression<'a> { } /// Private Identifier in Shift Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -568,7 +568,7 @@ pub struct PrivateInExpression<'a> { } /// Binary Logical Operators -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -581,7 +581,7 @@ pub struct LogicalExpression<'a> { } /// Conditional Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -594,7 +594,7 @@ pub struct ConditionalExpression<'a> { } /// Assignment Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -613,7 +613,7 @@ inherit_variants! { /// See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -632,7 +632,7 @@ inherit_variants! { /// Inherits variants from [`MemberExpression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -687,7 +687,7 @@ macro_rules! match_simple_assignment_target { } pub use match_simple_assignment_target; -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -707,7 +707,7 @@ macro_rules! match_assignment_target_pattern { pub use match_assignment_target_pattern; // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -726,7 +726,7 @@ pub struct ArrayAssignmentTarget<'a> { } // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -742,7 +742,7 @@ pub struct ObjectAssignmentTarget<'a> { pub rest: Option>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "RestElement"))] @@ -759,7 +759,7 @@ inherit_variants! { /// Inherits variants from [`AssignmentTarget`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -771,7 +771,7 @@ pub enum AssignmentTargetMaybeDefault<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -782,7 +782,7 @@ pub struct AssignmentTargetWithDefault<'a> { pub init: Expression<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -792,7 +792,7 @@ pub enum AssignmentTargetProperty<'a> { } /// Assignment Property - Identifier Reference -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -804,7 +804,7 @@ pub struct AssignmentTargetPropertyIdentifier<'a> { } /// Assignment Property - Property Name -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -816,7 +816,7 @@ pub struct AssignmentTargetPropertyProperty<'a> { } /// Sequence Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -826,7 +826,7 @@ pub struct SequenceExpression<'a> { pub expressions: Vec<'a, Expression<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -836,7 +836,7 @@ pub struct Super { } /// Await Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -846,7 +846,7 @@ pub struct AwaitExpression<'a> { pub argument: Expression<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -862,7 +862,7 @@ inherit_variants! { /// Inherits variants from [`MemberExpression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -875,7 +875,7 @@ pub enum ChainElement<'a> { } /// Parenthesized Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -892,7 +892,7 @@ inherit_variants! { /// See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -925,7 +925,7 @@ pub enum Statement<'a> { } /// Directive Prologue -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -939,7 +939,7 @@ pub struct Directive<'a> { } /// Hashbang -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -950,7 +950,7 @@ pub struct Hashbang<'a> { } /// Block Statement -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -963,7 +963,7 @@ pub struct BlockStatement<'a> { } /// Declarations and the Variable Statement -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1000,7 +1000,7 @@ macro_rules! match_declaration { pub use match_declaration; /// Variable Declaration -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1021,7 +1021,7 @@ pub enum VariableDeclarationKind { Let, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1037,7 +1037,7 @@ pub struct VariableDeclarator<'a> { /// Using Declaration /// * -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1050,7 +1050,7 @@ pub struct UsingDeclaration<'a> { } /// Empty Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1060,7 +1060,7 @@ pub struct EmptyStatement { } /// Expression Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1071,7 +1071,7 @@ pub struct ExpressionStatement<'a> { } /// If Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1084,7 +1084,7 @@ pub struct IfStatement<'a> { } /// Do-While Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1096,7 +1096,7 @@ pub struct DoWhileStatement<'a> { } /// While Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1108,7 +1108,7 @@ pub struct WhileStatement<'a> { } /// For Statement -#[visited_node] +#[ast(visit)] #[scope(if(self.init.as_ref().is_some_and(ForStatementInit::is_lexical_declaration)))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1129,7 +1129,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1143,7 +1143,7 @@ pub enum ForStatementInit<'a> { } /// For-In Statement -#[visited_node] +#[ast(visit)] #[scope(if(self.left.is_lexical_declaration()))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1163,7 +1163,7 @@ inherit_variants! { /// Inherits variants from [`AssignmentTarget`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1176,7 +1176,7 @@ pub enum ForStatementLeft<'a> { } } /// For-Of Statement -#[visited_node] +#[ast(visit)] #[scope(if(self.left.is_lexical_declaration()))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1192,7 +1192,7 @@ pub struct ForOfStatement<'a> { } /// Continue Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1203,7 +1203,7 @@ pub struct ContinueStatement<'a> { } /// Break Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1214,7 +1214,7 @@ pub struct BreakStatement<'a> { } /// Return Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1225,7 +1225,7 @@ pub struct ReturnStatement<'a> { } /// With Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1237,7 +1237,7 @@ pub struct WithStatement<'a> { } /// Switch Statement -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1251,7 +1251,7 @@ pub struct SwitchStatement<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1263,7 +1263,7 @@ pub struct SwitchCase<'a> { } /// Labelled Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1275,7 +1275,7 @@ pub struct LabeledStatement<'a> { } /// Throw Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1286,7 +1286,7 @@ pub struct ThrowStatement<'a> { } /// Try Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1299,7 +1299,7 @@ pub struct TryStatement<'a> { pub finalizer: Option>>, } -#[visited_node] +#[ast(visit)] #[scope(flags(ScopeFlags::CatchClause), if(self.param.is_some()))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1312,7 +1312,7 @@ pub struct CatchClause<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1323,7 +1323,7 @@ pub struct CatchParameter<'a> { } /// Debugger Statement -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1334,7 +1334,7 @@ pub struct DebuggerStatement { /// Destructuring Binding Patterns /// * -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))] @@ -1351,7 +1351,7 @@ pub struct BindingPattern<'a> { pub optional: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -1369,7 +1369,7 @@ pub enum BindingPatternKind<'a> { AssignmentPattern(Box<'a, AssignmentPattern<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1381,7 +1381,7 @@ pub struct AssignmentPattern<'a> { } // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1394,7 +1394,7 @@ pub struct ObjectPattern<'a> { pub rest: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1408,7 +1408,7 @@ pub struct BindingProperty<'a> { } // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1424,7 +1424,7 @@ pub struct ArrayPattern<'a> { pub rest: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename = "RestElement"))] @@ -1435,7 +1435,7 @@ pub struct BindingRestElement<'a> { } /// Function Definitions -#[visited_node] +#[ast(visit)] #[scope( // `flags` passed in to visitor via parameter defined by `#[visit_args(flags = ...)]` on parents flags(flags), @@ -1487,7 +1487,7 @@ pub enum FunctionType { /// // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1504,7 +1504,7 @@ pub struct FormalParameters<'a> { pub rest: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1532,7 +1532,7 @@ pub enum FormalParameterKind { } /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1544,7 +1544,7 @@ pub struct FunctionBody<'a> { } /// Arrow Function Definitions -#[visited_node] +#[ast(visit)] #[scope( flags(ScopeFlags::Function | ScopeFlags::Arrow), strict_if(self.body.has_use_strict_directive()), @@ -1567,7 +1567,7 @@ pub struct ArrowFunctionExpression<'a> { } /// Generator Function Definitions -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1579,7 +1579,7 @@ pub struct YieldExpression<'a> { } /// Class Definitions -#[visited_node] +#[ast(visit)] #[scope(flags(ScopeFlags::StrictMode))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1609,7 +1609,7 @@ pub enum ClassType { ClassExpression, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1619,7 +1619,7 @@ pub struct ClassBody<'a> { pub body: Vec<'a, ClassElement<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -1631,7 +1631,7 @@ pub enum ClassElement<'a> { TSIndexSignature(Box<'a, TSIndexSignature<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))] @@ -1663,7 +1663,7 @@ pub enum MethodDefinitionType { TSAbstractMethodDefinition, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(rename_all = "camelCase"))] @@ -1702,7 +1702,7 @@ pub enum MethodDefinitionKind { Set, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1712,7 +1712,7 @@ pub struct PrivateIdentifier<'a> { pub name: Atom<'a>, } -#[visited_node] +#[ast(visit)] #[scope(flags(ScopeFlags::ClassStaticBlock))] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1724,7 +1724,7 @@ pub struct StaticBlock<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1768,7 +1768,7 @@ pub enum AccessorPropertyType { TSAbstractAccessorProperty, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] pub struct AccessorProperty<'a> { @@ -1782,7 +1782,7 @@ pub struct AccessorProperty<'a> { pub r#static: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1793,7 +1793,7 @@ pub struct ImportExpression<'a> { pub arguments: Vec<'a, Expression<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1809,7 +1809,7 @@ pub struct ImportDeclaration<'a> { pub import_kind: ImportOrExportKind, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -1825,7 +1825,7 @@ pub enum ImportDeclarationSpecifier<'a> { // import {imported} from "source" // import {imported as local} from "source" -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1838,7 +1838,7 @@ pub struct ImportSpecifier<'a> { } // import local from "source" -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1849,7 +1849,7 @@ pub struct ImportDefaultSpecifier<'a> { } // import * as local from "source" -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1859,7 +1859,7 @@ pub struct ImportNamespaceSpecifier<'a> { pub local: BindingIdentifier<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1870,7 +1870,7 @@ pub struct WithClause<'a> { pub with_entries: Vec<'a, ImportAttribute<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1881,7 +1881,7 @@ pub struct ImportAttribute<'a> { pub value: StringLiteral<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -1890,7 +1890,7 @@ pub enum ImportAttributeKey<'a> { StringLiteral(StringLiteral<'a>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1910,7 +1910,7 @@ pub struct ExportNamedDeclaration<'a> { /// export default HoistableDeclaration /// export default ClassDeclaration /// export default AssignmentExpression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -1921,7 +1921,7 @@ pub struct ExportDefaultDeclaration<'a> { pub exported: ModuleExportName<'a>, // the `default` Keyword } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1934,7 +1934,7 @@ pub struct ExportAllDeclaration<'a> { pub export_kind: ImportOrExportKind, // `export type *` } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1952,7 +1952,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1975,7 +1975,7 @@ pub enum ExportDefaultDeclarationKind<'a> { /// * `export {foo as "\0 any unicode"}` /// * es2022: /// * -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] diff --git a/crates/oxc_ast/src/ast/jsx.rs b/crates/oxc_ast/src/ast/jsx.rs index 5226f948a9f6d..9f9c101f89d7f 100644 --- a/crates/oxc_ast/src/ast/jsx.rs +++ b/crates/oxc_ast/src/ast/jsx.rs @@ -8,7 +8,7 @@ #![allow(non_snake_case)] use oxc_allocator::{Box, Vec}; -use oxc_ast_macros::visited_node; +use oxc_ast_macros::ast; use oxc_span::{Atom, Span}; #[cfg(feature = "serialize")] use serde::Serialize; @@ -20,7 +20,7 @@ use super::{inherit_variants, js::*, literal::*, ts::*}; // 1.2 JSX Elements /// JSX Element -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -33,7 +33,7 @@ pub struct JSXElement<'a> { } /// JSX Opening Element -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -47,7 +47,7 @@ pub struct JSXOpeningElement<'a> { } /// JSX Closing Element -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -58,7 +58,7 @@ pub struct JSXClosingElement<'a> { } /// JSX Fragment -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -87,7 +87,7 @@ pub struct JSXClosingFragment { } /// JSX Element Name -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -101,7 +101,7 @@ pub enum JSXElementName<'a> { } /// JSX Namespaced Name -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -113,7 +113,7 @@ pub struct JSXNamespacedName<'a> { } /// JSX Member Expression -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -124,7 +124,7 @@ pub struct JSXMemberExpression<'a> { pub property: JSXIdentifier<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -133,7 +133,7 @@ pub enum JSXMemberExpressionObject<'a> { MemberExpression(Box<'a, JSXMemberExpression<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -149,7 +149,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -161,7 +161,7 @@ pub enum JSXExpression<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -173,7 +173,7 @@ pub struct JSXEmptyExpression { // 1.3 JSX Attributes /// JSX Attributes -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -183,7 +183,7 @@ pub enum JSXAttributeItem<'a> { } /// JSX Attribute -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -195,7 +195,7 @@ pub struct JSXAttribute<'a> { } /// JSX Spread Attribute -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -206,7 +206,7 @@ pub struct JSXSpreadAttribute<'a> { } /// JSX Attribute Name -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -216,7 +216,7 @@ pub enum JSXAttributeName<'a> { } /// JSX Attribute Value -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -227,7 +227,7 @@ pub enum JSXAttributeValue<'a> { Fragment(Box<'a, JSXFragment<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -240,7 +240,7 @@ pub struct JSXIdentifier<'a> { // 1.4 JSX Children /// JSX Child -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -252,7 +252,7 @@ pub enum JSXChild<'a> { Spread(Box<'a, JSXSpreadChild<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -262,7 +262,7 @@ pub struct JSXSpreadChild<'a> { pub expression: Expression<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] diff --git a/crates/oxc_ast/src/ast/literal.rs b/crates/oxc_ast/src/ast/literal.rs index c411bc87a78e3..380f9ef8f09bb 100644 --- a/crates/oxc_ast/src/ast/literal.rs +++ b/crates/oxc_ast/src/ast/literal.rs @@ -10,7 +10,7 @@ use std::hash::Hash; use bitflags::bitflags; -use oxc_ast_macros::visited_node; +use oxc_ast_macros::ast; use oxc_span::{Atom, Span}; use oxc_syntax::number::{BigintBase, NumberBase}; #[cfg(feature = "serialize")] @@ -18,7 +18,7 @@ use serde::Serialize; #[cfg(feature = "serialize")] use tsify::Tsify; -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -28,7 +28,7 @@ pub struct BooleanLiteral { pub value: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -37,7 +37,7 @@ pub struct NullLiteral { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -50,7 +50,7 @@ pub struct NumericLiteral<'a> { pub base: NumberBase, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -62,7 +62,7 @@ pub struct BigIntLiteral<'a> { pub base: BigintBase, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -86,7 +86,7 @@ pub struct RegExp<'a> { #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] pub struct EmptyObject; -#[visited_node] +#[ast(visit)] #[derive(Debug, Clone, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] diff --git a/crates/oxc_ast/src/ast/ts.rs b/crates/oxc_ast/src/ast/ts.rs index b7aaf26eadad1..b8bbdac18a103 100644 --- a/crates/oxc_ast/src/ast/ts.rs +++ b/crates/oxc_ast/src/ast/ts.rs @@ -13,7 +13,7 @@ use std::{cell::Cell, hash::Hash}; use oxc_allocator::{Box, Vec}; -use oxc_ast_macros::visited_node; +use oxc_ast_macros::ast; use oxc_span::{Atom, Span}; use oxc_syntax::scope::ScopeId; #[cfg(feature = "serialize")] @@ -33,7 +33,7 @@ export interface TSIndexSignatureName extends Span { } "#; -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -47,7 +47,7 @@ pub struct TSThisParameter<'a> { /// Enum Declaration /// /// `const_opt` enum `BindingIdentifier` { `EnumBody_opt` } -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -63,7 +63,7 @@ pub struct TSEnumDeclaration<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -80,7 +80,7 @@ inherit_variants! { /// Inherits variants from [`Expression`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -96,7 +96,7 @@ pub enum TSEnumMemberName<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -106,7 +106,7 @@ pub struct TSTypeAnnotation<'a> { pub type_annotation: TSType<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -116,7 +116,7 @@ pub struct TSLiteralType<'a> { pub literal: TSLiteral<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged, rename_all = "camelCase"))] @@ -131,7 +131,7 @@ pub enum TSLiteral<'a> { UnaryExpression(Box<'a, UnaryExpression<'a>>), } -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -229,7 +229,7 @@ pub use match_ts_type; /// `SomeType extends OtherType ? TrueType : FalseType;` /// /// -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -247,7 +247,7 @@ pub struct TSConditionalType<'a> { /// string | string[] | (() => string) | { s: string } /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -260,7 +260,7 @@ pub struct TSUnionType<'a> { /// type `ColorfulCircle` = Colorful & Circle; /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -270,7 +270,7 @@ pub struct TSIntersectionType<'a> { pub types: Vec<'a, TSType<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -283,7 +283,7 @@ pub struct TSParenthesizedType<'a> { /// keyof unique readonly /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -306,7 +306,7 @@ pub enum TSTypeOperatorOperator { /// `let myArray: string[] = ["hello", "world"];` /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -319,7 +319,7 @@ pub struct TSArrayType<'a> { /// `type I1 = Person["age" | "name"];` /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -333,7 +333,7 @@ pub struct TSIndexedAccessType<'a> { /// type `StringNumberPair` = [string, number]; /// /// -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -343,7 +343,7 @@ pub struct TSTupleType<'a> { pub element_types: Vec<'a, TSTupleElement<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -355,7 +355,7 @@ pub struct TSNamedTupleMember<'a> { pub optional: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -365,7 +365,7 @@ pub struct TSOptionalType<'a> { pub type_annotation: TSType<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -381,7 +381,7 @@ inherit_variants! { /// Inherits variants from [`TSType`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -396,7 +396,7 @@ pub enum TSTupleElement<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -405,7 +405,7 @@ pub struct TSAnyKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -414,7 +414,7 @@ pub struct TSStringKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -423,7 +423,7 @@ pub struct TSBooleanKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -432,7 +432,7 @@ pub struct TSNumberKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -442,7 +442,7 @@ pub struct TSNeverKeyword { } /// `type Uppercase = intrinsic;` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -451,7 +451,7 @@ pub struct TSIntrinsicKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -460,7 +460,7 @@ pub struct TSUnknownKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -469,7 +469,7 @@ pub struct TSNullKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -478,7 +478,7 @@ pub struct TSUndefinedKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -487,7 +487,7 @@ pub struct TSVoidKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -496,7 +496,7 @@ pub struct TSSymbolKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -505,7 +505,7 @@ pub struct TSThisType { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -514,7 +514,7 @@ pub struct TSObjectKeyword { pub span: Span, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type"))] @@ -526,7 +526,7 @@ pub struct TSBigIntKeyword { /// type C = A; /// type D = B.a; /// type E = D.c.b.a; -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -540,7 +540,7 @@ pub struct TSTypeReference<'a> { /// TypeName: /// IdentifierReference /// NamespaceName . IdentifierReference -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -559,7 +559,7 @@ macro_rules! match_ts_type_name { } pub use match_ts_type_name; -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -570,7 +570,7 @@ pub struct TSQualifiedName<'a> { pub right: IdentifierName<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -580,7 +580,7 @@ pub struct TSTypeParameterInstantiation<'a> { pub params: Vec<'a, TSType<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -595,7 +595,7 @@ pub struct TSTypeParameter<'a> { pub r#const: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -605,7 +605,7 @@ pub struct TSTypeParameterDeclaration<'a> { pub params: Vec<'a, TSTypeParameter<'a>>, } -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -630,7 +630,7 @@ pub enum TSAccessibility { Public, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -644,7 +644,7 @@ pub struct TSClassImplements<'a> { /// Interface Declaration /// /// interface `BindingIdentifier` `TypeParameters_opt` `InterfaceExtendsClause_opt` `ObjectType` -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -661,7 +661,7 @@ pub struct TSInterfaceDeclaration<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -671,7 +671,7 @@ pub struct TSInterfaceBody<'a> { pub body: Vec<'a, TSSignature<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -685,7 +685,7 @@ pub struct TSPropertySignature<'a> { pub type_annotation: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged, rename_all = "camelCase"))] @@ -697,7 +697,7 @@ pub enum TSSignature<'a> { TSMethodSignature(Box<'a, TSMethodSignature<'a>>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -709,7 +709,7 @@ pub struct TSIndexSignature<'a> { pub readonly: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -731,7 +731,7 @@ pub enum TSMethodSignatureKind { Set, } -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -750,7 +750,7 @@ pub struct TSMethodSignature<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -764,7 +764,7 @@ pub struct TSConstructSignatureDeclaration<'a> { pub scope_id: Cell>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize))] #[cfg_attr( @@ -778,7 +778,7 @@ pub struct TSIndexSignatureName<'a> { pub type_annotation: Box<'a, TSTypeAnnotation<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -789,7 +789,7 @@ pub struct TSInterfaceHeritage<'a> { pub type_parameters: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -801,7 +801,7 @@ pub struct TSTypePredicate<'a> { pub type_annotation: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged, rename_all = "camelCase"))] @@ -810,7 +810,7 @@ pub enum TSTypePredicateName<'a> { This(TSThisType), } -#[visited_node] +#[ast(visit)] #[scope( flags(ScopeFlags::TsModuleBlock), strict_if(self.body.as_ref().is_some_and(TSModuleDeclarationBody::is_strict)), @@ -853,7 +853,7 @@ impl TSModuleDeclarationKind { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -862,7 +862,7 @@ pub enum TSModuleDeclarationName<'a> { StringLiteral(StringLiteral<'a>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -872,7 +872,7 @@ pub enum TSModuleDeclarationBody<'a> { } // See serializer in serialize.rs -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -884,7 +884,7 @@ pub struct TSModuleBlock<'a> { pub body: Vec<'a, Statement<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -894,7 +894,7 @@ pub struct TSTypeLiteral<'a> { pub members: Vec<'a, TSSignature<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -904,7 +904,7 @@ pub struct TSInferType<'a> { pub type_parameter: Box<'a, TSTypeParameter<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -921,7 +921,7 @@ inherit_variants! { /// Inherits variants from [`TSTypeName`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -933,7 +933,7 @@ pub enum TSTypeQueryExprName<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -947,7 +947,7 @@ pub struct TSImportType<'a> { pub type_parameters: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -957,7 +957,7 @@ pub struct TSImportAttributes<'a> { pub elements: Vec<'a, TSImportAttribute<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -968,7 +968,7 @@ pub struct TSImportAttribute<'a> { pub value: Expression<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(untagged))] @@ -977,7 +977,7 @@ pub enum TSImportAttributeName<'a> { StringLiteral(StringLiteral<'a>), } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -990,7 +990,7 @@ pub struct TSFunctionType<'a> { pub type_parameters: Option>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1003,7 +1003,7 @@ pub struct TSConstructorType<'a> { pub type_parameters: Option>>, } -#[visited_node] +#[ast(visit)] #[scope] #[derive(Debug)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1031,7 +1031,7 @@ pub enum TSMappedTypeModifierOperator { None, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1042,7 +1042,7 @@ pub struct TSTemplateLiteralType<'a> { pub types: Vec<'a, TSType<'a>>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1053,7 +1053,7 @@ pub struct TSAsExpression<'a> { pub type_annotation: TSType<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1064,7 +1064,7 @@ pub struct TSSatisfiesExpression<'a> { pub type_annotation: TSType<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1075,7 +1075,7 @@ pub struct TSTypeAssertion<'a> { pub type_annotation: TSType<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1093,7 +1093,7 @@ inherit_variants! { /// Inherits variants from [`TSTypeName`]. See [`ast` module docs] for explanation of inheritance. /// /// [`ast` module docs]: `super` -#[visited_node] +#[ast(visit)] #[repr(C, u8)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] @@ -1105,7 +1105,7 @@ pub enum TSModuleReference<'a> { } } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1115,7 +1115,7 @@ pub struct TSExternalModuleReference<'a> { pub expression: StringLiteral<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1125,7 +1125,7 @@ pub struct TSNonNullExpression<'a> { pub expression: Expression<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1138,7 +1138,7 @@ pub struct Decorator<'a> { /// Export Assignment in non-module files /// /// `export = foo` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1151,7 +1151,7 @@ pub struct TSExportAssignment<'a> { /// Namespace Export Declaration in declaration files /// /// `export as namespace foo` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1161,7 +1161,7 @@ pub struct TSNamespaceExportDeclaration<'a> { pub id: IdentifierName<'a>, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1183,7 +1183,7 @@ pub enum ImportOrExportKind { // [`JSDoc`](https://github.com/microsoft/TypeScript/blob/54a554d8af2657630307cbfa8a3e4f3946e36507/src/compiler/types.ts#L393) /// `type foo = ty?` or `type foo = ?ty` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1195,7 +1195,7 @@ pub struct JSDocNullableType<'a> { } /// `type foo = ty!` or `type foo = !ty` -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] @@ -1206,7 +1206,7 @@ pub struct JSDocNonNullableType<'a> { pub postfix: bool, } -#[visited_node] +#[ast(visit)] #[derive(Debug, Hash)] #[cfg_attr(feature = "serialize", derive(Serialize, Tsify))] #[cfg_attr(feature = "serialize", serde(tag = "type", rename_all = "camelCase"))] diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 20e1243c58a6e..f7d8ea5d653f9 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -1,6 +1,3 @@ -// NB: `#[visited_node]` attribute on AST nodes does not do anything to the code in this file. -// It is purely a marker for codegen used in `oxc_traverse`. See docs in that crate. - use crate::ast::*; use std::{cell::Cell, fmt, hash::Hash}; diff --git a/crates/oxc_ast/src/ast_impl/literal.rs b/crates/oxc_ast/src/ast_impl/literal.rs index 25e99ae1b299b..108b9db81b5a5 100644 --- a/crates/oxc_ast/src/ast_impl/literal.rs +++ b/crates/oxc_ast/src/ast_impl/literal.rs @@ -1,8 +1,5 @@ //! Literals -// NB: `#[visited_node]` attribute on AST nodes does not do anything to the code in this file. -// It is purely a marker for codegen used in `oxc_traverse`. See docs in that crate. - // Silence erroneous warnings from Rust Analyser for `#[derive(Tsify)]` #![allow(non_snake_case)] diff --git a/crates/oxc_ast/src/ast_impl/ts.rs b/crates/oxc_ast/src/ast_impl/ts.rs index 65384029c3b93..1ec47a58be3a0 100644 --- a/crates/oxc_ast/src/ast_impl/ts.rs +++ b/crates/oxc_ast/src/ast_impl/ts.rs @@ -3,9 +3,6 @@ //! [AST Spec](https://github.com/typescript-eslint/typescript-eslint/tree/main/packages/ast-spec) //! [Archived TypeScript spec](https://github.com/microsoft/TypeScript/blob/3c99d50da5a579d9fa92d02664b1b66d4ff55944/doc/spec-ARCHIVED.md) -// NB: `#[visited_node]` attribute on AST nodes does not do anything to the code in this file. -// It is purely a marker for codegen used in `oxc_traverse`. See docs in that crate. - use std::{cell::Cell, hash::Hash}; use oxc_allocator::Vec; diff --git a/crates/oxc_ast_macros/src/lib.rs b/crates/oxc_ast_macros/src/lib.rs index 5b3dae9d0496f..eaa0c462659e3 100644 --- a/crates/oxc_ast_macros/src/lib.rs +++ b/crates/oxc_ast_macros/src/lib.rs @@ -5,24 +5,24 @@ use std::str::FromStr; /// /// Macro does not generate any code - it's purely a means to communicate information to the codegen. /// -/// Only thing macro does is add `#[derive(VisitedNode)]` to the item. -/// Deriving `VisitedNode` does nothing, but supports the `#[scope]` attr on struct fields. +/// Only thing macro does is add `#[derive(Ast)]` to the item. +/// Deriving `Ast` does nothing, but supports the `#[scope]` attr on struct fields. /// This is a workaround for Rust not supporting helper attributes for `proc_macro_attribute` macros, /// so we need to use a derive macro to get that support. /// /// Use native Rust `TokenStream`, to avoid dependency on slow-compiling crates like `syn` and `quote`. #[proc_macro_attribute] #[allow(clippy::missing_panics_doc)] -pub fn visited_node(_args: TokenStream, input: TokenStream) -> TokenStream { - let mut stream = TokenStream::from_str("#[derive(::oxc_ast_macros::VisitedNode)]").unwrap(); +pub fn ast(_args: TokenStream, input: TokenStream) -> TokenStream { + let mut stream = TokenStream::from_str("#[derive(::oxc_ast_macros::Ast)]").unwrap(); stream.extend(input); stream } -/// Dummy derive macro for a non-existent trait `VisitedNode`. +/// Dummy derive macro for a non-existent trait `Ast`. /// /// Does not generate any code, only purpose is to allow using `#[scope]` attr in the type def. -#[proc_macro_derive(VisitedNode, attributes(span, scope, visit, visit_as, visit_args))] -pub fn visited_node_derive(_item: TokenStream) -> TokenStream { +#[proc_macro_derive(Ast, attributes(span, scope, visit, visit_as, visit_args))] +pub fn ast_derive(_item: TokenStream) -> TokenStream { TokenStream::new() } diff --git a/crates/oxc_traverse/scripts/lib/parse.mjs b/crates/oxc_traverse/scripts/lib/parse.mjs index f9bfce40d06c6..db612b5a22d79 100644 --- a/crates/oxc_traverse/scripts/lib/parse.mjs +++ b/crates/oxc_traverse/scripts/lib/parse.mjs @@ -72,7 +72,8 @@ class Lines { function parseFile(code, filename, types) { const lines = Lines.fromCode(code, filename); while (!lines.isEnd()) { - if (lines.current() !== '#[visited_node]') { + // if not #[ast(visit, ..)] + if (!/^#\[ast\(.*visit.*\)\]/.test(lines.current())) { lines.next(); continue; } @@ -87,7 +88,7 @@ function parseFile(code, filename, types) { match = lines.next().match(/^pub (enum|struct) ((.+?)(?:<'a>)?) \{/); if (match) break; } - lines.position().assert(match, `Could not find enum or struct after #[visited_node]`); + lines.position().assert(match, `Could not find enum or struct after #[ast]`); const [, kind, rawName, name] = match; // Find end of struct / enum diff --git a/crates/oxc_traverse/scripts/lib/walk.mjs b/crates/oxc_traverse/scripts/lib/walk.mjs index 8ceb6eff2e26b..65cc2e7fe39eb 100644 --- a/crates/oxc_traverse/scripts/lib/walk.mjs +++ b/crates/oxc_traverse/scripts/lib/walk.mjs @@ -66,7 +66,7 @@ function generateWalkForStruct(type, types) { scopeEnterField = visitedFields.find(field => field.name === enterFieldName); assert( scopeEnterField, - `\`visited_node\` attr says to enter scope before field '${enterFieldName}' ` + `\`ast\` attr says to enter scope before field '${enterFieldName}' ` + `in '${type.name}', but that field is not visited` ); if (scopeEnterField === visitedFields[0]) scopeEnterField = undefined; diff --git a/tasks/ast_codegen/src/main.rs b/tasks/ast_codegen/src/main.rs index 5c996ea719d0c..80109fa16c3bd 100644 --- a/tasks/ast_codegen/src/main.rs +++ b/tasks/ast_codegen/src/main.rs @@ -27,7 +27,7 @@ use defs::TypeDef; use generators::{AstBuilderGenerator, AstKindGenerator, VisitGenerator, VisitMutGenerator}; use linker::{linker, Linker}; use schema::{Inherit, Module, REnum, RStruct, RType, Schema}; -use util::write_all_to; +use util::{write_all_to, NormalizeError}; use crate::generators::ImplGetSpanGenerator; @@ -250,7 +250,7 @@ fn main() -> std::result::Result<(), Box> { if let CliOptions { schema: Some(schema_path), dry_run: false, .. } = cli_options { let path = schema_path.to_str().expect("invalid path for schema output."); - let schema = serde_json::to_string_pretty(&schema).map_err(|e| e.to_string())?; + let schema = serde_json::to_string_pretty(&schema).normalize()?; write_all_to(schema.as_bytes(), path)?; } diff --git a/tasks/ast_codegen/src/schema.rs b/tasks/ast_codegen/src/schema.rs index a2c3019075050..9054a7c7e0237 100644 --- a/tasks/ast_codegen/src/schema.rs +++ b/tasks/ast_codegen/src/schema.rs @@ -5,11 +5,11 @@ use syn::{ parse::{Parse, ParseBuffer}, parse_quote, punctuated::Punctuated, - Attribute, Generics, Ident, Item, ItemConst, ItemEnum, ItemMacro, ItemStruct, ItemUse, Token, - Type, Variant, Visibility, + Attribute, Generics, Ident, Item, ItemConst, ItemEnum, ItemMacro, ItemStruct, ItemUse, Meta, + MetaList, Path, Token, Type, Variant, Visibility, }; -use crate::TypeName; +use crate::{util::NormalizeError, TypeName}; use super::{parse_file, Itertools, PathBuf, Rc, Read, RefCell, Result, TypeDef, TypeRef}; @@ -40,6 +40,7 @@ impl From for Inherit { pub struct EnumMeta { pub inherits: Vec, pub visitable: bool, + pub ast: bool, } #[derive(Debug)] @@ -74,6 +75,7 @@ impl From for REnum { #[derive(Debug, Default, Clone)] pub struct StructMeta { pub visitable: bool, + pub ast: bool, } #[derive(Debug)] @@ -152,9 +154,24 @@ impl RType { } pub fn set_visitable(&mut self, value: bool) -> Result<()> { + macro_rules! assign { + ($it:ident) => {{ + debug_assert!($it.meta.ast, "only ast types can be visitable!"); + $it.meta.visitable = value; + }}; + } + match self { + RType::Enum(it) => assign!(it), + RType::Struct(it) => assign!(it), + _ => return Err("Unsupported type!".to_string()), + } + Ok(()) + } + + pub fn set_ast(&mut self, value: bool) -> Result<()> { match self { - RType::Enum(it) => it.meta.visitable = value, - RType::Struct(it) => it.meta.visitable = value, + RType::Enum(it) => it.meta.ast = value, + RType::Struct(it) => it.meta.ast = value, _ => return Err("Unsupported type!".to_string()), } Ok(()) @@ -203,10 +220,10 @@ impl Module { pub fn load(mut self) -> Result { assert!(!self.loaded, "can't load twice!"); - let mut file = std::fs::File::open(&self.path).map_err(|e| e.to_string())?; + let mut file = std::fs::File::open(&self.path).normalize()?; let mut content = String::new(); - file.read_to_string(&mut content).map_err(|e| e.to_string())?; - let file = parse_file(content.as_str()).map_err(|e| e.to_string())?; + file.read_to_string(&mut content).normalize()?; + let file = parse_file(content.as_str()).normalize()?; self.shebang = file.shebang; self.attrs = file.attrs; self.items = file @@ -311,7 +328,7 @@ pub fn expand(type_def: &TypeRef) -> Result<()> { inherits, )) }) - .map_err(|e| e.to_string())?; + .normalize()?; Some(RType::Enum(REnum::with_meta( enum_, EnumMeta { @@ -331,16 +348,46 @@ pub fn expand(type_def: &TypeRef) -> Result<()> { } pub fn analyze(type_def: &TypeRef) -> Result<()> { - let is_visitable = match &*type_def.borrow() { + enum AstAttr { + None, + Mark, + Visit, + } + let ast_attr = match &*type_def.borrow() { RType::Enum(REnum { item: ItemEnum { attrs, .. }, .. }) | RType::Struct(RStruct { item: ItemStruct { attrs, .. }, .. }) => { - Some(attrs.iter().any(|attr| attr.path().is_ident("visited_node"))) + let attr = attrs.iter().find(|attr| attr.path().is_ident("ast")); + let attr = match attr { + Some(Attribute { meta: Meta::Path(_), .. }) => AstAttr::Mark, + Some(attr @ Attribute { meta: Meta::List(_), .. }) => { + // TODO: support for punctuated list of arguments here! + let args = attr.parse_args::().normalize()?; + if args.is_ident("visit") { + AstAttr::Visit + } else { + AstAttr::Mark + } + } + Some(_) => return Err(String::from("Invalid arguments in the `ast` attribute!")), + None => AstAttr::None, + }; + Some(attr) } _ => None, }; - if let Some(is_visitable) = is_visitable { - type_def.borrow_mut().set_visitable(is_visitable)?; + #[allow(clippy::match_same_arms)] + match ast_attr { + Some(AstAttr::Visit) => { + type_def.borrow_mut().set_ast(true)?; + type_def.borrow_mut().set_visitable(true)?; + } + Some(AstAttr::Mark) => { + // AST without visit! + type_def.borrow_mut().set_ast(true)?; + } + Some(AstAttr::None) => { /* non AST types */ } + None => { /* unrelated items like `use`, `type` and `macro` definitions */ } } Ok(()) diff --git a/tasks/ast_codegen/src/util.rs b/tasks/ast_codegen/src/util.rs index a48dd4e9e6e1a..c9a6a22fa560b 100644 --- a/tasks/ast_codegen/src/util.rs +++ b/tasks/ast_codegen/src/util.rs @@ -5,6 +5,19 @@ use syn::{GenericArgument, Ident, PathArguments, Type, TypePath}; use crate::{CodegenCtx, TypeRef}; +pub trait NormalizeError { + fn normalize(self) -> crate::Result; +} + +impl NormalizeError for Result +where + E: ToString, +{ + fn normalize(self) -> crate::Result { + self.map_err(|e| e.to_string()) + } +} + pub trait TokenStreamExt { fn replace_ident(self, needle: &str, replace: &Ident) -> TokenStream; }