[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7e7b6da 076/110: Simplify await parsing
From: |
Dmitry Gutov |
Subject: |
[elpa] master 7e7b6da 076/110: Simplify await parsing |
Date: |
Thu, 23 Jun 2016 01:13:00 +0000 (UTC) |
branch: master
commit 7e7b6da4619e4324cf2feedbac850f8d675f3bcf
Author: Jackson Ray Hamilton <address@hidden>
Commit: Jackson Ray Hamilton <address@hidden>
Simplify await parsing
---
js2-mode.el | 63 ++++++++++++++++++++++++++++++-----------------------------
1 file changed, 32 insertions(+), 31 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 3050417..aa1d60d 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -7756,39 +7756,40 @@ string is NAME. Returns nil and keeps current token
otherwise."
(defsubst js2-inside-function ()
(cl-plusp js2-nesting-of-function))
+(defsubst js2-inside-async-function ()
+ (and (js2-inside-function)
+ (js2-function-node-async js2-current-script-or-fn)))
+
(defun js2-parse-await-maybe (tt)
"Parse \"await\" as an AwaitExpression, if it is one."
- (let (pn post-parse-ts-state)
- (when (and (= tt js2-NAME)
- (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 ((pre-parse-ts-state (make-js2-ts-state))
- js2-recorded-identifiers
- js2-parsed-errors)
- (js2-get-token)
- ;; Stash the node in case it's a successful parse, because
then
- ;; we can return it.
- (setq pn (js2-make-unary js2-AWAIT 'js2-parse-unary-expr))
- ;; The token stream state after parsing must also be restored
- ;; if the node is returned.
- (setq post-parse-ts-state (make-js2-ts-state))
- (prog1
- (/= (js2-node-type (js2-unary-node-operand pn)) js2-ERROR)
- ;; Whether we parsed an AwaitExpression and need to do some
- ;; retroactive checks, or if the parse failed, the token
- ;; stream must be restored to its pre-parse state.
- (js2-ts-seek pre-parse-ts-state))))
- (js2-record-face 'font-lock-keyword-face)
- (let ((beg (js2-current-token-beg))
- (end (js2-current-token-end)))
- (js2-get-token)
- (unless (and (js2-inside-function)
- (js2-function-node-async js2-current-script-or-fn))
- (js2-report-error "msg.bad.await" nil
- beg (- end beg))))
- (js2-ts-seek post-parse-ts-state)
- pn)))
+ (and (= tt js2-NAME)
+ (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))
+ (recorded-identifiers js2-recorded-identifiers)
+ (parsed-errors js2-parsed-errors)
+ (current-token (js2-current-token))
+ (beg (js2-current-token-beg))
+ (end (js2-current-token-end))
+ pn)
+ (js2-get-token)
+ (setq pn (js2-make-unary js2-AWAIT 'js2-parse-unary-expr))
+ (if (= (js2-node-type (js2-unary-node-operand pn)) js2-ERROR)
+ ;; The parse failed, so pretend like nothing happened and restore
+ ;; the previous parsing state.
+ (progn
+ (js2-ts-seek ts-state)
+ (setq js2-recorded-identifiers recorded-identifiers
+ js2-parsed-errors parsed-errors)
+ ;; And ensure the caller knows about the failure.
+ nil)
+ ;; The parse was successful, so process and return the "await".
+ (js2-record-face 'font-lock-keyword-face current-token)
+ (unless (js2-inside-async-function)
+ (js2-report-error "msg.bad.await" nil
+ beg (- end beg)))
+ pn))))
(defun js2-get-prop-name-token ()
(js2-get-token (and (>= js2-language-version 170) 'KEYWORD_IS_NAME)))
- [elpa] master e9227bd 058/110: Fix a byte-compilation warning, (continued)
- [elpa] master e9227bd 058/110: Fix a byte-compilation warning, Dmitry Gutov, 2016/06/22
- [elpa] master 2a904e0 057/110: Implement object literal rest/spread (...), Dmitry Gutov, 2016/06/22
- [elpa] master 8047d7f 061/110: Recognize for-of and for-in loops with const, Dmitry Gutov, 2016/06/22
- [elpa] master 983f20a 072/110: Fix typo, Dmitry Gutov, 2016/06/22
- [elpa] master f8248df 066/110: Record class declarations for IMenu, Dmitry Gutov, 2016/06/22
- [elpa] master d92e772 069/110: Fix async parsing, Dmitry Gutov, 2016/06/22
- [elpa] master 5c97dce 002/110: Fix typo; Refs #185, Dmitry Gutov, 2016/06/22
- [elpa] master 97065c8 075/110: Fix compiler warning, Dmitry Gutov, 2016/06/22
- [elpa] master 849e061 081/110: js2-indent-operator-re, js2-declaration-keyword-re: Use symbols boundaries, Dmitry Gutov, 2016/06/22
- [elpa] master b2af331 083/110: Special-case unary + and -, Dmitry Gutov, 2016/06/22
- [elpa] master 7e7b6da 076/110: Simplify await parsing,
Dmitry Gutov <=
- [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, 2016/06/22
- [elpa] master 5f00a97 059/110: Use SVG for Travis CI badge, Dmitry Gutov, 2016/06/22