Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function async(presets, plugins, options) {
// Directly ask babel-preset-env whether we want to use transform-async
// based on currently configured targets. Only if that's the case we
// transform our async/await code. Otherwise we assume it works without
// any transpilation.
const requiresAsync = isPluginRequired(
getTargets(getEnvTargets(options)),
envPlugins["transform-async-to-generator"]
)
// Alternative to Babel Regenerator
// Implements the ES7 keywords async and await using syntax transformation
// to at Promises at compile-time, rather than using generators.
// https://github.com/babel/babel/pull/7076 (NEW: bundled plugin with Babel)
// https://www.npmjs.com/package/fast-async (OLD: separate Babel plugin)
if (requiresAsync) {
plugins.push(fastAsyncPlugin)
}
if (options.debug) {
console.log("- Async/Await Transpilation:", requiresAsync)
}
isPluginRequired(pluginName) {
let targets = this._getTargets();
// if no targets are setup, assume that all plugins are required
if (!targets) { return true; }
const isPluginRequired = require('@babel/preset-env').isPluginRequired;
const pluginList = require('@babel/preset-env/data/plugins');
return isPluginRequired(targets, pluginList[pluginName]);
},
return includes.filter(item => isPluginRequired(builtInTargets, builtInsList[item]))
}
return includes.filter(item => {
return isPluginRequired(builtInTargets, builtInsList[item])
})
}