babel / babel/minify

Support whitelist option ("include") in babel-plugin-transform-remove-console

Open
#821 1 comment 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
JavaScript
Stars
4.4k
Forks
217
PR merge metrics
No merged PRs in 30d

Description

#### Description

The "babel-plugin-transform-remove-console" [transform](https://github.com/babel/minify/tree/master/packages/babel-plugin-transform-remove-console) currently supports only a blacklist approach to controlling which console statements get removed, via the "exclude" option.

I would like to add a mutually-exclusive, optional "include" option to the transform so that a whitelist approach can be used instead.

A whitelist is a more controlled approach when adding this transform to an existing project since you can finely limit the impact of the transform to only specific, known console functions, which is nice given the sheer number of supported console functions, of which more are being added over time.

I think both whitelist, and blacklist approaches will be commonly required by users.

If the project maintainer thinks this is a good idea, I don't mind taking a crack at it.

#### Code Example

**.babelrc**
```
{
"plugins": [ ["transform-remove-console", { "include": [ "assert", ] }] ]
}
```

**In**

```javascript
console.log("foo");
console.assert(1);
console.error("bar");
```

**Out**

```javascript
console.log("foo");
console.error("bar");
```

Contributor guide

Open the contributing guide

Research direction

Start with packages/babel-plugin-transform-remove-console, linked from the issue, and inspect how the existing "exclude" option controls removal. Use the .babelrc and input/output examples as the behavioral guide: an "include" whitelist should remove only the named console function calls while remaining mutually exclusive with "exclude".

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.