emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/js2-mode 1a5aeb22e9 3/3: Fix position of async function


From: ELPA Syncer
Subject: [elpa] externals/js2-mode 1a5aeb22e9 3/3: Fix position of async functions (expressions and statements)
Date: Tue, 19 Dec 2023 15:58:21 -0500 (EST)

branch: externals/js2-mode
commit 1a5aeb22e93def6d21872c6192391decd6aacb6b
Author: Dmitry Gutov <dmitry@gutov.dev>
Commit: Dmitry Gutov <dmitry@gutov.dev>

    Fix position of async functions (expressions and statements)
    
    Fixes #471
---
 js2-mode.el | 51 +++++++++++++++++++++++++--------------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

diff --git a/js2-mode.el b/js2-mode.el
index fa887a9a9a..53b317487e 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -8032,9 +8032,10 @@ string is NAME.  Returns nil and keeps current token 
otherwise."
 (defun js2-match-async-function ()
   (when (and (js2-contextual-kwd-p (js2-current-token) "async")
              (= (js2-peek-token) js2-FUNCTION))
-    (js2-record-face 'font-lock-keyword-face)
-    (js2-get-token)
-    t))
+    (let ((async-pos (js2-current-token-beg)))
+      (js2-record-face 'font-lock-keyword-face)
+      (js2-get-token)
+      async-pos)))
 
 (defun js2-match-async-arrow-function ()
   (and (js2-contextual-kwd-p (js2-current-token) "async")
@@ -8503,37 +8504,34 @@ Last token scanned is the close-curly for the function 
body."
                                   (js2-name-node-name name) pos end)
         (js2-add-strict-warning "msg.anon.no.return.value" nil pos end)))))
 
-(defun js2-parse-function-stmt (&optional async-p)
-  (let ((pos (js2-current-token-beg))
+(defun js2-parse-function-stmt (&optional async-pos)
+  (let ((pos (or async-pos (js2-current-token-beg)))
         (star-p (js2-match-token js2-MUL)))
     (js2-must-match-name "msg.unnamed.function.stmt")
     (let ((name (js2-create-name-node t))
           pn member-expr)
       (cond
        ((js2-match-token js2-LP)
-        (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-p name))
+        (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-pos name))
        (js2-allow-member-expr-as-function-name
         (setq member-expr (js2-parse-member-expr-tail nil name))
         (js2-parse-highlight-member-expr-fn-name member-expr)
         (js2-must-match js2-LP "msg.no.paren.parms")
-        (setf pn (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-p)
+        (setf pn (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-pos)
               (js2-function-node-member-expr pn) member-expr)
         pn)
        (t
         (js2-report-error "msg.no.paren.parms")
         (make-js2-error-node))))))
 
-(defun js2-parse-async-function-stmt ()
-  (js2-parse-function-stmt t))
-
-(defun js2-parse-function-expr (&optional async-p)
-  (let ((pos (js2-current-token-beg))
+(defun js2-parse-function-expr (&optional async-pos)
+  (let ((pos (or async-pos (js2-current-token-beg)))
         (star-p (js2-match-token js2-MUL))
         name)
     (when (js2-match-token js2-NAME)
       (setq name (js2-create-name-node t)))
     (js2-must-match js2-LP "msg.no.paren.parms")
-    (js2-parse-function 'FUNCTION_EXPRESSION pos star-p async-p name)))
+    (js2-parse-function 'FUNCTION_EXPRESSION pos star-p async-pos name)))
 
 (defun js2-parse-function-internal (function-type pos star-p &optional async-p 
name)
   (let (fn-node lp)
@@ -8725,11 +8723,11 @@ node are given relative start positions and correct 
lengths."
 (defun js2-statement-helper ()
   (let* ((tt (js2-get-token))
          (first-tt tt)
-         (async-stmt (js2-match-async-function))
+         (async-pos (js2-match-async-function))
          (parser (if (= tt js2-ERROR)
                      #'js2-parse-semi
-                   (if async-stmt
-                       #'js2-parse-async-function-stmt
+                   (if async-pos
+                       (apply-partially #'js2-parse-function-stmt async-pos)
                      (aref js2-parsers tt))))
          pn)
     ;; If the statement is set, then it's been told its label by now.
@@ -8740,7 +8738,7 @@ node are given relative start positions and correct 
lengths."
     ;; Don't do auto semi insertion for certain statement types.
     (unless (or (memq first-tt js2-no-semi-insertion)
                 (js2-labeled-stmt-node-p pn)
-                async-stmt)
+                async-pos)
       (js2-auto-insert-semicolon pn))
     pn))
 
@@ -9140,7 +9138,8 @@ invalid export statements."
     (js2-report-error "msg.mod.export.decl.at.top.level"))
   (let ((beg (js2-current-token-beg))
         (children (list))
-        exports-list from-clause declaration default)
+        exports-list from-clause declaration default
+        async-pos)
     (cond
      ((js2-match-token js2-MUL)
       (setq from-clause (js2-parse-from-clause))
@@ -9160,10 +9159,10 @@ invalid export statements."
                                (js2-parse-class-stmt)
                              (js2-parse-class-expr)))
                           ((js2-match-token js2-NAME)
-                           (if (js2-match-async-function)
+                           (if (setq async-pos (js2-match-async-function))
                                (if (eq (js2-peek-token) js2-NAME)
-                                   (js2-parse-async-function-stmt)
-                                 (js2-parse-function-expr t))
+                                   (js2-parse-function-stmt async-pos)
+                                 (js2-parse-function-expr async-pos))
                              (js2-unget-token)
                              (js2-parse-expr)))
                           ((js2-match-token js2-FUNCTION)
@@ -9177,8 +9176,8 @@ invalid export statements."
       (setq declaration (js2-parse-class-stmt)))
      ((js2-match-token js2-NAME)
       (setq declaration
-            (if (js2-match-async-function)
-                (js2-parse-async-function-stmt)
+            (if (setq async-pos (js2-match-async-function))
+                (js2-parse-function-stmt async-pos)
               (js2-unget-token)
               (js2-parse-expr))))
      ((js2-match-token js2-FUNCTION)
@@ -10698,15 +10697,15 @@ For instance, @[expr], @*::[expr], or ns::[expr]."
   "Parse a literal (leaf) expression of some sort.
 Includes complex literals such as functions, object-literals,
 array-literals, array comprehensions and regular expressions."
-  (let (tt node)
+  (let (tt node async-pos)
     (setq tt (js2-current-token-type))
     (cond
      ((= tt js2-CLASS)
       (js2-parse-class-expr))
      ((= tt js2-FUNCTION)
       (js2-parse-function-expr))
-     ((js2-match-async-function)
-      (js2-parse-function-expr t))
+     ((setq async-pos (js2-match-async-function))
+      (js2-parse-function-expr async-pos))
      ((= tt js2-LB)
       (js2-parse-array-comp-or-literal))
      ((= tt js2-LC)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]