]> code.delx.au - gnu-emacs-elpa/commitdiff
Support ES6 computed property names.
authorStephen Hicks <sdh@google.com>
Tue, 11 Nov 2014 01:42:57 +0000 (17:42 -0800)
committerStephen Hicks <sdh@google.com>
Tue, 11 Nov 2014 01:48:36 +0000 (17:48 -0800)
This is specified by the ComputedPropertyName production in ยง12.2.5 of the draft ES6 spec: http://people.mozilla.org/~jorendorff/es6-draft.html#sec-object-initializer, and discussed at https://github.com/lukehoban/es6features\#enhanced-object-literals.

js2-mode.el
tests/parser.el

index 33d45bd690cc7629c14683b3c1f02f04bd2a37bf..c53c5b6b119ec8904afe236820328201bf54c91e 100644 (file)
@@ -1955,6 +1955,10 @@ the correct number of ARGS must be provided."
 (js2-msg "msg.yield.closing"
          "Yield from closing generator")
 
+;; Classes
+(js2-msg "msg.missing.computed.rb" ; added by js2-mode
+         "missing ']' after computed property expression")
+
 ;;; Tokens Buffer
 
 (defconst js2-ti-max-lookahead 2)
@@ -9554,6 +9558,13 @@ If ONLY-OF-P is non-nil, only the 'for (foo of bar)' form is allowed."
                  (not js2-recover-from-parse-errors))
             (setq continue nil)
           (push result elems)))
+       ;; {[Symbol.iterator]: ...}
+       ((and (= tt js2-LB)
+             (>= js2-language-version 200))
+        (let ((expr (js2-parse-expr)))
+          (js2-must-match js2-RB "msg.missing.computed.rb")
+          (setq after-comma nil)
+          (push (js2-parse-plain-property expr) elems)))
        ;; {12: x} or {10.7: x}
        ((= tt js2-NUMBER)
         (setq after-comma nil)
index 3804ce8e8e3285ca445130b6f83f98706376edf7..fe66d361abfdda8c6ef216a2237e247dc51a0fb3 100644 (file)
@@ -181,7 +181,7 @@ the test."
 
 ;;; Object literals
 
-(js2-deftest-parse abbreviated-object
+(js2-deftest-parse object-literal-shorthand
   "var x = {a: 1, b, c: 1, d};")
 
 (js2-deftest-parse object-literal-method
@@ -193,6 +193,9 @@ the test."
 (js2-deftest-parse object-literal-setter-method
   "var x = {set f(y) {  x = y;\n}};")
 
+(js2-deftest-parse object-literal-computed-keys
+  "var x = {[Symbol.iterator]: function() {}};")
+
 ;;; Function parameters
 
 (js2-deftest-parse function-with-default-parameters