emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] 11/46: Support yield*


From: Dmitry Gutov
Subject: [elpa] 11/46: Support yield*
Date: Sat, 15 Nov 2014 20:57:58 +0000

dgutov pushed a commit to branch master
in repository elpa.

commit d96d8e7ff7ce3c04c7fd409d4f75dbc94e9b9030
Author: Dmitry Gutov <address@hidden>
Date:   Wed Jun 4 04:18:31 2014 +0300

    Support yield*
    
    #139
---
 js2-mode.el     |   17 ++++++++++++-----
 tests/parser.el |    2 ++
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index f2b9802..2856105 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -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
diff --git a/tests/parser.el b/tests/parser.el
index a4e2e82..a3fa1e0 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -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() {}"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]