(js2-deftest-parse destruct-in-catch-clause
"try {\n} catch ({a, b}) {\n a + b;\n}")
+(js2-deftest-parse destruct-with-initializer-in-object
+ "var {a, b = 2, c} = {};")
+
+(js2-deftest-parse destruct-with-initializer-in-array
+ "var [a, b = 2, c] = [];")
+
+(js2-deftest-parse destruct-non-name-target-is-error
+ "var {1=1} = {};" :syntax-error "1" :errors-count 1)
+
+(js2-deftest-parse destruct-with-initializer-in-function-arguments
+ "function f({a, b = 1, c}, [d, e = 1, f]) {\n}")
+
+(js2-deftest-parse destruct-name-conflict-is-error-in-object
+ "\"use strict\";\nvar {a=1,a=2} = {};" :syntax-error "a" :errors-count 1)
+
+(js2-deftest destruct-name-conflict-is-warning-in-array "\"use strict\";\nvar [a=1,a=2] = [];"
+ (js2-mode)
+ (should (equal '("msg.var.redecl" "a")
+ (caar js2-parsed-warnings))))
+
;;; Object literals
(js2-deftest-parse object-literal-shorthand
(js2-deftest-parse object-literal-method
"var x = {f(y) { return y;\n}};")
+(js2-deftest object-literal-method-own-name-in-scope "({f(){f();}});"
+ (js2-mode)
+ (should (equal '("msg.undeclared.variable" "f")
+ (caar js2-parsed-warnings))))
+
(js2-deftest-parse object-literal-getter-method
"var x = {get f() { return 42;\n}};")
"function foo(a = 1, b = a + 1) {\n}")
(js2-deftest-parse function-with-no-default-after-default
- "function foo(a = 1, b) {\n}"
- :syntax-error "b")
+ "function foo(a = 1, b) {\n}")
(js2-deftest-parse function-with-destruct-after-default
- "function foo(a = 1, {b, c}) {\n}"
- :syntax-error "{")
+ "function foo(a = 1, {b, c}) {\n}")
(js2-deftest-parse function-with-rest-parameter
"function foo(a, b, ...rest) {\n}")
(js2-deftest-parse function-with-rest-after-default-parameter
"function foo(a = 1, ...rest) {\n}")
-;;; Strict identifiers
+;;; Strict mode errors
(js2-deftest-parse function-bad-strict-parameters
"'use strict';\nfunction foo(eval, {arguments}, bar) {\n}"
"'use strict';\narguments = 'fufufu';"
:syntax-error "arguments" :errors-count 1)
+(js2-deftest-parse function-property-strict-assignment
+ "'use strict';\narguments.okay = 'alright';")
+
+(js2-deftest-parse function-strict-with
+ "'use strict';\nwith ({}) {}"
+ :syntax-error "with" :errors-count 1)
+
+(js2-deftest-parse function-strict-octal
+ "'use strict';\nvar number = 0644;"
+ :syntax-error "0644" :errors-count 1)
+
+(js2-deftest-parse function-strict-duplicate-keys
+ "'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.
+
+(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
(js2-deftest-parse parse-class-keywordlike-method
"class C {\n delete() {}\n if() {}\n}")
+(js2-deftest-parse parse-harmony-class-allow-semicolon-element
+ "class Foo {;}" :reference "class Foo {\n}")
+
;;; Scopes
(js2-deftest ast-symbol-table-includes-fn-node "function foo() {}"