]> code.delx.au - gnu-emacs-elpa/commitdiff
Report error for binding initializer outside destructuring
authorCarl Lei <xecycle@gmail.com>
Fri, 30 Oct 2015 13:17:16 +0000 (21:17 +0800)
committerCarl Lei <xecycle@gmail.com>
Fri, 30 Oct 2015 13:17:16 +0000 (21:17 +0800)
This reports error for both object literals and class bodies, but only
tests object literals; because if ES7 class property initializers are
added, the error no longer makes sense and needs another message,
e.g. missing semicolon after property initializer.

js2-mode.el
tests/parser.el

index 249f4ca8b03ec2c751b18fb5c23b2f5c0479a551..643e921ce1962a7f52503fc9a5986c9d6ee0ed43 100644 (file)
@@ -1717,6 +1717,9 @@ the correct number of ARGS must be provided."
 (js2-msg "msg.destruct.assign.no.init"
          "Missing = in destructuring declaration")
 
+(js2-msg "msg.init.no.destruct"
+         "Binding initializer not in destructuring assignment")
+
 (js2-msg "msg.no.octal.strict"
          "Octal numbers prohibited in strict mode.")
 
@@ -10725,6 +10728,8 @@ When `js2-is-in-destructuring' is t, forms like {a, b, c} will be permitted."
      ;; binding element with initializer
      ((and (= (js2-peek-token) js2-ASSIGN)
            (>= js2-language-version 200))
+      (if (not js2-is-in-destructuring)
+          (js2-report-error "msg.init.no.destruct"))
       (js2-parse-initialized-binding key))
      ;; regular prop
      (t
index 51b03eb56690b8a39914f15134a26fa34f7e8b78..136b97c5a23580553ea41d3ab00f34e87efe54f3 100644 (file)
@@ -198,6 +198,11 @@ the test."
   (should (equal '("msg.var.redecl" "a")
                  (caar js2-parsed-warnings))))
 
+(js2-deftest initializer-outside-destruct-is-error "({a=1});"
+  (js2-mode)
+  (should (equal "msg.init.no.destruct"
+                 (car (caar js2-parsed-errors)))))
+
 ;;; Object literals
 
 (js2-deftest-parse object-literal-shorthand