Babel plugin to transform async functions containing await expressions to the equivalent chain of Promise calls with use of minimal helper functions.
async function fetchAsObjectURL(url) {
const response = await fetch(url);
const blob = await response.blob();
return URL.createObjectURL(blob);
}const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), function(response) {
return _await(response.blob(), URL.createObjectURL);
});
});function _response$blob(response) {
return _await(response.blob(), URL.createObjectURL);
}
const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), _response$blob);
});const fetchAsObjectURL = function(url) {
try {
return Promise.resolve(fetch(url)).then(function(response) {
return Promise.resolve(response.blob()).then(URL.createObjectURL);
});
} catch(e) {
return Promise.reject(e);
}
}async/awaitfor/while/doloops (including loops that would exhaust stack if dispatched recursively)switchstatements (including fallthrough anddefaultcases)- conditional expressions
- logical expressions
try/catchbreak/continuestatements (on both loops and labeled statements)throwexpressions- Function hoisting
- Variable hoisting
- Arrow functions
- Methods
argumentsthis- Proper member dereference order of operations
- Standards-compliant event loop scheduling
Function.length:asyncfunctions will often return a length of 0 (when the_asyncwrapper is used)
eval: impossible to support without deep hooks into the runtime- Async generator functions: not implemented or planned
Function.name: rewrite pass removes function name instrumentationnew AsyncFunction(...): impossible to support without shipping babel and the plugin in the output