You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
super is not working inside methods marked async (T6895) #3930
Reacted by Wout Mertens, Chris Watts, Tiago Nunes, Yvann Boucher, Seba Kerckhof, Paul Sanchez, Andy Edwards, Anand Prajapati, Aymeric Beaumet, Bart Van Remortele and 5 more
Comment originally made by Paul Sanchez (basicdays)
I ran into this as well when upgrading from Babel 5 to 6. Seems the issue is the output is creating a generator but keeping the original super syntax. Generators don't have the ability to call super unfortunately. I'm guessing there will have to be a transformer to just transpile super references within just async methods?
Add handling for this case to babel-helper-remap-async-to-generator to use babel-helper-replace-supers
Add general support to the internal shadow-functions.js transform so that at the same time we remap this to point at parent scopes, we do the same for super, since super and this are tied to the same function context.
For those coming across this, my recommendation for now would be to manually enable transform-es2015-classes which obviously isn't ideal, but does the job.
Would also like to understand the state of this issue. Did we agree on the solution path? If so and with some general pointers, I can try to send a PR to address this.
TBH, I'm a bit afraid of using this in production :/
FYI, I wanted to stop using babel-preset-stage-0 in favor of specific transforms to be able to not transpile async functions in Node when not necessary (to help with debugging). (See vatesfr/xo-server#536)
Unfortunately it breaks on Node 6.
If you want to make it part of preset-env as a temporary fix for users on Babel 6, I'd be happy to contribute it. It's not ideal that preset-env fails to generate working code when targeting Node 6 at the moment, so I think it would be great to either back port the fix from Babel 7, or add something like the above plugin to preset-env when compiling async functions but not classes.
Reacted by Adam Biggs, Aaron Wang and Anatoli Fridlund Belski
Activity
babel-bot commentedon Jan 8, 2016
I ran into this as well when upgrading from Babel 5 to 6. Seems the issue is the output is creating a generator but keeping the original
supersyntax. Generators don't have the ability to call super unfortunately. I'm guessing there will have to be a transformer to just transpile super references within just async methods?I have some example input/output code here: https://gist.github.com/psanchez-alertmd/5ffa9ff5e4653d9f93d8
babel-bot commentedon Jan 8, 2016
Oh, this was created with
babel6.4.0,babel-preset-es2015-node42.0.2, andbabel-preset-stage-3v6.3.13. Here are the plugins it was pulling in: https://github.com/jbach/babel-preset-es2015-node4/blob/master/index.jsbabel-bot commentedon Mar 7, 2016
This is a tough one. We've got two options I see.
babel-helper-remap-async-to-generatorto usebabel-helper-replace-supersshadow-functions.jstransform so that at the same time we remapthisto point at parent scopes, we do the same forsuper, sincesuperandthisare tied to the same function context.babel-bot commentedon Mar 13, 2016
Ended up going with #2.
#3423
loganfsmyth commentedon Sep 24, 2016
For those coming across this, my recommendation for now would be to manually enable
transform-es2015-classeswhich obviously isn't ideal, but does the job.matildayipan commentedon Oct 4, 2016
I have enabled transform-es2015-classes in .babelrc:
still have the same error
christensson commentedon Oct 14, 2016
@matildayipan If you are accessing super from within an async method, you still need to enable the async-function transformation:
develar commentedon Oct 19, 2016
Workaround:
SuperClass.prototype.method.call(this): http://madole.xyz/babel-plugin-transform-async-to-module-method-gotcha/alexeyraspopov commentedon Nov 19, 2016
Any updates on this?
tnunes commentedon Jan 16, 2017
Would also like to understand the state of this issue. Did we agree on the solution path? If so and with some general pointers, I can try to send a PR to address this.
Add a temporary workaround for a Babel's bug that forbids the usage o…
MikeKovarik commentedon Feb 23, 2017
+1
uscengineer commentedon Mar 9, 2017
@rightaway for me what worked was BaseClass.prototype.myfunction. Example:
xtuc commentedon Apr 26, 2017
Related issue babel/babel-preset-env#308 @julien-f
julien-f commentedon Jun 20, 2017
@loganfsmyth Has it been fixed by #5677?
Any plan to release this fix soon?
Thanks :)
hzoo commentedon Jun 20, 2017
You'll need to upgrade everything to v7.0.0-alpha.12 (and it might not be compatible with various packages outside of this monorepo)
julien-f commentedon Jun 20, 2017
TBH, I'm a bit afraid of using this in production :/
FYI, I wanted to stop using babel-preset-stage-0 in favor of specific transforms to be able to not transpile async functions in Node when not necessary (to help with debugging). (See vatesfr/xo-server#536)
Unfortunately it breaks on Node 6.
upgrade
devongovett commentedon Feb 12, 2018
Just wrote a simple plugin for Babel 6 to work around this issue here: https://github.com/devongovett/babel-plugin-transform-async-super. It only compiles super expressions inside async functions, so you could use it when you aren't already compiling classes to ES5 (e.g. Node 6).
If you want to make it part of preset-env as a temporary fix for users on Babel 6, I'd be happy to contribute it. It's not ideal that preset-env fails to generate working code when targeting Node 6 at the moment, so I think it would be great to either back port the fix from Babel 7, or add something like the above plugin to preset-env when compiling async functions but not classes.
bug: babel6 doesn't support `super.[method]` inside of async function