From: Stephen Hicks Date: Tue, 11 Nov 2014 01:42:57 +0000 (-0800) Subject: Support ES6 computed property names. X-Git-Url: https://code.delx.au/gnu-emacs-elpa/commitdiff_plain/926cb455eca15f05264d2b0192e96de28d1ba986 Support ES6 computed property names. 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. --- diff --git a/js2-mode.el b/js2-mode.el index 33d45bd69..c53c5b6b1 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -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) diff --git a/tests/parser.el b/tests/parser.el index 3804ce8e8..fe66d361a 100644 --- a/tests/parser.el +++ b/tests/parser.el @@ -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