Skip to content

Commit

Permalink
Merge branch 'option-cleanup'
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Apr 11, 2020
1 parent 77d098c commit d5465fd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
5 changes: 4 additions & 1 deletion packages/rollup-plugin-babel/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 6
"ecmaVersion": 2018,
"ecmaFeatures": {
"spread": true
}
}
}
2 changes: 1 addition & 1 deletion packages/rollup-plugin-babel/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var external = externalDeps.concat(nodeDeps);

export default {
input: 'src/index.js',
plugins: [ buble() ],
plugins: [ buble({ objectAssign: 'Object.assign' }) ],
external: external,
output: [
{
Expand Down
45 changes: 24 additions & 21 deletions packages/rollup-plugin-babel/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,30 @@ import helperPlugin from './helperPlugin.js';
import { warnOnce } from './utils.js';
import { RUNTIME, EXTERNAL, HELPERS } from './constants.js';

export default function babel ( options ) {
options = Object.assign( {}, options || {} );

const filter = createFilter( options.include, options.exclude );
delete options.include;
delete options.exclude;

if ( options.sourceMap !== false ) options.sourceMaps = true;
if ( options.sourceMaps !== false ) options.sourceMaps = true;
delete options.sourceMap;
const unpackOptions = ({
// rollup uses sourcemap, babel uses sourceMaps
// just normalize them here so people don't have to worry about it
sourcemap = true,
sourcemaps = true,
sourceMap = true,
sourceMaps = true,
...rest
} = {}) => ({
sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps,
...rest
});

const runtimeHelpers = options.runtimeHelpers;
delete options.runtimeHelpers;

let externalHelpers;
if ( options.externalHelpers ) externalHelpers = true;
delete options.externalHelpers;
export default function babel ( options ) {
const {
exclude,
externalHelpers,
externalHelpersWhitelist,
include,
runtimeHelpers,
...babelOptions
} = unpackOptions(options);

let externalHelpersWhitelist = null;
if ( options.externalHelpersWhitelist ) externalHelpersWhitelist = options.externalHelpersWhitelist;
delete options.externalHelpersWhitelist;
const filter = createFilter( include, exclude );

return {
name: 'babel',
Expand All @@ -47,15 +50,15 @@ export default function babel ( options ) {
if ( !filter( id ) ) return null;
if ( id === HELPERS ) return null;

const helpers = preflightCheck( this, options, dirname( id ) );
const helpers = preflightCheck( this, babelOptions, dirname( id ) );

if ( helpers === EXTERNAL && !externalHelpers ) {
warnOnce( this, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' );
} else if ( helpers === RUNTIME && !runtimeHelpers ) {
this.error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' );
}

let localOpts = Object.assign({ filename: id }, options);
let localOpts = Object.assign({ filename: id }, babelOptions);

if ( helpers !== RUNTIME ) {
localOpts = Object.assign({}, localOpts, { plugins: (localOpts.plugins || []).concat(helperPlugin) });
Expand Down

0 comments on commit d5465fd

Please sign in to comment.