branch: master commit 71416f652d7dc2530fc4d3bafab57a09707f5342 Merge: faf73e8 bb6c388 Author: Dmitry Gutov <dgu...@yandex.ru> Commit: GitHub <nore...@github.com>
Merge pull request #366 from XeCycle/drop-yield-paren Fix some yield parsing (#362) --- js2-mode.el | 13 ++++--------- tests/parser.el | 3 +++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/js2-mode.el b/js2-mode.el index 2848a2c..d18455d 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -1359,9 +1359,6 @@ the correct number of ARGS must be provided." (js2-msg "msg.bad.yield" "yield must be in a function.") -(js2-msg "msg.yield.parenthesized" - "yield expression must be parenthesized.") - (js2-msg "msg.bad.await" "await must be in async functions.") @@ -9363,7 +9360,7 @@ Last matched token must be js2-CONST or js2-VAR." (js2-parse-return-or-yield (js2-current-token-type) nil)) (defconst js2-parse-return-stmt-enders - (list js2-SEMI js2-RC js2-EOF js2-EOL js2-ERROR js2-RB js2-RP js2-YIELD)) + (list js2-SEMI js2-RC js2-EOF js2-EOL js2-ERROR js2-RB js2-RP)) (defsubst js2-now-all-set (before after mask) "Return whether or not the bits in the mask have changed to all set. @@ -9391,7 +9388,9 @@ but not BEFORE." (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) + (setq e (if (eq gen-type 'STAR) + (js2-parse-assign-expr) + (js2-parse-expr)) end (js2-node-end e))) (cond ((eq tt js2-RETURN) @@ -9772,8 +9771,6 @@ If NODE is non-nil, it is the AST node associated with the symbol." (while (and (not oneshot) (js2-match-token js2-COMMA)) (setq op-pos (- (js2-current-token-beg) pos)) ; relative - (if (= (js2-peek-token) js2-YIELD) - (js2-report-error "msg.yield.parenthesized")) (setq right (js2-parse-assign-expr) left pn pn (make-js2-infix-node :type js2-COMMA @@ -10162,8 +10159,6 @@ Returns the list in reverse order. Consumes the right-paren token." (unless (js2-match-token js2-RP) (cl-loop do (let ((tt (js2-get-token))) - (if (= tt js2-YIELD) - (js2-report-error "msg.yield.parenthesized")) (if (and (= tt js2-TRIPLEDOT) (>= js2-language-version 200)) (push (js2-make-unary tt 'js2-parse-assign-expr) result) diff --git a/tests/parser.el b/tests/parser.el index de97343..ead7a88 100644 --- a/tests/parser.el +++ b/tests/parser.el @@ -456,6 +456,9 @@ the test." (js2-deftest-parse harmony-generator-yield-star "(function*(a) { yield* a;\n});") +(js2-deftest-parse harmony-generator-yield-assign-expr + "(function*() { return {a: yield a, b: yield b, c: yield c};\n});") + ;;; Comprehensions (js2-deftest-parse parse-legacy-array-comp-loop-with-filter