Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/transforms_optimization): should capture hoisted variables correctly #6738

Merged
merged 4 commits into from Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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