[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master b78d224 045/110: Parse async methods
From: |
Dmitry Gutov |
Subject: |
[elpa] master b78d224 045/110: Parse async methods |
Date: |
Thu, 23 Jun 2016 01:12:56 +0000 (UTC) |
branch: master
commit b78d224db5f9baaf16c8eed493e89b42bc2114b8
Author: Carl Lei <address@hidden>
Commit: Carl Lei <address@hidden>
Parse async methods
Refs https://github.com/mooz/js2-mode/issues/185#issuecomment-107710557
---
js2-mode.el | 25 +++++++++++++------------
tests/parser.el | 12 ++++++++++++
2 files changed, 25 insertions(+), 12 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index cc26f97..b843fd6 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -3977,6 +3977,7 @@ property `METHOD_TYPE' set to 'GET or 'SET. ")
(when type
(insert (cdr (assoc type '((GET . "get ")
(SET . "set ")
+ (ASYNC . "async ")
(FUNCTION . ""))))))
(when (and (js2-function-node-p right)
(eq 'STAR (js2-function-node-generator-type right)))
@@ -10722,12 +10723,11 @@ expression)."
(= js2-MUL tt))
(setq previous-token (js2-current-token)
tt (js2-get-prop-name-token)))
- ;; Handle 'get' or 'set' keywords
+ ;; Handle getter, setter and async methods
(let ((prop (js2-current-token-string)))
(when (and (>= js2-language-version 200)
(= js2-NAME tt)
- (or (string= prop "get")
- (string= prop "set"))
+ (member prop '("get" "set" "async"))
(member (js2-peek-token)
(list js2-NAME js2-STRING js2-NUMBER js2-LB)))
(setq previous-token (js2-current-token)
@@ -10804,11 +10804,10 @@ When `js2-is-in-destructuring' is t, forms like {a,
b, c} will be permitted."
(if (= (js2-token-type previous-token) js2-MUL)
"*"
(js2-token-string previous-token)))))
- (when (or (string= prop "get")
- (string= prop "set"))
+ (when (member prop '("get" "set" "async"))
(js2-set-face (js2-token-beg previous-token)
(js2-token-end previous-token)
- 'font-lock-keyword-face 'record)) ; get/set
+ 'font-lock-keyword-face 'record)) ; get/set/async
(cond
;; method definition: {f() {...}}
((and (= (js2-peek-token) js2-LP)
@@ -10913,7 +10912,8 @@ string or expression."
"Parse method property in an object literal or a class body.
JavaScript syntax is:
- { foo(...) {...}, get foo() {...}, set foo(x) {...}, *foo(...) {...} }
+ { foo(...) {...}, get foo() {...}, set foo(x) {...}, *foo(...) {...},
+ async foo(...) {...} }
and expression closure style is also supported
@@ -10922,11 +10922,12 @@ and expression closure style is also supported
POS is the start position of the `get' or `set' keyword.
PROP is the `js2-name-node' representing the property name.
TYPE-STRING is a string `get', `set', `*', or nil, indicating a found keyword."
- (let ((type (or (cdr (assoc type-string '(("get" . GET)
- ("set" . SET))))
- 'FUNCTION))
- result end
- (fn (js2-parse-function-expr)))
+ (let* ((type (or (cdr (assoc type-string '(("get" . GET)
+ ("set" . SET)
+ ("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")
diff --git a/tests/parser.el b/tests/parser.el
index a5fd602..578e0cb 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -446,6 +446,18 @@ the test."
(js2-deftest-parse async-arrow-function-expression
"a = async (b) => { b;\n};")
+(js2-deftest-parse async-method-in-object-literal
+ "({async f() {}});")
+
+(js2-deftest-parse async-method-in-class-body
+ "class C {\n async foo() {}\n}")
+
+(js2-deftest-parse static-async-method-in-class-body
+ "class C {\n static async foo() {}\n}")
+
+(js2-deftest-parse async-method-allow-await
+ "({async f() { await x;\n}});")
+
;;; Await
(js2-deftest-parse await-is-ok "async function foo() {\n await bar();\n}")
- [elpa] master b2af331 083/110: Special-case unary + and -, (continued)
- [elpa] master b2af331 083/110: Special-case unary + and -, Dmitry Gutov, 2016/06/22
- [elpa] master 7e7b6da 076/110: Simplify await parsing, Dmitry Gutov, 2016/06/22
- [elpa] master b57d129 077/110: Merge pull request #304 from jacksonrayhamilton/fix-void-async-await, Dmitry Gutov, 2016/06/22
- [elpa] master 645d129 078/110: Add support for JSDoc @callback, @func and @method tags, Dmitry Gutov, 2016/06/22
- [elpa] master b576cef 097/110: Declare vars created with renaming destructuring, Dmitry Gutov, 2016/06/22
- [elpa] master 12586e5 098/110: Allow space before global declaration, Dmitry Gutov, 2016/06/22
- [elpa] master 910520e 100/110: Merge pull request #333 from daniellandau/master, Dmitry Gutov, 2016/06/22
- [elpa] master 5ebc7b8 099/110: Change warning message to not conflict with spec, Dmitry Gutov, 2016/06/22
- [elpa] master ae3ed93 102/110: Backport for fix for #335, Dmitry Gutov, 2016/06/22
- [elpa] master fa419df 093/110: Merge pull request #327 from XeCycle/ckw-as, Dmitry Gutov, 2016/06/22
- [elpa] master b78d224 045/110: Parse async methods,
Dmitry Gutov <=
- [elpa] master 5f00a97 059/110: Use SVG for Travis CI badge, Dmitry Gutov, 2016/06/22
- [elpa] master 4fc6ef8 064/110: js2-class-node: Inherit from js2-object-node, Dmitry Gutov, 2016/06/22
- [elpa] master ae922a3 067/110: Remove js2-make-await as unused, Dmitry Gutov, 2016/06/22
- [elpa] master 502c14a 003/110: Use = instead of eq; Refs #185, Dmitry Gutov, 2016/06/22
- [elpa] master 73c0348 062/110: Merge pull request #297 from Christoph-D/master, Dmitry Gutov, 2016/06/22
- [elpa] master 49954ea 084/110: Use idle timer to reparse, even when the buffer's just been opened, Dmitry Gutov, 2016/06/22
- [elpa] master 1e1e410 082/110: Merge pull request #289 from dgreensp/fix-array-rest, Dmitry Gutov, 2016/06/22
- [elpa] master 16c42ce 087/110: Run all tests on 'make test', Dmitry Gutov, 2016/06/22
- [elpa] master e265b69 090/110: Fix a byte compilation warning on Emacs 25, Dmitry Gutov, 2016/06/22
- [elpa] master 87f43f3 089/110: Fix more remaining failures, Dmitry Gutov, 2016/06/22