From 3caf6062d5f6dd81c4b2972df1fc1ecf7ae6e0e4 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Wed, 17 Jan 2018 16:30:44 +0800 Subject: [PATCH] fix corner case in `unsafe_proto` --- lib/ast.js | 6 +++--- test/compress/reduce_vars.js | 26 +++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index fdd18d69..19f6bfb5 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -310,9 +310,9 @@ var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent }, clone: function(deep) { var node = this._clone(deep); - node.variables = this.variables.clone(); - node.functions = this.functions.clone(); - node.enclosed = this.enclosed.slice(); + if (this.variables) node.variables = this.variables.clone(); + if (this.functions) node.functions = this.functions.clone(); + if (this.enclosed) node.enclosed = this.enclosed.slice(); return node; } }, AST_Block); diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 5f640df8..33175d1b 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -5303,7 +5303,7 @@ issue_2774: { expect_stdout: "undefined" } -issue_2799: { +issue_2799_1: { options = { reduce_funcs: true, reduce_vars: true, @@ -5336,3 +5336,27 @@ issue_2799: { } expect_stdout: "15" } + +issue_2799_2: { + options = { + reduce_vars: true, + unsafe_proto: true, + unused: true, + } + input: { + (function() { + function foo() { + Function.prototype.call.apply(console.log, [ null, "PASS" ]); + } + foo(); + })(); + } + expect: { + (function() { + (function() { + (function() {}).call.apply(console.log, [ null, "PASS" ]); + })(); + })(); + } + expect_stdout: "PASS" +}