diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-05-10 18:45:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-10 18:45:20 +0800 |
commit | 7bc7704edfe0a8af39924889e58b3d67f135b230 (patch) | |
tree | 7c4020db1a121280e815db00f9d3213113764d2b /lib | |
parent | 14e712ee802da2a6199653268f8519187ece2c51 (diff) | |
download | tracifyjs-7bc7704edfe0a8af39924889e58b3d67f135b230.tar.gz tracifyjs-7bc7704edfe0a8af39924889e58b3d67f135b230.zip |
fix corner case in `reduce_vars` (#3129)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/lib/compress.js b/lib/compress.js index d3c24529..5f35b98a 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -361,7 +361,7 @@ merge(Compressor.prototype, { if (def.scope === scope) return true; } while (scope instanceof AST_Function && (scope = scope.parent_scope)); })) { - tw.defun_ids[def.id] = undefined; + tw.defun_ids[def.id] = false; } def.recursive_refs = 0; def.references = []; @@ -386,23 +386,29 @@ merge(Compressor.prototype, { if (def.id in tw.defun_ids) { var marker = tw.defun_ids[def.id]; if (!marker) return; - if (marker !== tw.safe_ids) { - tw.defun_ids[def.id] = undefined; - return; + var visited = tw.defun_visited[def.id]; + if (marker === tw.safe_ids) { + if (!visited) return def.fixed; + } else if (visited) { + def.init.enclosed.forEach(function(d) { + if (def.init.variables.get(d.name) === d) return; + if (!safe_to_read(tw, d)) d.fixed = false; + }); + } else { + tw.defun_ids[def.id] = false; } - return def.fixed; - } - if (!tw.in_loop) { - tw.defun_ids[def.id] = tw.safe_ids; - return def.fixed; - } else if (tw.defun_ids[def.id] !== false) { - tw.defun_ids[def.id] = undefined; + } else { + if (!tw.in_loop) { + tw.defun_ids[def.id] = tw.safe_ids; + return def.fixed; + } + tw.defun_ids[def.id] = false; } } function walk_defuns(tw, scope) { scope.functions.each(function(def) { - if (def.init instanceof AST_Defun && tw.defun_ids[def.id] === undefined) { + if (def.init instanceof AST_Defun && !tw.defun_visited[def.id]) { tw.defun_ids[def.id] = tw.safe_ids; def.init.walk(tw); } @@ -587,8 +593,9 @@ merge(Compressor.prototype, { }); def(AST_Defun, function(tw, descend, compressor) { var id = this.name.definition().id; + if (tw.defun_visited[id]) return true; if (tw.defun_ids[id] !== tw.safe_ids) return true; - tw.defun_ids[id] = false; + tw.defun_visited[id] = true; this.inlined = false; push(tw); reset_variables(tw, compressor, this); @@ -820,6 +827,7 @@ merge(Compressor.prototype, { }); // Flow control for visiting `AST_Defun`s tw.defun_ids = Object.create(null); + tw.defun_visited = Object.create(null); // Record the loop body in which `AST_SymbolDeclaration` is first encountered tw.in_loop = null; tw.loop_ids = Object.create(null); |