-
-
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
feat: error on multiple export defaults in module #1096
Conversation
CLA Assistant Lite bot Thank you for your contribution! Like many free software projects, you must sign our Contributor License Agreement before we can accept your contribution. EDIT: All contributors have signed quick-lint-js' Contributor License Agreement (CLA-v1.md). |
I have read and hereby agree to quick-lint-js' Contributor License Agreement (CLA-v1.md). |
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.
This looks great! Let me know if you want to make changes or if I should merge it now.
[[qljs::message("cannot export default more than once", ARG(second_export_default))]] // | ||
[[qljs::message("export default previously appeared here", ARG(first_export_default))]] // |
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: Message here should match the title in docs/errors/E0715.md. (It doesn't have to be an exact match.)
For example, you could title the docs "cannot export default more than once" or you could change the first message to "cannot use multiple export default
statements in one module".
if (this->export_default_statement_span_.has_value()) { | ||
this->diag_reporter_->report( | ||
Diag_Multiple_Export_Defaults{ | ||
.second_export_default = this->peek().span(), | ||
.first_export_default = *this->export_default_statement_span_, | ||
}); | ||
} else { | ||
this->export_default_statement_span_ = this->peek().span(); | ||
} |
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.
👍
src/quick-lint-js/fe/parse.h
Outdated
// If set, refers to the first `export default` statement in this module. A | ||
// module cannot contain more than one `export default`. | ||
std::optional<Source_Code_Span> export_default_statement_span_ = std::nullopt; |
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.
👍
.first_export_default = *this->export_default_statement_span_, | ||
}); | ||
} else { | ||
this->export_default_statement_span_ = this->peek().span(); |
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: I think the name export_default_statement_span_
is wrong. The span is not for the whole statement, but for the 'default' keyword. first_export_default_statement_default_keyword_
is a good (but long) name. (I think length isn't a problem in this case; clarity is more important.)
6d77c61
to
28dcac6
Compare
I agree with your nitpicks, so I made the changes. I also fixed the error code in the header of the documentation file. It was |
Landed as commit 4bf1896. Thanks for the improvement! |
This closes issue #1039.