-
Notifications
You must be signed in to change notification settings - Fork 45.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
Adjust code to handle more availability of function.name #7670
Conversation
Changes Unknown when pulling 80ce391 on zpao:node-6.5-tests into * on facebook:master*. |
typeof parentType === 'string' ? | ||
parentType : | ||
Object.prototype.hasOwnProperty.call(parentType, 'displayName') ? | ||
parentType.display : |
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.
.displayName
?
Hrm, this feels off. It would be better to find a way to not use the .name I think. Or maybe some way to make the name not set to Constructor. |
I don't disagree. But I think we need |
IIRC |
How about: function noName(fn) {
return fn;
}
var Constructor = noName(function() { ... }); or some similar restructuring. |
Or |
Will the minifier preserve that? |
I figured it'd be nice to just break out that whole thing: createClass: function(spec) {
return applySpec(function() { ... }, spec);
} |
No, at least not Uglify with our current settings. But it probably doesn't matter since we only use this in warnings. And it's probably nice to have it go away in prod anyway. As for wrapping with another function… we already have I'm going to do what Ben said with a comment explaining why. |
What about |
It matters for the React devtools since it works in prod. I'm not too worried about adding another call on the stack since this is start up and not rerenders and start up for createClass sux anyway because of all the stuff it does in there. |
Yay thanks! It's now working on node 6 :) |
Debugging in Chrome devtools is a game changer. |
(cherry picked from commit 00ac179)
As @vjeux noted in https://www.facebook.com/groups/2003630259862046/permalink/2102903916601346/, using node v6.5 fails some tests. This is due to the status quo where
function.name
isn't well supported. @keyanzhang point toreact/src/isomorphic/classic/class/ReactClass.js
Line 765 in ed8a753
I changed a couple places in our code which were falling back to
function.name
to actually attempt to differentiate between cases where that's useful. It's not useful for theReact.createClass
cases since that will always beConstructor
. Instead I check if we have adisplayName
property instead of just using truthiness which seems to be good enough to differentiate.Tangential - we should probably consolidate so we don't duplicate this code. Originally it was pretty simple but we've had to add more checks and it's gotten longer. It's slightly different in these 2 places but close enough (and we can just use the same thing in both places).
Test Plan: Run tests in both node v6.5 & 4.x. Pass consistently.