(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
"'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