Skip to content

Commit

Permalink
feat(semantic): align class scope with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 11, 2024
1 parent bbe5ded commit 2634b62
Show file tree
Hide file tree
Showing 11 changed files with 528 additions and 272 deletions.
6 changes: 3 additions & 3 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,14 +1590,14 @@ pub struct Class<'a> {
#[cfg_attr(feature = "serialize", serde(flatten))]
pub span: Span,
pub decorators: Vec<'a, Decorator<'a>>,
#[scope(enter_before)]
pub id: Option<BindingIdentifier<'a>>,
#[scope(enter_before)]
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
#[visit_as(ClassHeritage)]
pub super_class: Option<Expression<'a>>,
pub body: Box<'a, ClassBody<'a>>,
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
pub super_type_parameters: Option<Box<'a, TSTypeParameterInstantiation<'a>>>,
pub implements: Option<Vec<'a, TSClassImplements<'a>>>,
pub body: Box<'a, ClassBody<'a>>,
pub r#abstract: bool,
pub declare: bool,
pub scope_id: Cell<Option<ScopeId>>,
Expand Down
80 changes: 40 additions & 40 deletions crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,29 +485,29 @@ impl<'a> AstBuilder<'a> {
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
type_parameters: T1,
super_class: Option<Expression<'a>>,
body: T1,
type_parameters: T2,
super_type_parameters: T3,
super_type_parameters: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
body: T3,
r#abstract: bool,
declare: bool,
) -> Expression<'a>
where
T1: IntoIn<'a, Box<'a, ClassBody<'a>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T3: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T3: IntoIn<'a, Box<'a, ClassBody<'a>>>,
{
Expression::ClassExpression(self.alloc(self.class(
r#type,
span,
decorators,
id,
super_class,
body,
type_parameters,
super_class,
super_type_parameters,
implements,
body,
r#abstract,
declare,
)))
Expand Down Expand Up @@ -2728,29 +2728,29 @@ impl<'a> AstBuilder<'a> {
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
type_parameters: T1,
super_class: Option<Expression<'a>>,
body: T1,
type_parameters: T2,
super_type_parameters: T3,
super_type_parameters: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
body: T3,
r#abstract: bool,
declare: bool,
) -> Declaration<'a>
where
T1: IntoIn<'a, Box<'a, ClassBody<'a>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T3: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T3: IntoIn<'a, Box<'a, ClassBody<'a>>>,
{
Declaration::ClassDeclaration(self.alloc(self.class(
r#type,
span,
decorators,
id,
super_class,
body,
type_parameters,
super_class,
super_type_parameters,
implements,
body,
r#abstract,
declare,
)))
Expand Down Expand Up @@ -3942,29 +3942,29 @@ impl<'a> AstBuilder<'a> {
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
type_parameters: T1,
super_class: Option<Expression<'a>>,
body: T1,
type_parameters: T2,
super_type_parameters: T3,
super_type_parameters: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
body: T3,
r#abstract: bool,
declare: bool,
) -> Class<'a>
where
T1: IntoIn<'a, Box<'a, ClassBody<'a>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T3: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T3: IntoIn<'a, Box<'a, ClassBody<'a>>>,
{
Class {
r#type,
span,
decorators,
id,
super_class,
body: body.into_in(self.allocator),
type_parameters: type_parameters.into_in(self.allocator),
super_class,
super_type_parameters: super_type_parameters.into_in(self.allocator),
implements,
body: body.into_in(self.allocator),
r#abstract,
declare,
scope_id: Default::default(),
Expand All @@ -3978,29 +3978,29 @@ impl<'a> AstBuilder<'a> {
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
type_parameters: T1,
super_class: Option<Expression<'a>>,
body: T1,
type_parameters: T2,
super_type_parameters: T3,
super_type_parameters: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
body: T3,
r#abstract: bool,
declare: bool,
) -> Box<'a, Class<'a>>
where
T1: IntoIn<'a, Box<'a, ClassBody<'a>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T3: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T3: IntoIn<'a, Box<'a, ClassBody<'a>>>,
{
self.class(
r#type,
span,
decorators,
id,
super_class,
body,
type_parameters,
super_class,
super_type_parameters,
implements,
body,
r#abstract,
declare,
)
Expand Down Expand Up @@ -4943,29 +4943,29 @@ impl<'a> AstBuilder<'a> {
span: Span,
decorators: Vec<'a, Decorator<'a>>,
id: Option<BindingIdentifier<'a>>,
type_parameters: T1,
super_class: Option<Expression<'a>>,
body: T1,
type_parameters: T2,
super_type_parameters: T3,
super_type_parameters: T2,
implements: Option<Vec<'a, TSClassImplements<'a>>>,
body: T3,
r#abstract: bool,
declare: bool,
) -> ExportDefaultDeclarationKind<'a>
where
T1: IntoIn<'a, Box<'a, ClassBody<'a>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T3: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T1: IntoIn<'a, Option<Box<'a, TSTypeParameterDeclaration<'a>>>>,
T2: IntoIn<'a, Option<Box<'a, TSTypeParameterInstantiation<'a>>>>,
T3: IntoIn<'a, Box<'a, ClassBody<'a>>>,
{
ExportDefaultDeclarationKind::ClassDeclaration(self.alloc(self.class(
r#type,
span,
decorators,
id,
super_class,
body,
type_parameters,
super_class,
super_type_parameters,
implements,
body,
r#abstract,
declare,
)))
Expand Down
72 changes: 36 additions & 36 deletions crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,16 @@ pub trait Visit<'a>: Sized {
walk_class_heritage(self, it);
}

#[inline]
fn visit_ts_class_implementses(&mut self, it: &Vec<'a, TSClassImplements<'a>>) {
walk_ts_class_implementses(self, it);
}

#[inline]
fn visit_ts_class_implements(&mut self, it: &TSClassImplements<'a>) {
walk_ts_class_implements(self, it);
}

#[inline]
fn visit_class_body(&mut self, it: &ClassBody<'a>) {
walk_class_body(self, it);
Expand Down Expand Up @@ -843,16 +853,6 @@ pub trait Visit<'a>: Sized {
walk_accessor_property(self, it);
}

#[inline]
fn visit_ts_class_implementses(&mut self, it: &Vec<'a, TSClassImplements<'a>>) {
walk_ts_class_implementses(self, it);
}

#[inline]
fn visit_ts_class_implements(&mut self, it: &TSClassImplements<'a>) {
walk_ts_class_implements(self, it);
}

#[inline]
fn visit_conditional_expression(&mut self, it: &ConditionalExpression<'a>) {
walk_conditional_expression(self, it);
Expand Down Expand Up @@ -2925,23 +2925,23 @@ pub mod walk {
let kind = AstKind::Class(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_decorators(&it.decorators);
visitor.enter_scope(ScopeFlags::StrictMode, &it.scope_id);
if let Some(id) = &it.id {
visitor.visit_binding_identifier(id);
}
if let Some(super_class) = &it.super_class {
visitor.visit_class_heritage(super_class);
}
visitor.visit_class_body(&it.body);
visitor.enter_scope(ScopeFlags::StrictMode, &it.scope_id);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
if let Some(super_class) = &it.super_class {
visitor.visit_class_heritage(super_class);
}
if let Some(super_type_parameters) = &it.super_type_parameters {
visitor.visit_ts_type_parameter_instantiation(super_type_parameters);
}
if let Some(implements) = &it.implements {
visitor.visit_ts_class_implementses(implements);
}
visitor.visit_class_body(&it.body);
visitor.leave_node(kind);
visitor.leave_scope();
}
Expand All @@ -2953,6 +2953,27 @@ pub mod walk {
visitor.leave_node(kind);
}

#[inline]
pub fn walk_ts_class_implementses<'a, V: Visit<'a>>(
visitor: &mut V,
it: &Vec<'a, TSClassImplements<'a>>,
) {
for el in it.iter() {
visitor.visit_ts_class_implements(el);
}
}

#[inline]
pub fn walk_ts_class_implements<'a, V: Visit<'a>>(visitor: &mut V, it: &TSClassImplements<'a>) {
let kind = AstKind::TSClassImplements(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_ts_type_name(&it.expression);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_instantiation(type_parameters);
}
visitor.leave_node(kind);
}

#[inline]
pub fn walk_class_body<'a, V: Visit<'a>>(visitor: &mut V, it: &ClassBody<'a>) {
let kind = AstKind::ClassBody(visitor.alloc(it));
Expand Down Expand Up @@ -3072,27 +3093,6 @@ pub mod walk {
}
}

#[inline]
pub fn walk_ts_class_implementses<'a, V: Visit<'a>>(
visitor: &mut V,
it: &Vec<'a, TSClassImplements<'a>>,
) {
for el in it.iter() {
visitor.visit_ts_class_implements(el);
}
}

#[inline]
pub fn walk_ts_class_implements<'a, V: Visit<'a>>(visitor: &mut V, it: &TSClassImplements<'a>) {
let kind = AstKind::TSClassImplements(visitor.alloc(it));
visitor.enter_node(kind);
visitor.visit_ts_type_name(&it.expression);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_instantiation(type_parameters);
}
visitor.leave_node(kind);
}

#[inline]
pub fn walk_conditional_expression<'a, V: Visit<'a>>(
visitor: &mut V,
Expand Down
Loading

0 comments on commit 2634b62

Please sign in to comment.