branch: externals/js2-mode commit a297ec2c2d9aa50ddc6c06959bb5a054e17b692a Merge: 7480c79691 95fe26867d Author: Dmitry Gutov <dgu...@yandex.ru> Commit: GitHub <nore...@github.com>
Merge pull request #593 from DamienCassou/top-level-await Support top-level await --- NEWS.md | 2 ++ js2-mode.el | 2 +- tests/parser.el | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 15b276a867..9f08e01228 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ ## Next +* Support top-level await + ([#593](https://github.com/mooz/js2-mode/issues/593)). * Fix for escaping inside template literal ([#592](https://github.com/mooz/js2-mode/issues/592)). diff --git a/js2-mode.el b/js2-mode.el index 754c6d15b0..d297c051e7 100644 --- a/js2-mode.el +++ b/js2-mode.el @@ -8064,7 +8064,7 @@ string is NAME. Returns nil and keeps current token otherwise." nil) ;; The parse was successful, so process and return the "await". (js2-record-face 'font-lock-keyword-face current-token) - (unless (js2-inside-async-function) + (unless (or (js2-inside-async-function) (equal js2-nesting-of-function 0)) (js2-report-error "msg.bad.await" nil beg (- end beg))) pn)))) diff --git a/tests/parser.el b/tests/parser.el index 8233d00044..8c2c7d04dd 100644 --- a/tests/parser.el +++ b/tests/parser.el @@ -572,6 +572,9 @@ the test." (js2-deftest-parse await-inside-array-is-ok "async function foo() {\n var results = [await bar(), await baz()];\n}") +(js2-deftest-parse await-top-level-is-ok + "await bar();") + (js2-deftest-parse await-inside-non-async-function-is-not-ok "function foo() {\n await bar();\n}" :syntax-error "await")