[Pkg-javascript-commits] [uglifyjs] 32/50: fix non-identifier getter/setter name (#2041)

Jonas Smedegaard dr at jones.dk
Thu Aug 17 23:06:46 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 3818a9e9c1a1c7a3831c438c6fc77dcd63da8498
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jun 1 18:11:16 2017 +0800

    fix non-identifier getter/setter name (#2041)
    
    fixes #2040
---
 lib/output.js               | 25 ++++++++++++++-----------
 test/compress/properties.js | 17 +++++++++++++++++
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/lib/output.js b/lib/output.js
index 0731fb4..78e2487 100644
--- a/lib/output.js
+++ b/lib/output.js
@@ -1207,9 +1207,8 @@ function OutputStream(options) {
         });
         else output.print("{}");
     });
-    DEFPRINT(AST_ObjectKeyVal, function(self, output){
-        var key = self.key;
-        var quote = self.quote;
+
+    function print_property_name(key, quote, output) {
         if (output.option("quote_keys")) {
             output.print_string(key + "");
         } else if ((typeof key == "number"
@@ -1226,20 +1225,24 @@ function OutputStream(options) {
         } else {
             output.print_string(key, quote);
         }
+    }
+
+    DEFPRINT(AST_ObjectKeyVal, function(self, output){
+        print_property_name(self.key, self.quote, output);
         output.colon();
         self.value.print(output);
     });
-    DEFPRINT(AST_ObjectSetter, function(self, output){
-        output.print("set");
+    AST_ObjectProperty.DEFMETHOD("_print_getter_setter", function(type, output) {
+        output.print(type);
         output.space();
-        self.key.print(output);
-        self.value._do_print(output, true);
+        print_property_name(this.key.name, this.quote, output);
+        this.value._do_print(output, true);
+    });
+    DEFPRINT(AST_ObjectSetter, function(self, output){
+        self._print_getter_setter("set", output);
     });
     DEFPRINT(AST_ObjectGetter, function(self, output){
-        output.print("get");
-        output.space();
-        self.key.print(output);
-        self.value._do_print(output, true);
+        self._print_getter_setter("get", output);
     });
     DEFPRINT(AST_Symbol, function(self, output){
         var def = self.definition();
diff --git a/test/compress/properties.js b/test/compress/properties.js
index 29bdfe2..d56d786 100644
--- a/test/compress/properties.js
+++ b/test/compress/properties.js
@@ -555,3 +555,20 @@ native_prototype: {
         "".indexOf.call(e, "bar");
     }
 }
+
+issue_2040: {
+    input: {
+        var a = 1;
+        var b = {
+            get "a-b"() {
+                return a;
+            },
+            set "a-b"(c) {
+                a = c;
+            }
+        };
+        console.log(b["a-b"], b["a-b"] = 2, b["a-b"]);
+    }
+    expect_exact: 'var a=1;var b={get"a-b"(){return a},set"a-b"(c){a=c}};console.log(b["a-b"],b["a-b"]=2,b["a-b"]);'
+    expect_stdout: "1 2 2"
+}

-- 
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