aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2019-12-22 01:08:56 +0000
committerGitHub <noreply@github.com>2019-12-22 01:08:56 +0000
commit519a00bd8adc72888ccf8d39161f835608a39ac3 (patch)
tree20215354e06ddf299fc87d50783c051943d96cf8
parent3ff0feddee0f293649d87be28d3cd0cf587dd195 (diff)
downloadtracifyjs-519a00bd8adc72888ccf8d39161f835608a39ac3.tar.gz
tracifyjs-519a00bd8adc72888ccf8d39161f835608a39ac3.zip
fix corner case in `collapse_vars` (#3642)
fixes #3641
-rw-r--r--lib/compress.js5
-rw-r--r--test/compress/collapse_vars.js23
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 3b40a5d3..c5b67569 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1569,6 +1569,7 @@ merge(Compressor.prototype, {
var parent = scanner.parent(level);
if (parent instanceof AST_Array) return find_stop_value(parent, level + 1);
if (parent instanceof AST_Assign) {
+ if (may_throw(parent)) return node;
if (parent.left instanceof AST_SymbolRef) {
var name = parent.left.name;
if (lhs.name == name) return node;
@@ -1647,7 +1648,9 @@ merge(Compressor.prototype, {
if (is_last_node(node, parent)) return node;
if (in_conditional(node, parent)) return node;
if (parent instanceof AST_Array) return find_stop_unused(parent, level + 1);
- if (parent instanceof AST_Assign) return find_stop_unused(parent, level + 1);
+ if (parent instanceof AST_Assign) {
+ return may_throw(parent) ? node : find_stop_unused(parent, level + 1);
+ }
if (parent instanceof AST_Binary) return find_stop_unused(parent, level + 1);
if (parent instanceof AST_Call) return find_stop_unused(parent, level + 1);
if (parent instanceof AST_Case) return find_stop_unused(parent, level + 1);
diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js
index 16cbadf8..edb5d57f 100644
--- a/test/compress/collapse_vars.js
+++ b/test/compress/collapse_vars.js
@@ -7399,3 +7399,26 @@ issue_3628_2: {
}
expect_stdout: "foo bar"
}
+
+issue_3641: {
+ options = {
+ collapse_vars: true,
+ }
+ input: {
+ var a, b;
+ try {
+ a = "foo";
+ b = (a += (A.p = 0, "bar")) % 0;
+ } catch (e) {}
+ console.log(a, b);
+ }
+ expect: {
+ var a, b;
+ try {
+ a = "foo";
+ b = (a += (A.p = 0, "bar")) % 0;
+ } catch (e) {}
+ console.log(a, b);
+ }
+ expect_stdout: "foo undefined"
+}