]> code.delx.au - gnu-emacs-elpa/commitdiff
Refactor async arrow function matching
authorJackson Hamilton <jackson@jacksonrayhamilton.com>
Sun, 3 Jan 2016 03:24:51 +0000 (19:24 -0800)
committerJackson Hamilton <jackson@jacksonrayhamilton.com>
Sun, 3 Jan 2016 03:24:51 +0000 (19:24 -0800)
js2-mode.el

index f66294eed4ba4639011bb6f7bc90c3940b0406fa..049fd8d66272dfb70869da5bf9e33e3afe72b24f 100644 (file)
@@ -7749,21 +7749,10 @@ string is NAME.  Returns nil and keeps current token otherwise."
     (js2-get-token)
     t))
 
-;; Matching "async" is performed in two parts, because in the functions' one use
-;; case, it isn't known whether an arrow function is actually being parsed (and
-;; thus whether `js2-get-token' should be called) until later.  If
-;; `js2-get-token' were called eccentrically, `js2-current-token' would be
-;; off-by-one, causing `js2-parse-unary-expr' to potentially fail when "async"
-;; is used in a non-keyword context.
-
-(defun js2-match-async-arrow-function-1 ()
+(defun js2-match-async-arrow-function ()
   (and (js2-contextual-kwd-p (js2-current-token) "async")
        (/= (js2-peek-token) js2-FUNCTION)))
 
-(defun js2-match-async-arrow-function-2 ()
-  (js2-record-face 'font-lock-keyword-face)
-  (js2-get-token))
-
 (defun js2-parse-await-maybe (tt)
   "Parse \"await\" as an AwaitExpression, if it is one."
   (let (pn post-parse-ts-state)
@@ -9705,7 +9694,7 @@ If NODE is non-nil, it is the AST node associated with the symbol."
       ;; `js2-parse-function-stmt' nor `js2-parse-function-expr' that
       ;; interpret `async` token, we trash `async` and just remember
       ;; we met `async` keyword to `async-p'.
-      (when (js2-match-async-arrow-function-1)
+      (when (js2-match-async-arrow-function)
         (setq async-p t))
       ;; Save the tokenizer state in case we find an arrow function
       ;; and have to rewind.
@@ -9741,7 +9730,8 @@ If NODE is non-nil, it is the AST node associated with the symbol."
              (>= js2-language-version 200))
         (js2-ts-seek ts-state)
         (when async-p
-          (js2-match-async-arrow-function-2))
+          (js2-record-face 'font-lock-keyword-face)
+          (js2-get-token))
         (setq js2-recorded-identifiers recorded-identifiers
               js2-parsed-errors parsed-errors)
         (setq pn (js2-parse-function 'FUNCTION_ARROW (js2-current-token-beg) nil async-p)))