Skip to content

Commit

Permalink
refactor(ast): move enter_scope after visit_binding_identifier (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Jul 14, 2024
1 parent dc2b3c4 commit 3e099fe
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,8 @@ 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>>,
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2925,10 +2925,10 @@ 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);
}
visitor.enter_scope(ScopeFlags::StrictMode, &it.scope_id);
if let Some(type_parameters) = &it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3049,10 +3049,10 @@ pub mod walk_mut {
let kind = AstType::Class;
visitor.enter_node(kind);
visitor.visit_decorators(&mut it.decorators);
visitor.enter_scope(ScopeFlags::StrictMode, &it.scope_id);
if let Some(id) = &mut it.id {
visitor.visit_binding_identifier(id);
}
visitor.enter_scope(ScopeFlags::StrictMode, &it.scope_id);
if let Some(type_parameters) = &mut it.type_parameters {
visitor.visit_ts_type_parameter_declaration(type_parameters);
}
Expand Down
9 changes: 1 addition & 8 deletions crates/oxc_semantic/src/checker/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,8 @@ pub fn check_identifier<'a>(name: &str, span: Span, node: &AstNode<'a>, ctx: &Se
if ctx.source_type.is_module() {
return ctx.error(reserved_keyword(name, span));
}

// It is a Syntax Error if ClassStaticBlockStatementList Contains await is true.
if (matches!(ctx.nodes.parent_kind(node.id()), Some(AstKind::Class(_)))
&& ctx
.scope
.get_parent_id(node.scope_id())
.is_some_and(|id| ctx.scope.get_flags(id).is_class_static_block()))
|| ctx.current_scope_flags().is_class_static_block()
{
if ctx.scope.get_flags(node.scope_id()).is_class_static_block() {
return ctx.error(class_static_block_await(span));
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_traverse/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2459,6 +2459,12 @@ pub(crate) unsafe fn walk_class<'a, Tr: Traverse<'a>>(
{
walk_decorator(traverser, item as *mut _, ctx);
}
if let Some(field) =
&mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_ID) as *mut Option<BindingIdentifier>)
{
ctx.retag_stack(AncestorType::ClassId);
walk_binding_identifier(traverser, field as *mut _, ctx);
}
let mut previous_scope_id = None;
if let Some(scope_id) = (*((node as *mut u8).add(ancestor::OFFSET_CLASS_SCOPE_ID)
as *mut Cell<Option<ScopeId>>))
Expand All @@ -2467,12 +2473,6 @@ pub(crate) unsafe fn walk_class<'a, Tr: Traverse<'a>>(
previous_scope_id = Some(ctx.current_scope_id());
ctx.set_current_scope_id(scope_id);
}
if let Some(field) =
&mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_ID) as *mut Option<BindingIdentifier>)
{
ctx.retag_stack(AncestorType::ClassId);
walk_binding_identifier(traverser, field as *mut _, ctx);
}
if let Some(field) = &mut *((node as *mut u8).add(ancestor::OFFSET_CLASS_TYPE_PARAMETERS)
as *mut Option<Box<TSTypeParameterDeclaration>>)
{
Expand Down

0 comments on commit 3e099fe

Please sign in to comment.