How to use core-js-compat - 4 common examples

To help you get started, we’ve selected a few core-js-compat 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 babel / babel / packages / babel-preset-env / src / polyfills / corejs3 / entry-plugin.js View on Github external
export default function(
  _: any,
  { corejs, include, exclude, polyfillTargets, debug }: InternalPluginOptions,
) {
  const polyfills = filterItems(
    corejs3Polyfills,
    include,
    exclude,
    polyfillTargets,
    null,
  );

  const available = new Set(getModulesListForTargetVersion(corejs.version));

  function shouldReplace(source, modules) {
    if (!modules) return false;
    if (
      // Don't replace an import with itself to avoid an infinite loop
      modules.length === 1 &&
      polyfills.has(modules[0]) &&
      available.has(modules[0]) &&
      getModulePath(modules[0]) === source
    ) {
      return false;
    }
    return true;
  }

  const isPolyfillImport = {
github babel / babel / packages / babel-preset-env / src / polyfills / corejs3 / usage-plugin.js View on Github external
debug,
  }: InternalPluginOptions,
) {
  const polyfills = filterItems(
    proposals
      ? corejs3Polyfills
      : shippedProposals
      ? corejs3PolyfillsWithShippedProposals
      : corejs3PolyfillsWithoutProposals,
    include,
    exclude,
    polyfillTargets,
    null,
  );

  const available = new Set(getModulesListForTargetVersion(corejs.version));

  function resolveKey(path, computed) {
    const { node, parent, scope } = path;
    if (path.isStringLiteral()) return node.value;
    const { name } = node;
    const isIdentifier = path.isIdentifier();
    if (isIdentifier && !(computed || parent.computed)) return name;
    if (!isIdentifier || scope.getBindingIdentifier(name)) {
      const { value } = path.evaluate();
      if (typeof value === "string") return value;
    }
  }

  function resolveSource(path) {
    const { node, scope } = path;
    let builtIn, instanceType;
github zloirock / core-js / packages / core-js-builder / index.js View on Github external
const set = new Set();

  function filter(method, list) {
    for (const ns of list) {
      for (const name of modulesList) {
        if (name === ns || name.startsWith(`${ ns }.`)) {
          set[method](name);
        }
      }
    }
  }

  filter('add', modules);
  filter('delete', blacklist);

  modules = modulesList.filter(it => set.has(it));

  if (targets) modules = compat({ targets, filter: modules }).list;

  const tempFileName = `core-js-${ Math.random().toString(36).slice(2) }.js`;
  const tempFile = join(tmpdir, tempFileName);

  await webpack({
    mode: 'none',
    node: {
      global: false,
      process: false,
      setImmediate: false,
    },
    entry: modules.map(it => require.resolve(`core-js/modules/${ it }`)),
    output: {
      path: tmpdir,
github zloirock / core-js / packages / core-js-builder / index.js View on Github external
module.exports = async function ({ blacklist = [], modules = modulesList.slice(), targets, filename } = {}) {
  const set = new Set();

  function filter(method, list) {
    for (const ns of list) {
      for (const name of modulesList) {
        if (name === ns || name.startsWith(`${ ns }.`)) {
          set[method](name);
        }
      }
    }
  }

  filter('add', modules);
  filter('delete', blacklist);

  modules = modulesList.filter(it => set.has(it));

core-js-compat

core-js compat

MIT
Latest version published 2 months ago

Package Health Score

94 / 100
Full package analysis

Similar packages