[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master d92e772 069/110: Fix async parsing
From: |
Dmitry Gutov |
Subject: |
[elpa] master d92e772 069/110: Fix async parsing |
Date: |
Thu, 23 Jun 2016 01:13:00 +0000 (UTC) |
branch: master
commit d92e772226a0dd18162e302114d6d0d0fbff40fd
Author: Jackson Hamilton <address@hidden>
Commit: Jackson Hamilton <address@hidden>
Fix async parsing
---
js2-mode.el | 24 +++++++++++++++++-------
tests/parser.el | 6 ++++++
2 files changed, 23 insertions(+), 7 deletions(-)
diff --git a/js2-mode.el b/js2-mode.el
index 85c3ee9..b20edd1 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -7749,12 +7749,20 @@ string is NAME. Returns nil and keeps current token
otherwise."
(js2-get-token)
t))
-(defun js2-match-async-arrow-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))
+;; 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 unused in a non-keyword context.
+
+(defun js2-match-async-arrow-function-1 ()
+ (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-match-await (tt)
(when (and (= tt js2-NAME)
@@ -9676,7 +9684,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)
+ (when (js2-match-async-arrow-function-1)
(setq async-p t))
;; Save the tokenizer state in case we find an arrow function
;; and have to rewind.
@@ -9711,6 +9719,8 @@ If NODE is non-nil, it is the AST node associated with
the symbol."
((and (= tt js2-ARROW)
(>= js2-language-version 200))
(js2-ts-seek ts-state)
+ (when async-p
+ (js2-match-async-arrow-function-2))
(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)))
diff --git a/tests/parser.el b/tests/parser.el
index 520ff45..b3c3620 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -487,6 +487,12 @@ the test."
;;; 'async' and 'await' are contextual keywords
+(js2-deftest-parse async-can-be-name
+ "void async;")
+
+(js2-deftest-parse async-can-be-object-name
+ "async.z;")
+
(js2-deftest-parse async-can-be-var-name
"var async = 3;")
- [elpa] master 00a455f 009/110: Merge pull request #266 from jacksonrayhamilton/no-getter-setter-duplicate, (continued)
- [elpa] master 00a455f 009/110: Merge pull request #266 from jacksonrayhamilton/no-getter-setter-duplicate, Dmitry Gutov, 2016/06/22
- [elpa] master 4894200 056/110: Merge pull request #290 from XeCycle/export-async-fn, Dmitry Gutov, 2016/06/22
- [elpa] master 027d546 051/110: Merge pull request #287 from dgreensp/fix-export-decls, Dmitry Gutov, 2016/06/22
- [elpa] master 13f0ffb 042/110: Fix parsing of param with destructure and default, Dmitry Gutov, 2016/06/22
- [elpa] master e48e862 055/110: Also parse async function statement in export node, Dmitry Gutov, 2016/06/22
- [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 <=
- [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, 2016/06/22
- [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