Skip to content

Commit

Permalink
fix corner case in functions (#5037)
Browse files Browse the repository at this point in the history
fixes #5036
  • Loading branch information
alexlamsl committed Jun 24, 2021
1 parent 1a064b6 commit 7621527
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6574,12 +6574,10 @@ merge(Compressor.prototype, {
return all(def.references, function(ref) {
var scope = ref.scope;
if (scope.find_variable(name) !== sym) return false;
if (forbidden) {
if (forbidden) do {
scope = scope.resolve();
do {
if (forbidden(scope)) return false;
} while ((scope = scope.parent_scope.resolve()) && scope !== fn);
}
if (forbidden(scope)) return false;
} while (scope !== fn && (scope = scope.parent_scope));
return true;
}) && def;
}
Expand Down
25 changes: 25 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6258,3 +6258,28 @@ issue_5025: {
}
expect_stdout: "object"
}

issue_5036: {
options = {
functions: true,
reduce_vars: true,
unused: true,
}
input: {
console.log(typeof function() {
var await = function f() {
return f;
};
return await() === await;
}() ? "PASS" : "FAIL");
}
expect: {
console.log(typeof function() {
function await() {
return await;
}
return await() === await;
}() ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
}

0 comments on commit 7621527

Please sign in to comment.