Skip to content

Commit

Permalink
fix(es/utils): Fix detection of hoisting (#6738)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf0 committed Jan 3, 2023
1 parent 0a1e30a commit b5d31cc
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
@@ -1,5 +1,5 @@
function f() {
var x, g, q, y;
var x, g;
g();
x = 10;
throw Error("foo");
Expand Down
@@ -1,6 +1,6 @@
"use strict";
function f() {
var x, g, q, y;
var x, g;
g();
x = 10;
throw Error("foo");
Expand Down
Expand Up @@ -1815,3 +1815,33 @@ fn issue_1825() {
fn issue_1851_1() {
test("x ?? (x = 'abc');", "x ?? (x = 'abc');");
}

#[test]
fn issue_6732_1() {
test(
"
if (false) {
foo(function () {
var module = {};
return module;
});
}
",
"",
);
}

#[test]
fn issue_6732_2() {
test(
"
if (false) {
function foo() {
var module = {};
return module;
};
}
",
"var foo;",
);
}
4 changes: 2 additions & 2 deletions crates/swc_ecma_utils/src/lib.rs
Expand Up @@ -494,8 +494,6 @@ impl Visit for Hoister {

fn visit_fn_decl(&mut self, f: &FnDecl) {
self.vars.push(f.ident.clone());

f.visit_children_with(self)
}

fn visit_pat(&mut self, p: &Pat) {
Expand All @@ -513,6 +511,8 @@ impl Visit for Hoister {

v.visit_children_with(self)
}

fn visit_fn_expr(&mut self, _n: &FnExpr) {}
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit b5d31cc

Please sign in to comment.