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 error message when not providing a value for JSX key #12983
Improve error message when not providing a value for JSX key #12983
Conversation
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/44294/ |
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit d0c94e1:
|
@@ -0,0 +1,2 @@ | |||
|
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.
Can you duplicate this test to fixtures/react/
, which shares test suites with react-automatic
but with runtime
set to classic
, the default behaviour of Babel 7.
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.
Okay. I've done that. As I mentioned in the issue, the compilation was successful in development mode. Fixing it was a bit trickier. Let me know if I have to improve my solution in any way.
Show location of attribute instead of only the path Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
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.
We should also throw in development mode, but let's merge this as-is for now since it already fixes the original problem (the unhelpful error message).
If you want to open the follow-up PR please do so, otherwise I'll open an issue about it!
This changed the behaviour very slightly, and actually ended up breaking a build of ours. Now when running the react-native metro bundler on an error case of 'key' used as a boolean it throws an exception and fails at compile time, instead of at runtime. We fixed it by fixing the bug, but maybe worth checking this scenario in future. Thanks for working on amazing open source anyway! |
Oh sorry for the inconvenience, I assumed this was already a compile-time error (just with a worse message) because of #12931. If many people are affected we could make it a warning instead, but since this would be a runtime error anyway I lean towards leaving it as-is. |
Throwing a more descriptive error when compiling a React element in a list that hasn't been given a value for its key.
eg.
<Component key />