-
-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unexpected 'await' keyword on function declaration #1187
base: master
Are you sure you want to change the base?
Changes from 5 commits
4f34348
a9e22ca
83a2c93
4726f58
b6d1eed
fdb3eb4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# E0719: unexpected 'await' keyword on function declaration | ||
|
||
If you meant to define an asynchronous function, you need to explicitly annotate | ||
the function with `async` keyword, not `await`. | ||
|
||
```javascript | ||
await function f() {} | ||
``` | ||
|
||
To fix this warning, simply replace `await` by `async`. Now, you have an | ||
asynchronous function and you're able to use `await` inside it. | ||
|
||
```javascript | ||
async function f() {} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (C) 2020 Matthew "strager" Glazar | ||
// See end of file for extended copyright information. | ||
|
||
#include <cstdio> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Undo. |
||
#include <cstdlib> | ||
#include <optional> | ||
#include <quick-lint-js/assert.h> | ||
|
@@ -417,6 +418,20 @@ bool Parser::parse_and_visit_statement(Parse_Visitor_Base &v, | |
this->skip(); | ||
this->check_body_after_label(); | ||
goto parse_statement; | ||
} else if (this->peek().type == Token_Type::kw_function) { | ||
this->parse_and_visit_function_declaration( | ||
v, Function_Declaration_Options{ | ||
.attributes = Function_Attributes::normal, | ||
.begin = this->peek().begin, | ||
.require_name = Name_Requirement::required_for_statement, | ||
.async_keyword = std::nullopt, | ||
.declare_keyword = std::nullopt, | ||
}); | ||
if (this->peek().type != Token_Type::left_paren) { | ||
this->diag_reporter_->report( | ||
Diag_Unexpected_Await_On_Function_Declaration{ | ||
.await_keyword = await_token.span()}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Must fix: Your special handling of
Also, adding code here in parse_and_visit_expression doesn't catch mistakes such as the following: foo(await function() {
});
|
||
} else { | ||
Expression *ast = | ||
this->parse_await_expression(v, await_token, Precedence{}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should follow the syntactic style of existing diagnostics (like E0178) instead: