aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-10 18:07:05 +0100
committerGitHub <noreply@github.com>2020-05-11 01:07:05 +0800
commit7e0ad232b079202024ea845a2076ee78e1e0dbd7 (patch)
tree4359af5064a156b62fda43fd19ee241e5d80f972
parent63adfb1590886b9b03827805e1226bfe235e5868 (diff)
downloadtracifyjs-7e0ad232b079202024ea845a2076ee78e1e0dbd7.tar.gz
tracifyjs-7e0ad232b079202024ea845a2076ee78e1e0dbd7.zip
retain `@__PURE__` call when return value is used (#3874)
-rw-r--r--lib/compress.js1
-rw-r--r--test/compress/pure_funcs.js25
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 5509137b..6a444e92 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3499,6 +3499,7 @@ merge(Compressor.prototype, {
if (fn instanceof AST_Lambda) {
if (fn.evaluating) return this;
if (fn.name && fn.name.definition().recursive_refs > 0) return this;
+ if (this.is_expr_pure(compressor)) return this;
var stat = fn.first_statement();
if (!(stat instanceof AST_Return)) return this;
var args = eval_args(this.args);
diff --git a/test/compress/pure_funcs.js b/test/compress/pure_funcs.js
index 15ddf095..d65399f1 100644
--- a/test/compress/pure_funcs.js
+++ b/test/compress/pure_funcs.js
@@ -782,3 +782,28 @@ inline_pure_call_3: {
"undefined",
]
}
+
+inline_pure_call_4: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ var a = /*@__PURE__*/ function() {
+ return console.log("PASS"), 42;
+ }();
+ console.log(a);
+ }
+ expect: {
+ var a = function() {
+ return console.log("PASS"), 42;
+ }();
+ console.log(a);
+ }
+ expect_stdout: [
+ "PASS",
+ "42",
+ ]
+}