branch: master
commit 83d98906e29ad69ecd6971d809425e2d79c4409f
Author: Jackson Hamilton <[email protected]>
Commit: Jackson Hamilton <[email protected]>
Fix await parsing
---
js2-mode.el | 11 ++++++++++-
tests/parser.el | 6 ++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/js2-mode.el b/js2-mode.el
index b20edd1..87a5f2c 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -7766,7 +7766,16 @@ string is NAME. Returns nil and keeps current token
otherwise."
(defun js2-match-await (tt)
(when (and (= tt js2-NAME)
- (js2-contextual-kwd-p (js2-current-token) "await"))
+ (js2-contextual-kwd-p (js2-current-token) "await")
+ ;; Per the proposal, AwaitExpression consists of "await"
+ ;; followed by a UnaryExpression. So look ahead for one.
+ (let ((ts-state (make-js2-ts-state))
+ js2-recorded-identifiers
+ js2-parsed-errors)
+ (js2-get-token)
+ (prog1
+ (/= (js2-node-type (js2-parse-unary-expr)) js2-ERROR)
+ (js2-ts-seek ts-state))))
(js2-record-face 'font-lock-keyword-face)
(let ((beg (js2-current-token-beg))
(end (js2-current-token-end)))
diff --git a/tests/parser.el b/tests/parser.el
index b3c3620..2111671 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -499,6 +499,12 @@ the test."
(js2-deftest-parse async-can-be-function-name
"function async() {\n}")
+(js2-deftest-parse await-can-be-name
+ "void await;")
+
+(js2-deftest-parse await-can-be-object-name
+ "await.z;")
+
(js2-deftest-parse await-can-be-var-name
"var await = 3;")