]> code.delx.au - gnu-emacs-elpa/commitdiff
Support yield*
authorDmitry Gutov <dgutov@yandex.ru>
Wed, 4 Jun 2014 01:18:31 +0000 (04:18 +0300)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 4 Jun 2014 01:18:31 +0000 (04:18 +0300)
#139

js2-mode.el
tests/parser.el

index f2b98028ec95ad8e6b1c3ffc4352d5b20e4413fc..28561054ec7cbc6bbb1c1ad94b5c4fc9a23a0a1d 100644 (file)
@@ -3631,8 +3631,9 @@ property `GETTER_SETTER' set to js2-GET or js2-SET. ")
             (:constructor nil)
             (:constructor make-js2-yield-node (&key (type js2-YIELD)
                                                     (pos js2-ts-cursor)
-                                                    len value)))
+                                                    len value star-p)))
   "AST node for yield statement or expression."
+  star-p ; whether it's yield*
   value) ; optional:  value to be yielded
 
 (put 'cl-struct-js2-yield-node 'js2-visitor 'js2-visit-yield-node)
@@ -3644,6 +3645,8 @@ property `GETTER_SETTER' set to js2-GET or js2-SET. ")
 (defun js2-print-yield-node (n i)
   (insert (js2-make-pad i))
   (insert "yield")
+  (when (js2-yield-node-star-p n)
+    (insert "*"))
   (when (js2-yield-node-value n)
     (insert " ")
     (js2-print-ast (js2-yield-node-value n) 0)))
@@ -8120,11 +8123,16 @@ but not BEFORE."
         (end (js2-current-token-end))
         (before js2-end-flags)
         (inside-function (js2-inside-function))
-        e ret name)
+        e ret name yield-star-p)
     (unless inside-function
       (js2-report-error (if (eq tt js2-RETURN)
                             "msg.bad.return"
                           "msg.bad.yield")))
+    (when (and inside-function
+               (eq (js2-function-node-generator-type js2-current-script-or-fn)
+                   'STAR)
+               (js2-match-token js2-MUL))
+      (setq yield-star-p t))
     ;; This is ugly, but we don't want to require a semicolon.
     (unless (memq (js2-peek-token-or-eol) js2-parse-return-stmt-enders)
       (setq e (js2-parse-expr)
@@ -8151,11 +8159,10 @@ but not BEFORE."
                                 (logior js2-end-returns js2-end-returns-value)))
           (js2-add-strict-warning "msg.return.inconsistent" nil pos end)))
      (t
-      (unless (js2-inside-function)
-        (js2-report-error "msg.bad.yield"))
       (setq ret (make-js2-yield-node :pos pos
                                      :len (- end pos)
-                                     :value e))
+                                     :value e
+                                     :star-p yield-star-p))
       (js2-node-add-children ret e)
       (unless expr-context
         (setq e ret
index a4e2e821b58c263b996e1937c7629092378c786b..a3fa1e067dd232aa4f4646fced9931d1bdedf4d2 100644 (file)
@@ -248,6 +248,8 @@ the test."
 
 (js2-deftest-parse harmony-generator "function* bar() {\n  yield 2;\n  return 3;\n}")
 
+(js2-deftest-parse harmony-generator-yield-star "(function*(a) {  yield* a;\n});")
+
 ;;; Scopes
 
 (js2-deftest ast-symbol-table-includes-fn-node "function foo() {}"