emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 34245fe 008/110: Don't treat getter / setter pairs as dupl


From: Dmitry Gutov
Subject: [elpa] master 34245fe 008/110: Don't treat getter / setter pairs as duplicates
Date: Thu, 23 Jun 2016 01:12:52 +0000 (UTC)

branch: master
commit 34245fec536c0e22786b074e792873d8f2be84f5
Author: Jackson Hamilton <address@hidden>
Commit: Jackson Hamilton <address@hidden>

    Don't treat getter / setter pairs as duplicates
    
    Fixes #264
---
 js2-mode.el     |    8 +++++++-
 tests/parser.el |   14 +++++++++++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index 926003d..fc22efe 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -10654,7 +10654,13 @@ expression)."
                     (lambda (previous-elem)
                       (and (setq previous-elem-key-string
                                  (js2-property-key-string previous-elem))
-                           (string= previous-elem-key-string elem-key-string)))
+                           ;; Check if the property is a duplicate.
+                           (string= previous-elem-key-string elem-key-string)
+                           ;; But make an exception for getter / setter pairs.
+                           (not (and (js2-getter-setter-node-p elem)
+                                     (js2-getter-setter-node-p previous-elem)
+                                     (/= (js2-getter-setter-node-type elem)
+                                         (js2-getter-setter-node-type 
previous-elem))))))
                     elems))
           (js2-report-error "msg.dup.obj.lit.prop.strict"
                             elem-key-string
diff --git a/tests/parser.el b/tests/parser.el
index dc8c001..17519ca 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -294,10 +294,22 @@ the test."
   "'use strict';\nvar object = {a: 1, a: 2, 'a': 3, ['a']: 4, 1: 5, '1': 6, [1 
+ 1]: 7};"
   :syntax-error "a" :errors-count 4) ; "a" has 3 dupes, "1" has 1 dupe.
 
-;; errors... or lackthereof.
+(js2-deftest-parse function-strict-duplicate-getter
+  "'use strict';\nvar a = {get x() {}, get x() {}};"
+  :syntax-error "x" :errors-count 1)
+
+(js2-deftest-parse function-strict-duplicate-setter
+  "'use strict';\nvar a = {set x() {}, set x() {}};"
+  :syntax-error "x" :errors-count 1)
+
+;;; Lack of errors in strict mode
+
 (js2-deftest-parse function-strict-const-scope
   "'use strict';\nconst a;\nif (1) {\n  const a;\n}")
 
+(js2-deftest-parse function-strict-no-getter-setter-duplicate
+  "'use strict';\nvar a = {get x() {}, set x() {}};")
+
 ;;; Spread operator
 
 (js2-deftest-parse spread-in-array-literal



reply via email to

[Prev in Thread] Current Thread [Next in Thread]