Skip to content

Commit 1a5aeb2

Browse files
committed
Fix position of async functions (expressions and statements)
Fixes #471
1 parent 1f94b09 commit 1a5aeb2

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

js2-mode.el

+25-26
Original file line numberDiff line numberDiff line change
@@ -8032,9 +8032,10 @@ string is NAME. Returns nil and keeps current token otherwise."
80328032
(defun js2-match-async-function ()
80338033
(when (and (js2-contextual-kwd-p (js2-current-token) "async")
80348034
(= (js2-peek-token) js2-FUNCTION))
8035-
(js2-record-face 'font-lock-keyword-face)
8036-
(js2-get-token)
8037-
t))
8035+
(let ((async-pos (js2-current-token-beg)))
8036+
(js2-record-face 'font-lock-keyword-face)
8037+
(js2-get-token)
8038+
async-pos)))
80388039

80398040
(defun js2-match-async-arrow-function ()
80408041
(and (js2-contextual-kwd-p (js2-current-token) "async")
@@ -8503,37 +8504,34 @@ Last token scanned is the close-curly for the function body."
85038504
(js2-name-node-name name) pos end)
85048505
(js2-add-strict-warning "msg.anon.no.return.value" nil pos end)))))
85058506

8506-
(defun js2-parse-function-stmt (&optional async-p)
8507-
(let ((pos (js2-current-token-beg))
8507+
(defun js2-parse-function-stmt (&optional async-pos)
8508+
(let ((pos (or async-pos (js2-current-token-beg)))
85088509
(star-p (js2-match-token js2-MUL)))
85098510
(js2-must-match-name "msg.unnamed.function.stmt")
85108511
(let ((name (js2-create-name-node t))
85118512
pn member-expr)
85128513
(cond
85138514
((js2-match-token js2-LP)
8514-
(js2-parse-function 'FUNCTION_STATEMENT pos star-p async-p name))
8515+
(js2-parse-function 'FUNCTION_STATEMENT pos star-p async-pos name))
85158516
(js2-allow-member-expr-as-function-name
85168517
(setq member-expr (js2-parse-member-expr-tail nil name))
85178518
(js2-parse-highlight-member-expr-fn-name member-expr)
85188519
(js2-must-match js2-LP "msg.no.paren.parms")
8519-
(setf pn (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-p)
8520+
(setf pn (js2-parse-function 'FUNCTION_STATEMENT pos star-p async-pos)
85208521
(js2-function-node-member-expr pn) member-expr)
85218522
pn)
85228523
(t
85238524
(js2-report-error "msg.no.paren.parms")
85248525
(make-js2-error-node))))))
85258526

8526-
(defun js2-parse-async-function-stmt ()
8527-
(js2-parse-function-stmt t))
8528-
8529-
(defun js2-parse-function-expr (&optional async-p)
8530-
(let ((pos (js2-current-token-beg))
8527+
(defun js2-parse-function-expr (&optional async-pos)
8528+
(let ((pos (or async-pos (js2-current-token-beg)))
85318529
(star-p (js2-match-token js2-MUL))
85328530
name)
85338531
(when (js2-match-token js2-NAME)
85348532
(setq name (js2-create-name-node t)))
85358533
(js2-must-match js2-LP "msg.no.paren.parms")
8536-
(js2-parse-function 'FUNCTION_EXPRESSION pos star-p async-p name)))
8534+
(js2-parse-function 'FUNCTION_EXPRESSION pos star-p async-pos name)))
85378535

85388536
(defun js2-parse-function-internal (function-type pos star-p &optional async-p name)
85398537
(let (fn-node lp)
@@ -8725,11 +8723,11 @@ node are given relative start positions and correct lengths."
87258723
(defun js2-statement-helper ()
87268724
(let* ((tt (js2-get-token))
87278725
(first-tt tt)
8728-
(async-stmt (js2-match-async-function))
8726+
(async-pos (js2-match-async-function))
87298727
(parser (if (= tt js2-ERROR)
87308728
#'js2-parse-semi
8731-
(if async-stmt
8732-
#'js2-parse-async-function-stmt
8729+
(if async-pos
8730+
(apply-partially #'js2-parse-function-stmt async-pos)
87338731
(aref js2-parsers tt))))
87348732
pn)
87358733
;; 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."
87408738
;; Don't do auto semi insertion for certain statement types.
87418739
(unless (or (memq first-tt js2-no-semi-insertion)
87428740
(js2-labeled-stmt-node-p pn)
8743-
async-stmt)
8741+
async-pos)
87448742
(js2-auto-insert-semicolon pn))
87458743
pn))
87468744

@@ -9140,7 +9138,8 @@ invalid export statements."
91409138
(js2-report-error "msg.mod.export.decl.at.top.level"))
91419139
(let ((beg (js2-current-token-beg))
91429140
(children (list))
9143-
exports-list from-clause declaration default)
9141+
exports-list from-clause declaration default
9142+
async-pos)
91449143
(cond
91459144
((js2-match-token js2-MUL)
91469145
(setq from-clause (js2-parse-from-clause))
@@ -9160,10 +9159,10 @@ invalid export statements."
91609159
(js2-parse-class-stmt)
91619160
(js2-parse-class-expr)))
91629161
((js2-match-token js2-NAME)
9163-
(if (js2-match-async-function)
9162+
(if (setq async-pos (js2-match-async-function))
91649163
(if (eq (js2-peek-token) js2-NAME)
9165-
(js2-parse-async-function-stmt)
9166-
(js2-parse-function-expr t))
9164+
(js2-parse-function-stmt async-pos)
9165+
(js2-parse-function-expr async-pos))
91679166
(js2-unget-token)
91689167
(js2-parse-expr)))
91699168
((js2-match-token js2-FUNCTION)
@@ -9177,8 +9176,8 @@ invalid export statements."
91779176
(setq declaration (js2-parse-class-stmt)))
91789177
((js2-match-token js2-NAME)
91799178
(setq declaration
9180-
(if (js2-match-async-function)
9181-
(js2-parse-async-function-stmt)
9179+
(if (setq async-pos (js2-match-async-function))
9180+
(js2-parse-function-stmt async-pos)
91829181
(js2-unget-token)
91839182
(js2-parse-expr))))
91849183
((js2-match-token js2-FUNCTION)
@@ -10698,15 +10697,15 @@ For instance, @[expr], @*::[expr], or ns::[expr]."
1069810697
"Parse a literal (leaf) expression of some sort.
1069910698
Includes complex literals such as functions, object-literals,
1070010699
array-literals, array comprehensions and regular expressions."
10701-
(let (tt node)
10700+
(let (tt node async-pos)
1070210701
(setq tt (js2-current-token-type))
1070310702
(cond
1070410703
((= tt js2-CLASS)
1070510704
(js2-parse-class-expr))
1070610705
((= tt js2-FUNCTION)
1070710706
(js2-parse-function-expr))
10708-
((js2-match-async-function)
10709-
(js2-parse-function-expr t))
10707+
((setq async-pos (js2-match-async-function))
10708+
(js2-parse-function-expr async-pos))
1071010709
((= tt js2-LB)
1071110710
(js2-parse-array-comp-or-literal))
1071210711
((= tt js2-LC)

0 commit comments

Comments
 (0)