How to use the @babel/preset-env/lib/targets-parser function in @babel/preset-env

To help you get started, we’ve selected a few @babel/preset-env examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sebastian-software / babel-preset-edge / src / parts / async.js View on Github external
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)
  }
}
github sebastian-software / babel-preset-edge / src / getEnvTargets.js View on Github external
// This behavior reduces the amount a transpilations a bit when working in pure NodeJS environments
      envTargets.node = "10.13.0"
    }
  } else {
    throw new Error("Invalid transpile configuration!")
  }

  // We fill the browsers field if not defined with an empty array so that
  // the browserslist config is properly ignored when transpilation if passed over.
  if (envTargets.node != null && envTargets.browsers == null) {
    envTargets.browsers = []
  }

  if (options.debug) {
    console.log("- Computed Targets:", envTargets)
    console.log("- Final Targets:", getTargets(envTargets))
  }

  return envTargets
}