diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-10 15:41:00 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-10 23:41:00 +0800 |
commit | 083679bcad5711a90e49272e8a695a0c7b189a47 (patch) | |
tree | 41cc79a5f16a3fdb55c2856e5b4831e9c0ba46e9 /lib/compress.js | |
parent | f5659f292b796539a0960887f601b3f08c856bb7 (diff) | |
download | tracifyjs-083679bcad5711a90e49272e8a695a0c7b189a47.tar.gz tracifyjs-083679bcad5711a90e49272e8a695a0c7b189a47.zip |
fix corner cases with asynchronous generators (#4642)
fixes #4641
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/compress.js b/lib/compress.js index 8b5b020d..3d857190 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1307,6 +1307,10 @@ merge(Compressor.prototype, { return found; }); + function in_async_generator(scope) { + return scope instanceof AST_AsyncGeneratorDefun || scope instanceof AST_AsyncGeneratorFunction; + } + function find_scope(compressor) { var level = 0, node; while (node = compressor.parent(level++)) { @@ -2987,7 +2991,9 @@ merge(Compressor.prototype, { var stat = statements[i]; if (prev) { if (stat instanceof AST_Exit) { - stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor); + if (stat.value || !in_async_generator(scope)) { + stat.value = cons_seq(stat.value || make_node(AST_Undefined, stat)).transform(compressor); + } } else if (stat instanceof AST_For) { if (!(stat.init instanceof AST_Definitions)) { var abort = false; @@ -11045,7 +11051,10 @@ merge(Compressor.prototype, { }); OPT(AST_Return, function(self, compressor) { - if (self.value && is_undefined(self.value, compressor)) { + if (compressor.option("side_effects") + && self.value + && is_undefined(self.value, compressor) + && !in_async_generator(compressor.find_parent(AST_Scope))) { self.value = null; } return self; |