[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/js2-mode 7275b46 1/3: feat(parser): add for-await-of pa
From: |
ELPA Syncer |
Subject: |
[elpa] externals/js2-mode 7275b46 1/3: feat(parser): add for-await-of parsing |
Date: |
Wed, 14 Apr 2021 18:57:09 -0400 (EDT) |
branch: externals/js2-mode
commit 7275b4681b38102cb4ab57ce252fea7b7404b074
Author: Matus Goljer <matus.goljer@gmail.com>
Commit: Matus Goljer <matus.goljer@gmail.com>
feat(parser): add for-await-of parsing
---
js2-mode.el | 37 ++++++++++++++++++++++++++-----------
tests/parser.el | 6 ++++++
2 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index c05be21..abdb935 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -2632,14 +2632,17 @@ so many of its properties will be nil.
object
in-pos
each-pos
- foreach-p forof-p
+ await-pos
+ foreach-p forof-p
forawait-p
lp rp)))
"AST node for a for..in loop."
iterator ; [var] foo in ...
object ; object over which we're iterating
in-pos ; buffer position of 'in' keyword
each-pos ; buffer position of 'each' keyword, if foreach-p
+ await-pos ; buffer position of 'await' keyword, if forawait-p
foreach-p ; t if it's a for-each loop
+ forawait-p ; t if it's a for-await loop
forof-p) ; t if it's a for-of loop
(js2--struct-put 'js2-for-in-node 'js2-visitor 'js2-visit-for-in-node)
@@ -2653,10 +2656,13 @@ so many of its properties will be nil.
(defun js2-print-for-in-node (n i)
(let ((pad (js2-make-pad i))
(foreach (js2-for-in-node-foreach-p n))
+ (forawait (js2-for-in-node-forawait-p n))
(forof (js2-for-in-node-forof-p n)))
(insert pad "for ")
(if foreach
(insert "each "))
+ (if forawait
+ (insert "await "))
(insert "(")
(js2-print-ast (js2-for-in-node-iterator n) 0)
(insert (if forof " of " " in "))
@@ -9096,24 +9102,31 @@ invalid export statements."
node)))
(defun js2-parse-for ()
- "Parse a for, for-in or for each-in statement.
+ "Parse a for, for-in, for each-in or for await-in statement.
Last matched token must be js2-FOR."
(let ((for-pos (js2-current-token-beg))
(tmp-scope (make-js2-scope))
- pn is-for-each is-for-in-or-of is-for-of
- in-pos each-pos tmp-pos
+ pn is-for-each is-for-in-or-of is-for-of is-for-await
+ in-pos each-pos tmp-pos await-pos
init ; Node init is also foo in 'foo in object'.
cond ; Node cond is also object in 'foo in object'.
incr ; 3rd section of for-loop initializer.
body tt lp rp)
- ;; See if this is a for each () instead of just a for ()
(when (js2-match-token js2-NAME)
- (if (string= "each" (js2-current-token-string))
- (progn
- (setq is-for-each t
- each-pos (- (js2-current-token-beg) for-pos)) ; relative
- (js2-record-face 'font-lock-keyword-face))
- (js2-report-error "msg.no.paren.for")))
+ (cond
+ ;; See if this is a for each () instead of just a for ()
+ ((string= "each" (js2-current-token-string))
+ (progn
+ (setq is-for-each t
+ each-pos (- (js2-current-token-beg) for-pos)) ; relative
+ (js2-record-face 'font-lock-keyword-face)))
+ ;; See if this is a for await () instead of just a for ()
+ ((string= "await" (js2-current-token-string))
+ (progn
+ (setq is-for-await t
+ await-pos (- (js2-current-token-beg) for-pos)) ; relative
+ (js2-record-face 'font-lock-keyword-face)))
+ (t (js2-report-error "msg.no.paren.for"))))
(if (js2-must-match js2-LP "msg.no.paren.for")
(setq lp (- (js2-current-token-beg) for-pos)))
(setq tt (js2-get-token))
@@ -9175,6 +9188,8 @@ Last matched token must be js2-FOR."
:in-pos in-pos
:foreach-p is-for-each
:each-pos each-pos
+ :forawait-p is-for-await
+ :await-pos await-pos
:forof-p is-for-of
:lp lp
:rp rp)))
diff --git a/tests/parser.el b/tests/parser.el
index c87fa5f..335b26e 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -188,6 +188,12 @@ the test."
(js2-deftest-parse parse-for-of
"for (var a of []) {\n}")
+(js2-deftest-parse parse-for-each
+ "for each (var a of []) {\n}")
+
+(js2-deftest-parse parse-for-await
+ "for await (var a of []) {\n}")
+
(js2-deftest-parse of-can-be-name
"void of;")