diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-05-24 14:29:30 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-24 14:29:30 +0800 |
commit | 24d9633a355ff0fac64dee2b356b99661079e921 (patch) | |
tree | f7ba20c3142952f536788f715f21023c8fd52e59 /lib/scope.js | |
parent | 7963b96681869a2a3b3d0873c8df1100fe2b36a5 (diff) | |
download | tracifyjs-24d9633a355ff0fac64dee2b356b99661079e921.tar.gz tracifyjs-24d9633a355ff0fac64dee2b356b99661079e921.zip |
fix corner cases with `eval()` (#3147)
fixes #3146
Diffstat (limited to 'lib/scope.js')
-rw-r--r-- | lib/scope.js | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/scope.js b/lib/scope.js index 17d87643..fb14480f 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -63,12 +63,12 @@ SymbolDef.prototype = { unmangleable: function(options) { if (!options) options = {}; - return (this.global && !options.toplevel) + return this.global && !options.toplevel || this.undeclared - || (!options.eval && (this.scope.uses_eval || this.scope.uses_with)) - || (options.keep_fnames + || !options.eval && this.scope.pinned() + || options.keep_fnames && (this.orig[0] instanceof AST_SymbolLambda - || this.orig[0] instanceof AST_SymbolDefun)); + || this.orig[0] instanceof AST_SymbolDefun); }, mangle: function(options) { var cache = options.cache && options.cache.props; @@ -355,7 +355,7 @@ function next_mangled_name(scope, options, def) { return name; } -AST_Symbol.DEFMETHOD("unmangleable", function(options){ +AST_Symbol.DEFMETHOD("unmangleable", function(options) { var def = this.definition(); return !def || def.unmangleable(options); }); @@ -363,16 +363,15 @@ AST_Symbol.DEFMETHOD("unmangleable", function(options){ // labels are always mangleable AST_Label.DEFMETHOD("unmangleable", return_false); -AST_Symbol.DEFMETHOD("unreferenced", function(){ - return this.definition().references.length == 0 - && !(this.scope.uses_eval || this.scope.uses_with); +AST_Symbol.DEFMETHOD("unreferenced", function() { + return !this.definition().references.length && !this.scope.pinned(); }); -AST_Symbol.DEFMETHOD("definition", function(){ +AST_Symbol.DEFMETHOD("definition", function() { return this.thedef; }); -AST_Symbol.DEFMETHOD("global", function(){ +AST_Symbol.DEFMETHOD("global", function() { return this.definition().global; }); |