diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-10 02:37:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 10:37:00 +0800 |
commit | 5ec82e58011cd07e668b37a40dc545c2431e3d48 (patch) | |
tree | b3d0a9df15027b3dae00f5ea37dd684066538690 | |
parent | c76481341ca62e6c651f4bc8db7ed3508423b421 (diff) | |
download | tracifyjs-5ec82e58011cd07e668b37a40dc545c2431e3d48.tar.gz tracifyjs-5ec82e58011cd07e668b37a40dc545c2431e3d48.zip |
fix corner case in `reduce_vars` (#4636)
-rw-r--r-- | lib/compress.js | 3 | ||||
-rw-r--r-- | test/compress/yields.js | 65 |
2 files changed, 67 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index b35fc6a5..a0e018e3 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9836,7 +9836,8 @@ merge(Compressor.prototype, { } } while (scope = scope.parent_scope); } - } else if (fixed.name && fixed.name.name == "await" && is_async(fixed)) { + } else if (fixed.name && (fixed.name.name == "await" && is_async(fixed) + || fixed.name.name == "yield" && is_generator(fixed))) { single_use = false; } if (single_use) fixed.parent_scope = self.scope; diff --git a/test/compress/yields.js b/test/compress/yields.js index 5a6948ed..cd2518d6 100644 --- a/test/compress/yields.js +++ b/test/compress/yields.js @@ -255,6 +255,71 @@ collapse_property_lambda: { node_version: ">=4" } +defun_name: { + input: { + function* yield() { + console.log("PASS"); + } + yield().next(); + } + expect: { + function* yield() { + console.log("PASS"); + } + yield().next(); + } + expect_stdout: "PASS" + node_version: ">=4" +} + +drop_fname: { + rename = true + options = { + reduce_vars: true, + toplevel: true, + unused: true, + } + mangle = { + toplevel: true, + } + input: { + function* yield() { + console.log("PASS"); + } + yield().next(); + } + expect: { + (function*() { + console.log("PASS"); + })().next(); + } + expect_stdout: "PASS" + node_version: ">=4" +} + +keep_fname: { + options = { + keep_fnames: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + function* yield() { + console.log("PASS"); + } + yield().next(); + } + expect: { + function* yield() { + console.log("PASS"); + } + yield().next(); + } + expect_stdout: "PASS" + node_version: ">=4" +} + evaluate: { options = { evaluate: true, |