diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-06-16 14:54:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-16 14:54:46 +0800 |
commit | 11e63bc3351597a7cd05a769346bb577e65069d4 (patch) | |
tree | 02724a869226c6bb1aec1fa6d75f0cec7baa2d80 /lib | |
parent | 33405bb24b9a5933badf146a9576953b8b456aad (diff) | |
download | tracifyjs-11e63bc3351597a7cd05a769346bb577e65069d4.tar.gz tracifyjs-11e63bc3351597a7cd05a769346bb577e65069d4.zip |
correctly determine scope of `AST_This` (#2109)
fixes #2107
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/lib/compress.js b/lib/compress.js index e14e63ae..a4552e85 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3207,18 +3207,21 @@ merge(Compressor.prototype, { if (body.length == 1 && body[0] instanceof AST_Return) { value = body[0].value; if (!value) return make_node(AST_Undefined, self); - value.walk(new TreeWalker(function(node) { + var tw = new TreeWalker(function(node) { if (value === self) return true; - if (node instanceof AST_SymbolRef && matches(node.scope.find_variable(node)) - || node instanceof AST_This && matches(node)) { + if (node instanceof AST_SymbolRef) { + var ref = node.scope.find_variable(node); + if (ref && ref.scope.parent_scope === fn.parent_scope) { + value = self; + return true; + } + } + if (node instanceof AST_This && !tw.find_parent(AST_Scope)) { value = self; return true; } - - function matches(ref) { - return ref && ref.scope.parent_scope === fn.parent_scope; - } - })); + }); + value.walk(tw); if (value !== self) value = best_of(compressor, value, self); } else { value = self; |