[Pkg-javascript-commits] [uglifyjs] 52/228: fix `evaluate` on object getter & setter (#1515)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:16 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository uglifyjs.

commit b34fa11a13221b7ad26ea48f18fcf2f5903c94c1
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Mar 1 02:03:47 2017 +0800

    fix `evaluate` on object getter & setter (#1515)
---
 lib/compress.js           | 15 ++++++++++-----
 test/compress/evaluate.js | 26 ++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 294cb61..0349e45 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1148,11 +1148,14 @@ merge(Compressor.prototype, {
         def(AST_Statement, function(){
             throw new Error(string_template("Cannot evaluate a statement [{file}:{line},{col}]", this.start));
         });
+        // XXX: AST_Accessor and AST_Function both inherit from AST_Scope,
+        // which itself inherits from AST_Statement; however, they aren't
+        // really statements.  This could bite in other places too. :-(
+        // Wish JS had multiple inheritance.
+        def(AST_Accessor, function(){
+            throw def;
+        });
         def(AST_Function, function(){
-            // XXX: AST_Function inherits from AST_Scope, which itself
-            // inherits from AST_Statement; however, an AST_Function
-            // isn't really a statement.  This could byte in other
-            // places too. :-( Wish JS had multiple inheritance.
             throw def;
         });
         function ev(node, compressor) {
@@ -1180,7 +1183,9 @@ merge(Compressor.prototype, {
                 for (var i = 0, len = this.properties.length; i < len; i++) {
                     var prop = this.properties[i];
                     var key = prop.key;
-                    if (key instanceof AST_Node) {
+                    if (key instanceof AST_Symbol) {
+                        key = key.name;
+                    } else if (key instanceof AST_Node) {
                         key = ev(key, compressor);
                     }
                     if (typeof Object.prototype[key] === 'function') {
diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js
index 6bed73f..f84436d 100644
--- a/test/compress/evaluate.js
+++ b/test/compress/evaluate.js
@@ -337,6 +337,32 @@ unsafe_object_repeated: {
     }
 }
 
+unsafe_object_accessor: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unsafe: true,
+    }
+    input: {
+        function f() {
+            var a = {
+                get b() {},
+                set b() {}
+            };
+            return {a:a};
+        }
+    }
+    expect: {
+        function f() {
+            var a = {
+                get b() {},
+                set b() {}
+            };
+            return {a:a};
+        }
+    }
+}
+
 unsafe_function: {
     options = {
         evaluate  : true,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list