aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-11 16:07:28 +0000
committerGitHub <noreply@github.com>2020-12-12 00:07:28 +0800
commit515e93d88a9b5fa67b155ea081fc6716249d8ce8 (patch)
tree296467faacc9c22cc0fba86fb44565dc7719f9bd
parent57105b299ec582bc731b58002703faa297f10063 (diff)
downloadtracifyjs-515e93d88a9b5fa67b155ea081fc6716249d8ce8.tar.gz
tracifyjs-515e93d88a9b5fa67b155ea081fc6716249d8ce8.zip
fix corner case in `collapse_vars` (#4360)
fixes #4359
-rw-r--r--lib/compress.js12
-rw-r--r--test/compress/async.js27
2 files changed, 35 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js
index d4b911ee..cb3351ac 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1614,6 +1614,14 @@ merge(Compressor.prototype, {
var scan_lhs = lhs && !side_effects && !is_lhs_read_only(lhs, compressor);
var scan_rhs = foldable(candidate);
if (!scan_lhs && !scan_rhs) continue;
+ var funarg = candidate.name instanceof AST_SymbolFunarg;
+ var may_throw = return_false;
+ if (candidate.may_throw(compressor)) {
+ if (funarg && scope instanceof AST_AsyncFunction) continue;
+ may_throw = in_try ? function(node) {
+ return node.has_side_effects(compressor);
+ } : side_effects_external;
+ }
var read_toplevel = false;
var modify_toplevel = false;
// Locate symbols which may execute code outside of scanning range
@@ -1622,10 +1630,6 @@ merge(Compressor.prototype, {
var rvalue = get_rvalue(candidate);
if (!side_effects) side_effects = value_has_side_effects();
var replace_all = replace_all_symbols(candidate);
- var may_throw = candidate.may_throw(compressor) ? in_try ? function(node) {
- return node.has_side_effects(compressor);
- } : side_effects_external : return_false;
- var funarg = candidate.name instanceof AST_SymbolFunarg;
var hit = funarg;
var abort = false;
var replaced = 0;
diff --git a/test/compress/async.js b/test/compress/async.js
index 3011a6af..71df2449 100644
--- a/test/compress/async.js
+++ b/test/compress/async.js
@@ -444,3 +444,30 @@ issue_4349_3: {
expect_stdout: "function"
node_version: ">=8"
}
+
+issue_4359: {
+ options = {
+ collapse_vars: true,
+ unused: true,
+ }
+ input: {
+ try {
+ (async function(a) {
+ return a;
+ })(A);
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ try {
+ (async function(a) {
+ return a;
+ })(A);
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=8"
+}