diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-04-18 17:03:52 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-18 17:03:52 +0800 |
commit | e8a2c0b5bf18659a3e1285b6038ea755a290220d (patch) | |
tree | 6519593833ec84a2f5c19ce3274a1e55b13d5900 | |
parent | 21cd7e3f571030c889619b39287ac8420044bcc4 (diff) | |
download | tracifyjs-e8a2c0b5bf18659a3e1285b6038ea755a290220d.tar.gz tracifyjs-e8a2c0b5bf18659a3e1285b6038ea755a290220d.zip |
fix corner case in `functions` (#3365)
fixes #3364
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | lib/scope.js | 4 | ||||
-rw-r--r-- | test/compress/functions.js | 65 |
3 files changed, 67 insertions, 4 deletions
diff --git a/lib/compress.js b/lib/compress.js index 2fdfc89e..f5479bef 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3602,7 +3602,7 @@ merge(Compressor.prototype, { compressor.warn("Declaring {name} as function [{file}:{line},{col}]", template(def.name)); var defun = make_node(AST_Defun, def, def.value); defun.name = make_node(AST_SymbolDefun, def.name, def.name); - self.def_function(defun.name); + defun.parent_scope.resolve().def_function(defun.name); body.push(defun); } else { if (side_effects.length > 0) { diff --git a/lib/scope.js b/lib/scope.js index 47e05da2..08c9efd8 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -61,8 +61,6 @@ SymbolDef.next_id = 1; SymbolDef.prototype = { unmangleable: function(options) { - if (!options) options = {}; - return this.global && !options.toplevel || this.undeclared || !options.eval && this.scope.pinned() @@ -296,7 +294,7 @@ AST_Scope.DEFMETHOD("def_variable", function(symbol, init) { AST_Lambda.DEFMETHOD("resolve", return_this); AST_Scope.DEFMETHOD("resolve", function() { - return this.parent_scope; + return this.parent_scope.resolve(); }); AST_Toplevel.DEFMETHOD("resolve", return_this); diff --git a/test/compress/functions.js b/test/compress/functions.js index 2d00c594..c43c17eb 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -2916,3 +2916,68 @@ issue_2485: { } expect_stdout: "6" } + +issue_3364: { + options = { + functions: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + mangle = {} + input: { + var s = 2, a = 100, b = 10, c = 0; + function f(p, e, r) { + try { + for (var i = 1; i-- > 0;) + var a = function(x) { + function g(y) { + y && y[a++]; + } + var x = g(--s >= 0 && f(c++)); + for (var j = 1; --j > 0;); + }(); + } catch (e) { + try { + return; + } catch (z) { + for (var k = 1; --k > 0;) { + for (var l = 1; l > 0; --l) { + var n = function() {}; + for (var k in n) + var o = (n, k); + } + } + } + } + } + var r = f(); + console.log(c); + } + expect: { + var s = 2, c = 0; + (function n(r, o, a) { + try { + for (var f = 1; f-- >0;) + var t = function(r) { + (function(r) { + r && r[t++]; + })(--s >= 0 && n(c++)); + for (var o = 1; --o > 0;); + }(); + } catch (o) { + try { + return; + } catch (r) { + for (var v = 1; --v > 0;) + for (var i = 1; i > 0;--i) { + function u() {} + for (var v in u); + } + } + } + })(); + console.log(c); + } + expect_stdout: "2" +} |