diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-03-07 17:20:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 17:20:38 +0800 |
commit | 10b3752b1e1e16f92b7c6a62ed30d5dc3ac2cb49 (patch) | |
tree | 80f3c500f028d74acc0ffd7017f9500e2b20176e | |
parent | fe51a91395f3b0a6ab812f3f42746d39efd9e80c (diff) | |
download | tracifyjs-10b3752b1e1e16f92b7c6a62ed30d5dc3ac2cb49.tar.gz tracifyjs-10b3752b1e1e16f92b7c6a62ed30d5dc3ac2cb49.zip |
fix `mangle` of `AST_SymbolLambda` under `ie8` (#2978)
fixes #2976
-rw-r--r-- | lib/scope.js | 12 | ||||
-rw-r--r-- | test/compress/screw-ie8.js | 72 |
2 files changed, 77 insertions, 7 deletions
diff --git a/lib/scope.js b/lib/scope.js index 9a8e25cc..baa3e8bd 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -74,17 +74,12 @@ SymbolDef.prototype = { var cache = options.cache && options.cache.props; if (this.global && cache && cache.has(this.name)) { this.mangled_name = cache.get(this.name); - } - else if (!this.mangled_name && !this.unmangleable(options)) { - var s = this.scope; - var sym = this.orig[0]; - if (options.ie8 && sym instanceof AST_SymbolLambda) - s = s.parent_scope; + } else if (!this.mangled_name && !this.unmangleable(options)) { var def; if (def = this.redefined()) { this.mangled_name = def.mangled_name || def.name; } else { - this.mangled_name = next_mangled_name(s, options, this); + this.mangled_name = next_mangled_name(this.scope, options, this); } if (this.global && cache) { cache.set(this.name, this.mangled_name); @@ -377,6 +372,9 @@ function next_mangled_name(scope, options, def) { holes.push(scope.cname); } scope.names_in_use[name] = true; + if (options.ie8 && def.orig[0] instanceof AST_SymbolLambda) { + names_in_use(scope.parent_scope, options)[name] = true; + } return name; } diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js index b4098b8e..3a95eb6b 100644 --- a/test/compress/screw-ie8.js +++ b/test/compress/screw-ie8.js @@ -392,3 +392,75 @@ issue_2254_2: { } expect_stdout: "PASS" } + +issue_24_1: { + mangle = { + ie8: false, + } + input: { + (function(a) { + console.log(typeof function f(){} === typeof a ? "FAIL" : "PASS"); + })(); + } + expect: { + (function(o) { + console.log(typeof function o(){} === typeof o ? "FAIL" : "PASS"); + })(); + } + expect_stdout: "PASS" +} + +issue_24_2: { + mangle = { + ie8: true, + } + input: { + (function(a) { + console.log(typeof function f(){} === typeof a ? "FAIL" : "PASS"); + })(); + } + expect: { + (function(n) { + console.log(typeof function o(){} === typeof n ? "FAIL" : "PASS"); + })(); + } + expect_stdout: "PASS" +} + +issue_2976_1: { + mangle = { + ie8: false, + } + input: { + console.log(function f() { + var a; + return a === f ? "FAIL" : "PASS"; + }()); + } + expect: { + console.log(function n() { + var o; + return o === n ? "FAIL" : "PASS"; + }()); + } + expect_stdout: "PASS" +} + +issue_2976_2: { + mangle = { + ie8: true, + } + input: { + console.log(function f() { + var a; + return a === f ? "FAIL" : "PASS"; + }()); + } + expect: { + console.log(function n() { + var o; + return o === n ? "FAIL" : "PASS"; + }()); + } + expect_stdout: "PASS" +} |