diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-06-24 10:09:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-24 17:09:19 +0800 |
commit | 82772ccb12cfef97480fa8021032a53f90cd1f45 (patch) | |
tree | fb7c6b6ff5a0b21ff63c00b077d776285a3d00b9 | |
parent | 7cbcd114402188d09267d3537894e611d2f13f9a (diff) | |
download | tracifyjs-82772ccb12cfef97480fa8021032a53f90cd1f45.tar.gz tracifyjs-82772ccb12cfef97480fa8021032a53f90cd1f45.zip |
workaround Safari quirks (#5033)
closes #5032
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | lib/minify.js | 2 | ||||
-rw-r--r-- | test/compress/awaits.js | 74 | ||||
-rw-r--r-- | test/compress/yields.js | 74 |
4 files changed, 151 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 6b4cbc7c..3f9678a7 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -108,6 +108,7 @@ function Compressor(options, false_by_default) { unsafe_undefined: false, unused : !false_by_default, varify : !false_by_default, + webkit : false, yields : !false_by_default, }, true); var evaluate = this.options["evaluate"]; @@ -5857,6 +5858,7 @@ merge(Compressor.prototype, { if (head_refs.start.block !== tail_refs.start.block || !mergeable(head_refs, tail_refs) || (head_refs.start.loop || !same_scope(def)) && !mergeable(tail_refs, head_refs) + || compressor.option("webkit") && is_funarg(def) !== is_funarg(tail.definition) || !all(tail_refs, function(sym) { return sym.scope.find_variable(def.name) === def; })) { diff --git a/lib/minify.js b/lib/minify.js index 52246d70..e85adb1f 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -100,7 +100,7 @@ function minify(files, options) { if (options.keep_fnames) set_shorthand("keep_fnames", options, [ "compress", "mangle" ]); if (options.toplevel) set_shorthand("toplevel", options, [ "compress", "mangle" ]); if (options.v8) set_shorthand("v8", options, [ "mangle", "output" ]); - if (options.webkit) set_shorthand("webkit", options, [ "mangle", "output" ]); + if (options.webkit) set_shorthand("webkit", options, [ "compress", "mangle", "output" ]); var quoted_props; if (options.mangle) { options.mangle = defaults(options.mangle, { diff --git a/test/compress/awaits.js b/test/compress/awaits.js index adfc9e4a..a0d744ba 100644 --- a/test/compress/awaits.js +++ b/test/compress/awaits.js @@ -1915,3 +1915,77 @@ issue_5023_2: { expect_stdout: "PASS" node_version: ">=8" } + +issue_5032_normal: { + options = { + merge_vars: true, + webkit: false, + } + input: { + function log(value) { + console.log(value); + return value; + } + async function f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS"); + } + expect: { + function log(value) { + console.log(value); + return value; + } + async function f(c) { + var b = log(c), c = b; + log(b); + log(c); + } + f("PASS"); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + ] + node_version: ">=8" +} + +issue_5032_webkit: { + options = { + merge_vars: true, + webkit: true, + } + input: { + function log(value) { + console.log(value); + return value; + } + async function f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS"); + } + expect: { + function log(value) { + console.log(value); + return value; + } + async function f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS"); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + ] + node_version: ">=8" +} diff --git a/test/compress/yields.js b/test/compress/yields.js index 2e0816e5..5761d85e 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -1142,3 +1142,77 @@ issue_5019_2: { ] node_version: ">=4" } + +issue_5032_normal: { + options = { + merge_vars: true, + webkit: false, + } + input: { + function log(value) { + console.log(value); + return value; + } + function *f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS").next(); + } + expect: { + function log(value) { + console.log(value); + return value; + } + function *f(c) { + var b = log(c), c = b; + log(b); + log(c); + } + f("PASS").next(); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + ] + node_version: ">=4" +} + +issue_5032_webkit: { + options = { + merge_vars: true, + webkit: true, + } + input: { + function log(value) { + console.log(value); + return value; + } + function *f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS").next(); + } + expect: { + function log(value) { + console.log(value); + return value; + } + function *f(a) { + var b = log(a), c = b; + log(b); + log(c); + } + f("PASS").next(); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + ] + node_version: ">=4" +} |