-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Provide better error message for invalid default export declaration #7717
Provide better error message for invalid default export declaration #7717
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/7579/ |
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.
Thank you for this PR!
) { | ||
this.raise( | ||
this.state.start, | ||
"The `default` export can only take an expression;" + |
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.
It can also take function and class declarations.
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.
So would you suggest to just add both to the error message?
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.
Maybe just:
Only expressions, functions or class declarations are allowed as the default export.
(Let's add tests for those too).
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.
Yeah, I like that compact message.
So, I will change the message then and will also add tests for class declarations. Tests for functions declarations already exist as I've just seen.
87e2343
to
9c4d0ef
Compare
Alright, I changed the error message as discussed and added tests for class declarations/expressions. |
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.
Nice work, a great first PR!
@dczombera thanks! |
This one always catches me off-guard ( This might be the wrong forum but can anyone explain why you can't do that but you can do this?:
|
An easy way to think about it is that named exports must have a name, while default exports not. The real reason is that named exports export bindings, or variables (infact, if you modify an already exported variable the modules which import it will see the changes), while default exports export values. |
But there's an asterisk... there's always an asterisk 😇 If your default export is a It's also possible to make anything you want the default export by using |
I was not sure if an error message like the one suggested in the issue is consistent with the other error messages that babylon provides (is consistency even an issue when it comes to error messages?).
Apart from that, it's my first contribution to the project. I welcome any type of feedback. Thanks! :)
REPL from build