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
Async function hoisting is overly aggressive #6206
Comments
Hey @houli! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Currently this is the suggested approach: #4487 (comment) We don't really have any way of knowing where to put the function. We could technically special-case The best we could do is leave it as a function declaration and just rewrite it to remove the |
Fixes #8 Requires babel-polyfill to be imported before the main file due to aggressing async function hoisting babel/babel#6206
This should be fixed in 7.x |
Bug Report
The transformation of
async function x
tovar x = function () { var _ref = _asyncToGenerator(...
means that x must be hoisted. This is to avoid issues wherex
is referred to before it is defined. The problem is that the hoisting is overly aggressive and async functions appear before other statements in the code such as requires and imports. This is immediately noticeable if you try to write an async function in a module that sets upbabel-polyfill
/regenerator-runtime
as a global using a side-effectful require/import. The result is broken code that fails asregeneratorRuntime
will be undefined.Input Code
Example using
import
Example using
require
Babel Configuration (.babelrc, package.json, cli command)
Expected Behavior
The order of statements is preserved in a way that async functions are hoisted only as high as they need to be.
Current Behavior
Async functions are hoisted to the top of the module including to the point where they break the semantics of the
import
statement by appearing before it.Your Environment
The text was updated successfully, but these errors were encountered: