branch: master
commit 92f5479d9bc27b5289d352946a76ef585525a22e
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>
Parse generator methods better
Fixes #340
---
js2-mode.el | 14 ++++++--------
tests/parser.el | 2 +-
2 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index ba492d7..527c639 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -10986,15 +10986,13 @@ TYPE-STRING is a string `get', `set', `*', or nil,
indicating a found keyword."
("async" . ASYNC))))
'FUNCTION))
result end
- (fn (js2-parse-function-expr (eq type 'ASYNC))))
- ;; it has to be an anonymous function, as we already parsed the name
- (if (/= (js2-node-type fn) js2-FUNCTION)
- (js2-report-error "msg.bad.prop")
- (if (cl-plusp (length (js2-function-name fn)))
- (js2-report-error "msg.bad.prop")))
+ (pos (js2-current-token-beg))
+ (_ (js2-must-match js2-LP "msg.no.paren.parms"))
+ (fn (js2-parse-function 'FUNCTION_EXPRESSION pos
+ (string= type-string "*")
+ (eq type 'ASYNC)
+ nil)))
(js2-node-set-prop fn 'METHOD_TYPE type) ; for codegen
- (when (string= type-string "*")
- (setf (js2-function-node-generator-type fn) 'STAR))
(unless pos (setq pos (js2-node-pos prop)))
(setq end (js2-node-end fn)
result (make-js2-method-node :pos pos
diff --git a/tests/parser.el b/tests/parser.el
index 69222b8..145bcbd 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -260,7 +260,7 @@ the test."
"var x = {get [foo + bar]() { return 42;\n}};")
(js2-deftest-parse object-literal-generator
- "var x = {*foo() { yield 42;\n}};")
+ "var x = {*foo() { yield* 42;\n}};")
(js2-deftest-parse object-literal-computed-generator-key
"var x = {*[foo + bar]() { yield 42;\n}};")