aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2020-05-03 20:30:10 +0100
committerGitHub <noreply@github.com>2020-05-04 03:30:10 +0800
commitffa19431773aec2205b4dfe7bbcc6d20e4e733fb (patch)
treebc849e35d72d9a318a7ecdfdffe1edf8c7dc7836 /lib
parentac429dc8e1a3d49af8fd3627449bd22ffd781f20 (diff)
downloadtracifyjs-ffa19431773aec2205b4dfe7bbcc6d20e4e733fb.tar.gz
tracifyjs-ffa19431773aec2205b4dfe7bbcc6d20e4e733fb.zip
fix corner case in `reduce_vars` (#3845)
fixes #3844
Diffstat (limited to 'lib')
-rw-r--r--lib/compress.js21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 8b6c38dd..59e4d861 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -716,6 +716,14 @@ merge(Compressor.prototype, {
fn.inlined = false;
var iife;
if (!fn.name && (iife = tw.parent()) instanceof AST_Call && iife.expression === fn) {
+ var hit = false;
+ var aborts = false;
+ fn.walk(new TreeWalker(function(node) {
+ if (hit) return aborts = true;
+ if (node instanceof AST_Return) return hit = true;
+ if (node instanceof AST_Scope && node !== fn) return true;
+ }));
+ if (aborts) push(tw);
reset_variables(tw, compressor, fn);
// Virtually turn IIFE parameters into variable definitions:
// (function(a,b) {...})(c,d) => (function() {var a=c,b=d; ...})()
@@ -735,22 +743,11 @@ merge(Compressor.prototype, {
d.fixed = false;
}
});
- var has_return = false;
- var visit = tw.visit;
- tw.visit = function(node, descend) {
- var ret = visit.call(tw, node, descend);
- if (!has_return && node instanceof AST_Return && tw.find_parent(AST_Scope) === fn) {
- has_return = true;
- push(tw);
- }
- return ret;
- };
descend();
- tw.visit = visit;
var safe_ids = tw.safe_ids;
pop(tw);
walk_defuns(tw, fn);
- if (!has_return) tw.safe_ids = safe_ids;
+ if (!aborts) tw.safe_ids = safe_ids;
} else {
push(tw);
reset_variables(tw, compressor, fn);