diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2019-03-14 21:36:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-14 21:36:45 +0800 |
commit | e49297e5eb7039246cc3a78019234826631eb623 (patch) | |
tree | a0cf11f0807a16f358feb323ccc16fa9f86c1020 | |
parent | ebd82b3fb6773f1985752550254a2effcc70b4af (diff) | |
download | tracifyjs-e49297e5eb7039246cc3a78019234826631eb623.tar.gz tracifyjs-e49297e5eb7039246cc3a78019234826631eb623.zip |
improve usability of `pure_funcs` (#3336)
fixes #3325
-rw-r--r-- | lib/compress.js | 12 | ||||
-rw-r--r-- | test/compress/pure_funcs.js | 38 |
2 files changed, 47 insertions, 3 deletions
diff --git a/lib/compress.js b/lib/compress.js index 04adb8b2..2a4f0df8 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -106,10 +106,16 @@ function Compressor(options, false_by_default) { var pure_funcs = this.options["pure_funcs"]; if (typeof pure_funcs == "function") { this.pure_funcs = pure_funcs; - } else { - this.pure_funcs = pure_funcs ? function(node) { + } else if (typeof pure_funcs == "string") { + this.pure_funcs = function(node) { + return pure_funcs !== node.expression.print_to_string(); + }; + } else if (Array.isArray(pure_funcs)) { + this.pure_funcs = function(node) { return pure_funcs.indexOf(node.expression.print_to_string()) < 0; - } : return_true; + }; + } else { + this.pure_funcs = return_true; } var top_retain = this.options["top_retain"]; if (top_retain instanceof RegExp) { diff --git a/test/compress/pure_funcs.js b/test/compress/pure_funcs.js index 56c36dd7..48140dd6 100644 --- a/test/compress/pure_funcs.js +++ b/test/compress/pure_funcs.js @@ -642,3 +642,41 @@ issue_3065_4: { })(); } } + +issue_3325_1: { + options = { + pure_funcs: "cb", + side_effects: true, + } + input: { + function cb() { + console.log("PASS"); + } + cb(); + } + expect: { + function cb() { + console.log("PASS"); + } + } +} + +issue_3325_2: { + options = { + pure_funcs: "xxxcbxxx", + side_effects: true, + } + input: { + function cb() { + console.log("PASS"); + } + cb(); + } + expect: { + function cb() { + console.log("PASS"); + } + cb(); + } + expect_stdout: "PASS" +} |