branch: master
commit 48942009bcd35ff8473f3bf05bff907be288748f
Merge: f9d28d3 e48e862
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>
Merge pull request #290 from XeCycle/export-async-fn
Also parse async function statement in export node
---
js2-mode.el | 15 ++++++++++++++-
tests/parser.el | 19 +++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/js2-mode.el b/js2-mode.el
index bf7219a..eb805e7 100644
--- a/js2-mode.el
+++ b/js2-mode.el
@@ -2551,7 +2551,9 @@ so many of its properties will be nil.
(js2-print-from-clause from))
(exports-list
(js2-print-named-imports exports-list)))
- (unless (and default (not (js2-assign-node-p default)))
+ (unless (or (and default (not (js2-assign-node-p default)))
+ (and declaration (or (js2-function-node-p declaration)
+ (js2-class-node-p declaration))))
(insert ";\n"))))
(cl-defstruct (js2-while-node
@@ -8845,6 +8847,11 @@ invalid export statements."
((js2-match-token js2-DEFAULT)
(setq default (cond ((js2-match-token js2-CLASS)
(js2-parse-class-stmt))
+ ((js2-match-token js2-NAME)
+ (if (js2-match-async-function)
+ (js2-parse-async-function-stmt)
+ (js2-unget-token)
+ (js2-parse-expr)))
((js2-match-token js2-FUNCTION)
(js2-parse-function-stmt))
(t (js2-parse-expr)))))
@@ -8852,6 +8859,12 @@ invalid export statements."
(setq declaration (js2-parse-variables (js2-current-token-type)
(js2-current-token-beg))))
((js2-match-token js2-CLASS)
(setq declaration (js2-parse-class-stmt)))
+ ((js2-match-token js2-NAME)
+ (setq declaration
+ (if (js2-match-async-function)
+ (js2-parse-async-function-stmt)
+ (js2-unget-token)
+ (js2-parse-expr))))
((js2-match-token js2-FUNCTION)
(setq declaration (js2-parse-function-stmt)))
(t
diff --git a/tests/parser.el b/tests/parser.el
index 79481c8..50cb521 100644
--- a/tests/parser.el
+++ b/tests/parser.el
@@ -790,6 +790,13 @@ the test."
(js2-mode)
(should (not (equal nil js2-parsed-warnings))))
+(js2-deftest export-default-async-function-no-semicolon "export default async
function foo() {}"
+ (js2-mode)
+ (should (equal nil js2-parsed-warnings)))
+(js2-deftest export-async-function-no-semicolon "export async function foo()
{}"
+ (js2-mode)
+ (should (equal nil js2-parsed-warnings)))
+
(js2-deftest-parse parse-export-rexport "export * from 'other/lib';")
(js2-deftest-parse parse-export-export-named-list "export {foo, bar as bang};")
(js2-deftest-parse parse-re-export-named-list "export {foo, bar as bang} from
'other/lib';")
@@ -799,6 +806,18 @@ the test."
(js2-deftest-parse parse-export-generator-declaration "export default
function* one() {\n}")
(js2-deftest-parse parse-export-assignment-expression "export default a = b;")
+(js2-deftest-parse parse-export-function-declaration-no-semi
+ "export function f() {\n}")
+
+(js2-deftest-parse parse-export-class-declaration-no-semi
+ "export class C {\n}")
+
+(js2-deftest-parse parse-export-async-function-allow-await
+ "export async function f() {\n await f();\n}")
+
+(js2-deftest-parse parse-export-default-async-function-allow-await
+ "export default async function f() {\n await f();\n}")
+
;;; Strings
(js2-deftest-parse string-literal