-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Warn if the included mixin is undefined #6158
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
@@ -437,6 +437,12 @@ function validateMethodOverride(isAlreadyDefined, name) { | |||
*/ | |||
function mixSpecIntoComponent(Constructor, spec) { | |||
if (!spec) { | |||
warning( |
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.
Should wrap this in a __DEV__
block.
d2407c7
to
0fa4265
Compare
@swaroopsm updated the pull request. |
var typeofSpec = typeof spec; | ||
|
||
warning( | ||
typeofSpec !== 'object' || typeofSpec === null, |
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.
What is || typeofSpec === null
protecting against?
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.
Oh my bad. I meant spec === null
.
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.
Also, I think the typeofSpec !== 'object'
check here might be backwards. Warning behaves the opposite of an if statement, if I recall correctly. We should probably add a couple of unit tests to verify behavior.
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.
Ah right. Warning behaves the opposite of an if statement.
0fa4265
to
f3b9f0c
Compare
@swaroopsm updated the pull request. |
@@ -437,6 +437,20 @@ function validateMethodOverride(isAlreadyDefined, name) { | |||
*/ | |||
function mixSpecIntoComponent(Constructor, spec) { | |||
if (!spec) { | |||
if(__DEV__) { | |||
var typeofSpec = typeof spec, | |||
isMixinValid = typeofSpec === 'object' && spec !== null; |
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.
Let's just add another var statement, put a semicolon on the previous line.
One nit pick. Let's also add a few unit tests, and then I think this is ready to go. |
f3b9f0c
to
8341f31
Compare
@swaroopsm updated the pull request. |
Ok, looks good to me. Let's squash these commits ( |
8341f31
to
5aea1d3
Compare
@@ -437,6 +437,20 @@ function validateMethodOverride(isAlreadyDefined, name) { | |||
*/ | |||
function mixSpecIntoComponent(Constructor, spec) { | |||
if (!spec) { | |||
if(__DEV__) { |
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.
Note: this should be failing lint (travis is really behind though 😢)
@jimfb before you merge, can you read through #1305 which we didn't merge in part due to issues with jest mocking (many mocked things become undefined which was really noisy internally). It would be good to test this internally and see what the ramifications are. (Though that was before we had createWarning so we can now probably exclude this warning from tests) |
5aea1d3
to
9777b4d
Compare
@swaroopsm updated the pull request. |
@swaroopsm updated the pull request. |
Let’s also add a test for this “mixin defines a mixin” case. |
6274565
to
3d03798
Compare
@swaroopsm updated the pull request. |
3d03798
to
331b6de
Compare
@swaroopsm updated the pull request. |
'%s: You\'re attempting to include a mixin that is either null ' + | ||
'or not an object. Check the mixins included by the component, ' + | ||
'as well as any mixins they include themselves. ' + | ||
'Expected object but got %s.', |
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.
As far as I can see, this will print Expected object but got object.
for arrays.
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 right. IMHO, I don't think there might be a case where an array will be included as mixin? The docs also has an example with a mixin being an object. Thoughts?
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.
I mean that we should avoid confusing warnings even if turn up in edge cases.
We could do something like
var type;
if (spec == null) {
type = '' + spec;
} else if (Array.isArray(spec)) {
type = 'array';
} else {
type = typeof spec;
}
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.
As noted below, you’re right—we’ll never get into this block with arrays anyway so it doesn’t matter. I was wrong!
Now the only thing holding this back is @zpao sharing his thoughts on how we want to do branches now that we use major versions. Thank you for your work! |
LGTM |
Note: #7126 will need to get merged right after this because this PR used Jasmine 1 assertion format. |
(cherry picked from commit 18bad06)
(cherry picked from commit a49b7a2)
No description provided.