]> code.delx.au - gnu-emacs-elpa/commitdiff
Also parse async function statement in export node
authorCarl Lei <xecycle@gmail.com>
Mon, 9 Nov 2015 02:06:55 +0000 (10:06 +0800)
committerCarl Lei <xecycle@gmail.com>
Mon, 9 Nov 2015 02:32:51 +0000 (10:32 +0800)
AsyncFunctionDeclaration is added as a
HoistableDeclaration (http://tc39.github.io/ecmascript-asyncawait/#HoistableDeclaration),
which shall be covered in productions "export Declaration" and "export
default HoistableDeclaration".

js2-mode.el
tests/parser.el

index 2e5b21014f7fcd6d65bc6d8333cdbe279361d0a4..eb805e7b331e4c9d3619aafc23035365af7fcf77 100644 (file)
@@ -8847,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)))))
@@ -8854,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
index 198e5780c4ce1cb070c33fc025fc3d893bd05ec8..50cb521bab8ea64cfb2b30dfaab813f67b5423d5 100644 (file)
@@ -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';")
@@ -805,6 +812,12 @@ the test."
 (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