
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
babel-plugin-transform-async-to-promises
Advanced tools
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);
});
});
hoist
enabled:function _response$blob(response) {
return _await(response.blob(), URL.createObjectURL);
}
const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), _response$blob);
});
inlineHelpers
enabled: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);
}
}
externalHelpers
enabled:In the normal case, helpers are added to the top of the file for the _async
and _await
functions (as well as others). This can cause bloat in a codebase due to duplication of helper code in every file. To avoid this, enable externalHelpers
and those will be imported instead:
import { _async } from "babel-plugin-transform-async-to-promises/helpers";
import { _await } from "babel-plugin-transform-async-to-promises/helpers";
const fetchAsObjectURL = _async(function(url) {
return _await(fetch(url), function(response) {
return _await(response.blob(), URL.createObjectURL);
});
});
export default fetchAsObjectURL;
async
/await
for
/while
/do
loops (including loops that would exhaust stack if dispatched recursively)switch
statements (including fallthrough and default
cases)try
/catch
break
/continue
statements (on both loops and labeled statements)throw
expressionsarguments
this
Function.length
: async
functions will often return a length of 0 (when the _async
wrapper is used)topLevelAwait
option to return
when using SystemJS.eval
: impossible to support without deep hooks into the runtimeFunction.name
: rewrite pass removes function name instrumentationnew AsyncFunction(...)
: impossible to support without shipping babel and the plugin in the outputThis package transforms async/await syntax into generator functions. While it also aims to provide compatibility for environments that do not support async/await, it uses generator functions instead of Promises, which can result in different performance characteristics and code structure.
This package allows Babel to parse async functions but does not transform them. It is useful if you want to use async/await syntax in your code but rely on another tool or runtime to handle the actual transformation or execution.
This package transforms generator functions and async functions to use regenerator runtime. It provides a broader transformation capability, including both async/await and generator functions, but may introduce additional runtime dependencies.
FAQs
Transform async/await to promise chains
The npm package babel-plugin-transform-async-to-promises receives a total of 267,765 weekly downloads. As such, babel-plugin-transform-async-to-promises popularity was classified as popular.
We found that babel-plugin-transform-async-to-promises demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.