Skip to content

Easier way to exclude/include (especially builtIns) #6636

@babel-bot

Description

@babel-bot

Issue originally reported by @hzoo in babel/babel-preset-env#132

Context:

Docs for the include/exclude options: https://github.com/babel/babel-preset-env#include
Example: https://github.com/babel/babel-preset-env#example-with-includeexclude


This is a bit more involved, but still basically the gist is changing indexOf to handle regex.

This is mostly for built-ins.

There's a lot of them: https://github.com/babel/babel-preset-env/blob/master/test/fixtures/preset-options/use-builtins-all/expected.js

If we don't use reflect or number or math you currently have to list each one individually since we do an indexOf check

I think we can change it to accept a regex or glob (I think regex) to match multiple of them.

So instead of:

{
  "exclude": [
    "es6.math.acosh",
    "es6.math.asinh",
    "es6.math.atanh",
    "es6.math.cbrt",
    "es6.math.clz32",
    "es6.math.cosh",
    "...etc"
  ]
}

be able to handle something like

{
  "exclude: [/^es6.math.+/]
}

The current logic is https://github.com/babel/babel-preset-env/blob/8eb0c0799cefe3548216a3b2bc372e21dcd3b065/src/index.js#L250-L257
and https://github.com/babel/babel-preset-env/blob/8eb0c0799cefe3548216a3b2bc372e21dcd3b065/src/index.js#L277-L279

    polyfills = Object.keys(builtInsList)
      .filter((builtInName) => isPluginRequired(targets, builtInsList[builtInName]))
      .concat(defaultInclude)
      .filter((plugin) => exclude.builtIns.indexOf(plugin) === -1) // here
      .concat(include.builtIns); // here
  const allTransformations = transformations
  .filter((plugin) => exclude.plugins.indexOf(plugin) === -1) // here
  .concat(include.plugins); // here
  • change indexOf check to handle regex
  • tests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions