Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub enum Expression<'a> {
ChainExpression(Box<'a, ChainExpression<'a>>) = 16,
ClassExpression(Box<'a, Class<'a>>) = 17,
ConditionalExpression(Box<'a, ConditionalExpression<'a>>) = 18,
#[visit_args(flags = None)]
FunctionExpression(Box<'a, Function<'a>>) = 19,
ImportExpression(Box<'a, ImportExpression<'a>>) = 20,
LogicalExpression(Box<'a, LogicalExpression<'a>>) = 21,
Expand Down Expand Up @@ -250,6 +251,7 @@ pub enum ArrayExpressionElement<'a> {
/// <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Trailing_commas#arrays>
Elision(Elision) = 65,
// `Expression` variants added here by `inherit_variants!` macro
// TODO: support for attributes syntax here so we can use `#[visit_as(ExpressionArrayElement)]`
@inherit Expression
}
}
Expand Down Expand Up @@ -967,6 +969,7 @@ pub struct BlockStatement<'a> {
#[cfg_attr(feature = "serialize", serde(untagged))]
pub enum Declaration<'a> {
VariableDeclaration(Box<'a, VariableDeclaration<'a>>) = 32,
#[visit_args(flags = None)]
FunctionDeclaration(Box<'a, Function<'a>>) = 33,
ClassDeclaration(Box<'a, Class<'a>>) = 34,
UsingDeclaration(Box<'a, UsingDeclaration<'a>>) = 35,
Expand Down Expand Up @@ -1291,6 +1294,7 @@ pub struct TryStatement<'a> {
pub span: Span,
pub block: Box<'a, BlockStatement<'a>>,
pub handler: Option<Box<'a, CatchClause<'a>>>,
#[visit_as(FinallyClause)]
pub finalizer: Option<Box<'a, BlockStatement<'a>>>,
}

Expand Down Expand Up @@ -1432,7 +1436,7 @@ pub struct BindingRestElement<'a> {
#[visited_node]
#[scope(
// TODO: `ScopeFlags::Function` is not correct if this is a `MethodDefinition`
flags(ScopeFlags::Function),
flags(flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function),
strict_if(self.body.as_ref().is_some_and(|body| body.has_use_strict_directive())),
)]
#[derive(Debug)]
Expand Down Expand Up @@ -1586,6 +1590,7 @@ pub struct Class<'a> {
pub decorators: Vec<'a, Decorator<'a>>,
#[scope(enter_before)]
pub id: Option<BindingIdentifier<'a>>,
#[visit_as(ClassHeritage)]
pub super_class: Option<Expression<'a>>,
pub body: Box<'a, ClassBody<'a>>,
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
Expand Down Expand Up @@ -1635,6 +1640,12 @@ pub struct MethodDefinition<'a> {
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
pub key: PropertyKey<'a>,
#[visit_args(flags = Some(match self.kind {
MethodDefinitionKind::Get => ScopeFlags::GetAccessor,
MethodDefinitionKind::Set => ScopeFlags::SetAccessor,
MethodDefinitionKind::Constructor => ScopeFlags::Constructor,
MethodDefinitionKind::Method => ScopeFlags::empty(),
}))]
pub value: Box<'a, Function<'a>>, // FunctionExpression
pub kind: MethodDefinitionKind,
pub computed: bool,
Expand Down Expand Up @@ -1946,9 +1957,11 @@ inherit_variants! {
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[cfg_attr(feature = "serialize", serde(untagged))]
pub enum ExportDefaultDeclarationKind<'a> {
#[visit_args(flags = None)]
FunctionDeclaration(Box<'a, Function<'a>>) = 64,
ClassDeclaration(Box<'a, Class<'a>>) = 65,

#[visit(ignore)]
TSInterfaceDeclaration(Box<'a, TSInterfaceDeclaration<'a>>) = 66,

// `Expression` variants added here by `inherit_variants!` macro
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ pub enum TSTypePredicateName<'a> {
#[visited_node]
#[scope(
flags(ScopeFlags::TsModuleBlock),
strict_if(self.body.as_ref().is_some_and(|body| body.is_strict())),
strict_if(self.body.as_ref().is_some_and(TSModuleDeclarationBody::is_strict)),
)]
#[derive(Debug)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub fn visited_node(_args: TokenStream, input: TokenStream) -> TokenStream {
/// Dummy derive macro for a non-existent trait `VisitedNode`.
///
/// Does not generate any code, only purpose is to allow using `#[scope]` attr in the type def.
#[proc_macro_derive(VisitedNode, attributes(scope))]
#[proc_macro_derive(VisitedNode, attributes(scope, visit, visit_as, visit_args))]
pub fn visited_node_derive(_item: TokenStream) -> TokenStream {
TokenStream::new()
}
1 change: 1 addition & 0 deletions tasks/ast_codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ serde = { workspace = true, features = ["derive"] }
regex = { workspace = true }
prettyplease = { workspace = true }
lazy_static = { workspace = true }
convert_case = { workspace = true }
4 changes: 2 additions & 2 deletions tasks/ast_codegen/src/defs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{REnum, RStruct, RType};
use crate::{schema::Inherit, TypeName};
use crate::{schema::Inherit, util::TypeExt, TypeName};
use quote::ToTokens;
use serde::Serialize;

Expand Down Expand Up @@ -95,7 +95,7 @@ impl From<&Inherit> for EnumInheritDef {
fn from(inherit: &Inherit) -> Self {
match inherit {
Inherit::Linked { super_, variants } => Self {
super_name: super_.into(),
super_name: super_.get_ident().as_ident().unwrap().to_string(),
variants: variants.iter().map(Into::into).collect(),
},
Inherit::Unlinked(_) => {
Expand Down
3 changes: 2 additions & 1 deletion tasks/ast_codegen/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::generated_header;

pub struct AstKindGenerator;

const BLACK_LIST: [&str; 69] = [
pub const BLACK_LIST: [&str; 69] = [
"Expression",
"ObjectPropertyKind",
"TemplateElement",
Expand Down Expand Up @@ -102,6 +102,7 @@ impl Generator for AstKindGenerator {
let have_kinds: Vec<(Ident, Type)> = ctx
.ty_table
.iter()
.filter(|it| it.borrow().visitable())
.filter_map(|maybe_kind| match &*maybe_kind.borrow() {
kind @ (RType::Enum(_) | RType::Struct(_)) if kind.visitable() => {
let ident = kind.ident().unwrap().clone();
Expand Down
2 changes: 2 additions & 0 deletions tasks/ast_codegen/src/generators/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
mod ast;
mod ast_kind;
mod impl_get_span;
mod visit;

/// Inserts a newline in the `TokenStream`.
#[allow(unused)]
Expand Down Expand Up @@ -42,3 +43,4 @@ pub(crate) use insert;
pub use ast::AstGenerator;
pub use ast_kind::AstKindGenerator;
pub use impl_get_span::ImplGetSpanGenerator;
pub use visit::VisitGenerator;
Loading