Package Exports
- babel-plugin-transform-async-to-promises
- babel-plugin-transform-async-to-promises/helpers
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (babel-plugin-transform-async-to-promises) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
babel-plugin-transform-async-to-promises
Babel plugin to transform async
functions containing await
expressions to the equivalent chain of Promise
calls with use of minimal helper functions.
Input:
async function fetchAsObjectURL(url) {
const response = await fetch(url);
const blob = await response.blob();
return URL.createObjectURL(blob);
}
Output:
const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), function(response) {
return _await(response.blob(), function(blob) {
return URL.createObjectURL(blob);
});
});
});
Output with hoist
enabled:
function _response$blob(response) {
return _await(response.blob(), _URL$createObjectURL);
}
function _URL$createObjectURL = function(blob) {
return URL.createObjectURL(blob);
}
const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), _response$blob);
});
Output with inlineHelpers
enabled:
const fetchAsObjectURL = function(url) {
try {
return Promise.resolve(fetch(url)).then(function(response) {
return Promise.resolve(response.blob()).then(function(blob){
return URL.createObjectURL(blob);
});
});
} catch(e) {
return Promise.reject(e);
}
}
JavaScript Language Features
Full Support
async
/await
for
/while
/do
loops (including loops that would exhaust stack if dispatched recursively)switch
statements (including fallthrough anddefault
cases)- conditional expressions
- logical expressions
try
/catch
break
/continue
statements (on both loops and labeled statements)throw
expressions- Function hoisting
- Variable hoisting
- Arrow functions
- Methods
arguments
this
- Proper member dereference order of operations
- Standards-compliant event loop scheduling
Partial Support
Function.length
:async
functions will often return a length of 0 (when the_async
wrapper is used)
No support
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