File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -774,15 +774,16 @@ impl<'a> Visit<'a> for SemanticBuilder<'a> {
774774
775775 self . visit_decorators ( & class. decorators ) ;
776776 self . enter_scope ( ScopeFlags :: StrictMode , & class. scope_id ) ;
777- if let Some ( id) = & class. id {
778- self . visit_binding_identifier ( id) ;
779- }
780777
781778 if class. is_expression ( ) {
782- // We need to bind class expression in the class scope
779+ // We need to bind class expressions in the class scope before visiting the identifier.
783780 class. bind ( self ) ;
784781 }
785782
783+ if let Some ( id) = & class. id {
784+ self . visit_binding_identifier ( id) ;
785+ }
786+
786787 if let Some ( type_parameters) = & class. type_parameters {
787788 self . visit_ts_type_parameter_declaration ( type_parameters) ;
788789 }
Original file line number Diff line number Diff line change @@ -333,6 +333,22 @@ mod tests {
333333 assert ! ( scopes. get_binding( scopes. root_scope_id( ) , Ident :: new_const( "Fn" ) ) . is_some( ) ) ;
334334 }
335335
336+ #[ test]
337+ fn repeated_build_with_named_class_expression_and_syntax_checks ( ) {
338+ let allocator = Allocator :: default ( ) ;
339+ let source = "export const X = class Base {};" ;
340+ let source_type = SourceType :: ts ( ) ;
341+ let parse = oxc_parser:: Parser :: new ( & allocator, source, source_type) . parse ( ) ;
342+
343+ assert ! ( parse. errors. is_empty( ) ) ;
344+
345+ let first = SemanticBuilder :: new ( ) . with_check_syntax_error ( true ) . build ( & parse. program ) ;
346+ assert ! ( first. errors. is_empty( ) ) ;
347+
348+ let second = SemanticBuilder :: new ( ) . with_check_syntax_error ( true ) . build ( & parse. program ) ;
349+ assert ! ( second. errors. is_empty( ) ) ;
350+ }
351+
336352 #[ test]
337353 fn test_is_global ( ) {
338354 let source = "
You can’t perform that action at this time.
0 commit comments