-
-
Notifications
You must be signed in to change notification settings - Fork 192
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
Suggest fix for mispelled await inside async function #488
Conversation
It looks like there are test failures. (See the CI job failures.) Do you need help fixing the tests? |
I was some commits behind and error code 176 was already taken, oops. |
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.
Looks good! Let me know when I should merge.
Because we diagnose the await
and suggest async
instead, we should parse the arrow function's body as if async
was written instead. For example, this should report only one error, not two:
let f = await () => { // should error on 'await'
await g(); // shouldn't error because of 'await'; we're supposed to be in an async function
};
But we can leave that for a separate PR.
src/parse.cpp
Outdated
if (child->kind() == expression_kind::_invalid) { | ||
this->error_reporter_->report(error_missing_operand_for_operator{ | ||
.where = operator_span, | ||
}); | ||
} else if (this->in_async_function_ && this->is_arrow_kind(child) && | ||
!is_followed_by_async) { |
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.
Nit: Instead of checking for the async
token, you can ask if child
is async
:
!is_followed_by_async) { | |
child->attributes() == function_attributes::async) { |
src/quick-lint-js/error.h
Outdated
@@ -88,6 +88,13 @@ | |||
ERROR(QLJS_TRANSLATABLE("'await' is only allowed in async functions"), \ | |||
await_operator)) \ | |||
\ | |||
QLJS_ERROR_TYPE( \ | |||
error_await_followed_by_arrow_function, "E177", \ |
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.
Minor: Now E177 is taken. xD Try E178. (I can fix this when I merge if you want.)
ERROR(QLJS_TRANSLATABLE("'await' cannot be followed by an arrow " \ | ||
"function; use 'async' instead"), \ |
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 can merge if you wish. I can make a followup PR, one step at a time. |
Fix for issue #279.