aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-12-28 02:05:59 +0000
committerGitHub <noreply@github.com>2020-12-28 10:05:59 +0800
commit28bcdbd7df403a4dca8bd2b7f327b65c8491235d (patch)
treeb6478d1f18a790427fcba01aaec8eecee3de96c3
parent6a8aed20496cde3b22cad7c9309ec804c71e5c84 (diff)
downloadtracifyjs-28bcdbd7df403a4dca8bd2b7f327b65c8491235d.tar.gz
tracifyjs-28bcdbd7df403a4dca8bd2b7f327b65c8491235d.zip
fix corner case in `inline` (#4472)
fixes #4471
-rw-r--r--lib/compress.js6
-rw-r--r--test/compress/functions.js34
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 58e0d785..c556c492 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -8039,7 +8039,11 @@ merge(Compressor.prototype, {
refs.forEach(function(ref) {
var def = ref.definition();
def.references.push(ref);
- if (replacing) def.replaced++;
+ if (replacing) {
+ def.replaced++;
+ } else {
+ def.single_use = false;
+ }
});
return node;
}
diff --git a/test/compress/functions.js b/test/compress/functions.js
index 066bc3ca..af99467a 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -5249,3 +5249,37 @@ issue_4451: {
}
expect_stdout: "function"
}
+
+issue_4471: {
+ options = {
+ inline: true,
+ reduce_funcs: true,
+ reduce_vars: true,
+ toplevel: true,
+ unused: true,
+ }
+ input: {
+ f(f());
+ function f() {
+ return g();
+ }
+ function g() {
+ {
+ console.log("PASS");
+ }
+ }
+ }
+ expect: {
+ f(g());
+ function f() {
+ return g();
+ }
+ function g() {
+ console.log("PASS");
+ }
+ }
+ expect_stdout: [
+ "PASS",
+ "PASS",
+ ]
+}