]> code.delx.au - gnu-emacs-elpa/commitdiff
Don't treat getter / setter pairs as duplicates
authorJackson Hamilton <jackson@jacksonrayhamilton.com>
Fri, 11 Sep 2015 04:09:56 +0000 (21:09 -0700)
committerJackson Hamilton <jackson@jacksonrayhamilton.com>
Fri, 11 Sep 2015 04:09:56 +0000 (21:09 -0700)
Fixes #264

js2-mode.el
tests/parser.el

index 926003d5a80a1166c088b8ff8b7494bfbd462c9f..fc22efe8cc626f2af5ea820119c8b2ce7daf4fe9 100644 (file)
@@ -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
index dc8c001cac36fb209ee02ff6ba4c0ab51cd9527d..17519cab5cbdfac10d5ea809dbe622612e964cfb 100644 (file)
@@ -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