-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Improve non-top-level import/export error, especially for JS #47076
Comments
Isn’t |
Hey everyone, I'd like to take on this issue. |
can I work on this issue? |
@lokicodedaily sure, although you might want to co-ordinate with @vicente-s. |
@fatcerberus Good point. I updated the Expected section. |
@islandryu I'm backlogged on community PRs. I'll review it when I can. |
Thank you @islandryu! |
ES imports and exports can only be used at the top level of a module. This is illegal:
The current errors for these three statements are vague and, for JS, contain irrelevant terms:
Actual:
(1) "An import declaration can only be used in a namespace or module."
(2) "An export declaration can only be used in a module."
(3) "A namespace declaration is only allowed in a namespace or module."
Expected:
(1) When the node is in a JS file, "An import declaration can only be used at the top level of a module."
Otherwise, "An import declaration can only be used at the top level of a namespace or module."
(2) When the node is in a JS file, "An export declaration can only be used at the top level of a module."
Otherwise, "An export declaration can only be used at the top level of a namespace or module."
(3) "A namespace declaration is only allowed at the top level of a module."
Implementation:
checkGrammarModuleElementContext
issues these errors. I don't know whether it's better to make it smarter or just avoid calling it for case (1).The text was updated successfully, but these errors were encountered: