Skip to content

Commit

Permalink
Support top-level await
Browse files Browse the repository at this point in the history
  • Loading branch information
DamienCassou committed Oct 28, 2022
1 parent 7480c79 commit 95fe268
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)).

Expand Down
2 changes: 1 addition & 1 deletion js2-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
3 changes: 3 additions & 0 deletions tests/parser.el
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 95fe268

Please sign in to comment.