diff --git a/ecmascript/transforms/base/src/resolver/mod.rs b/ecmascript/transforms/base/src/resolver/mod.rs index 0dcfda3f21cc..d30489cd1aad 100644 --- a/ecmascript/transforms/base/src/resolver/mod.rs +++ b/ecmascript/transforms/base/src/resolver/mod.rs @@ -1245,6 +1245,9 @@ impl VisitMut for Hoister<'_, '_> { } fn visit_mut_class_decl(&mut self, node: &mut ClassDecl) { + if self.in_block { + return; + } self.resolver.in_type = false; self.resolver .visit_mut_binding_ident(&mut node.ident, Some(VarDeclKind::Let)); diff --git a/ecmascript/transforms/base/src/resolver/tests.rs b/ecmascript/transforms/base/src/resolver/tests.rs index 27af359e84db..05bc14bf467d 100644 --- a/ecmascript/transforms/base/src/resolver/tests.rs +++ b/ecmascript/transforms/base/src/resolver/tests.rs @@ -2646,3 +2646,31 @@ to!( })(); "# ); + +to!( + block_scope_class, + r#" + const g = 20; + + function baz() { + { + class g {} + console.log(g); + } + + return g; + } + "#, + r#" + const g = 20; + + function baz() { + { + class g1 {} + console.log(g1); + } + + return g; + } + "# +);