Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Commit

Permalink
Merge pull request #92 from sorgloomer/master
Browse files Browse the repository at this point in the history
Added externalHelpersWhitelist option
  • Loading branch information
Rich-Harris committed Dec 12, 2016
2 parents 9897ce7 + 4d0fa37 commit 47b8528
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -39,7 +39,11 @@ rollup({
}).then(...)
```

All options are as per the [Babel documentation](https://babeljs.io/), except `options.externalHelpers` (a boolean value indicating whether to bundle in the babel helpers), `options.include` and `options.exclude` (each a minimatch pattern, or array of minimatch patterns), which determine which files are transpiled by Babel (by default, all files are transpiled).
All options are as per the [Babel documentation](https://babeljs.io/), except the following:

* `options.externalHelpers`: a boolean value indicating whether to bundle in the babel helpers
* `options.include` and `options.exclude`: each a minimatch pattern, or array of minimatch patterns, which determine which files are transpiled by Babel (by default, all files are transpiled)
* `options.externalHelpersWhitelist`: an array which gives explicit control over which babelHelper functions are allowed in the bundle (by default, every helper is allowed)

Babel will respect `.babelrc` files – this is generally the best place to put your configuration.

Expand Down
8 changes: 6 additions & 2 deletions src/index.js
Expand Up @@ -26,8 +26,12 @@ export default function babel ( options ) {
if ( options.externalHelpers ) externalHelpers = true;
delete options.externalHelpers;

let externalHelpersWhitelist = null;
if ( options.externalHelpersWhitelist ) externalHelpersWhitelist = options.externalHelpersWhitelist;
delete options.externalHelpersWhitelist;

let warn = msg => console.warn(msg); // eslint-disable-line no-console

return {
name: 'babel',

Expand All @@ -43,7 +47,7 @@ export default function babel ( options ) {
if ( id === HELPERS ) {
const pattern = new RegExp( `babelHelpers\\.(${keywordHelpers.join('|')})`, 'g' );

const helpers = buildExternalHelpers( null, 'var' )
const helpers = buildExternalHelpers( externalHelpersWhitelist, 'var' )
.replace( pattern, 'var _$1' )
.replace( /^babelHelpers\./gm, 'export var ' ) +
`\n\nexport { ${keywordHelpers.map( word => `_${word} as ${word}`).join( ', ')} }`;
Expand Down

0 comments on commit 47b8528

Please sign in to comment.