-
Notifications
You must be signed in to change notification settings - Fork 414
Add babelHelpers mock for fb-www #1354
Conversation
If we change the subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass)
Object.setPrototypeOf
? Object.setPrototypeOf(subClass, superClass)
: (subClass.__proto__ = superClass); You no longer get broken output. Maybe we should use this version instead? |
We could, but is it worth figuring out why the current version breaks? |
@gaearon I'm not even sure how it works, maybe it relies on some special internal hacks/logic that I'm not aware of. See my inline comment. |
Object.assign(subClass, superClass); | ||
subClass.prototype = Object.create(superClass && superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
subClass.__superConstructor__ = superClass; |
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 does __superConstructor__
even do? Every other polyfill does a __proto__
assignment or setPrototypeOf
here instead.
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.
That's an FB specific thing, I don't actually remember what it does. Need to check.
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.
If you change that one line to __proto__
, everything works as expected. but because we are setting it to be superClass
, it tries to emit the function React.Component
instead; which isn't right :/
Regardless of what the polyfill does or doesn't do, isn't Prepack emitting variable access for undeclared variables always a bug? I don't understand how valid JS code (app code + polyfill code), even if buggy, can result in broken JS output (undeclared variables). |
@gaearon The function is missing the arguments What I was trying to say was that we shouldn't be serializing the mock We should write some test cases for these bugs too. |
Makes sense, thanks. Yeah I wasn't saying it's related to this issue in particular, I just wanted to point out this seems like a bug in Prepack regardless of this implementation. |
Fixes lint error
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.
@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Needed for our www class transform.
I verified
extends
works. However I get weird results with inheritance.Input: https://gist.github.com/gaearon/f70a187badf877e3d29c49252471686d
Output without #1348: (crashes)
Output with #1348: https://gist.github.com/gaearon/3c60fce62a354b3571618704b51aeb2a
(note it uses undefined
props
variable).