aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/scope.js36
-rw-r--r--test/compress/destructured.js60
2 files changed, 76 insertions, 20 deletions
diff --git a/lib/scope.js b/lib/scope.js
index 77000de3..ea662815 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -234,19 +234,24 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
if (node.label) node.label.thedef.references.push(node);
return true;
}
- // ensure mangling works if `catch` reuses a scope variable
- if (node instanceof AST_SymbolCatch) {
- var def = node.definition().redefined();
- if (def) for (var s = node.scope; s; s = s.parent_scope) {
- push_uniq(s.enclosed, def);
- if (s === def.scope) break;
+ if (node instanceof AST_SymbolDeclaration) {
+ if (node instanceof AST_SymbolCatch) {
+ // ensure mangling works if `catch` reuses a scope variable
+ var def = node.definition().redefined();
+ if (def) for (var s = node.scope; s; s = s.parent_scope) {
+ push_uniq(s.enclosed, def);
+ if (s === def.scope) break;
+ }
+ } else if (node instanceof AST_SymbolConst) {
+ // ensure compression works if `const` reuses a scope variable
+ var redef = node.definition().redefined();
+ if (redef) redef.const_redefs = true;
}
- return true;
- }
- // ensure compression works if `const` reuses a scope variable
- if (node instanceof AST_SymbolConst) {
- var redef = node.definition().redefined();
- if (redef) redef.const_redefs = true;
+ if (node.name != "arguments") return true;
+ var parent = node instanceof AST_SymbolVar && tw.parent();
+ if (parent instanceof AST_VarDef && !parent.value) return true;
+ var sym = node.scope.resolve().find_variable("arguments");
+ if (sym && is_arguments(sym)) sym.scope.uses_arguments = 3;
return true;
}
if (node instanceof AST_SymbolRef) {
@@ -295,13 +300,6 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
node.reference(options);
return true;
}
- if (node instanceof AST_VarDef) {
- if (node.value && node.name.name == "arguments") {
- var sym = node.name.scope.resolve().find_variable("arguments");
- if (sym && is_arguments(sym)) sym.scope.uses_arguments = 3;
- }
- return;
- }
});
self.walk(tw);
diff --git a/test/compress/destructured.js b/test/compress/destructured.js
index 4f6a9f2f..029b4427 100644
--- a/test/compress/destructured.js
+++ b/test/compress/destructured.js
@@ -2189,7 +2189,7 @@ issue_4446: {
issue_4456: {
options = {
- pure_getters: true,
+ pure_getters: "strict",
unused: true,
}
input: {
@@ -2398,3 +2398,61 @@ issue_4512: {
expect_stdout: "undefined"
node_version: ">=6"
}
+
+issue_4519_1: {
+ options = {
+ arguments: true,
+ keep_fargs: false,
+ }
+ input: {
+ try {
+ (function() {
+ var [ arguments ] = [];
+ arguments[0];
+ })();
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ try {
+ (function() {
+ var [ arguments ] = [];
+ arguments[0];
+ })();
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}
+
+issue_4519_2: {
+ options = {
+ pure_getters: "strict",
+ side_effects: true,
+ }
+ input: {
+ try {
+ (function() {
+ var [ arguments ] = [];
+ arguments[0];
+ })();
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect: {
+ try {
+ (function() {
+ var [ arguments ] = [];
+ arguments[0];
+ })();
+ } catch (e) {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: "PASS"
+ node_version: ">=6"
+}