Skip to content

Commit

Permalink
fix(es/transforms/compat): Fix block scoping of class declarations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
devongovett authored Apr 14, 2021
1 parent df2a926 commit d8a18df
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecmascript/transforms/base/src/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
28 changes: 28 additions & 0 deletions ecmascript/transforms/base/src/resolver/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
"#
);

0 comments on commit d8a18df

Please sign in to comment.