-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unexpected super() return value when subclassing ES5 ctor function #4663
Labels
Comments
sethbrenith
added a commit
to sethbrenith/ChakraCore
that referenced
this issue
Feb 12, 2018
Hi guys, I still have this issue on Edge/17.17134 Is this bug back or the fix not shipped yet? |
Thank you for the quick answer @sethbrenith 👍 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In classes that extend ES5 constructor functions, the value returned by a call to
super()
within the constructor does not match the value ofthis
.It seems that the return value of the base constructor function is used as the return value of
super()
, unless the constructor function returns an object.Chrome, Firefox, and Safari do not throw in any of these cases.
I found this because code similar to this is generated by Babel when transforming async arrow function properties that reference
this
. The async function transform uses a generator function, and since generator arrow functions aren't yet available, the generator function closes over the return value ofsuper()
for use in place ofthis
in the former arrow function.React.Component
is distributed as an ES5 constructor function, so my React components that use async arrow function properties all produce this problem code --React.Component
has no return statement, so in my casesuper()
returnsundefined
.Here's some example code that causes Babel to produce the problem code: https://babeljs.io/repl/#?babili=false&browsers=&build=&builtIns=false&code_lz=GYVwdgxgLglg9mABAYTgWwA4IKZigCgEoBvAXwChyIAbAQwGd7EB1GAEwHNspFsAPKLjZNUmHHkTFyiRAEg-iALyIA5AAts1anBUBuaTMRs4AZXTc1MMByWIGAT0iIiSgHySDhwxAT041bAA6bQ58KEt6QL5CT0QKCnIwbAB3FnYuAkJA4zM0CytQwl0gA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=true&fileSize=false&lineWrap=false&presets=es2017%2Cstage-2&prettier=false&targets=&version=6.26.0&envVersion=
Interestingly, the TypeScript compiler seems to avoid the problem (at least when the constructor function returns
undefined
) by usingsuper() || this
to capture the value used in closures. This was apparently added along with a change to support override values returned by base class constructors in this PR.Tested in Edge 15 and 16. Apologies if this doesn't repro on ChakraCore's master, or if this is the wrong place to report.
The text was updated successfully, but these errors were encountered: