Browse Source

Cut options validation into method

legacy-quote-reserved-properties
Vladimir Smyshlyaev 8 years ago
parent
commit
daaaeafc75
  1. 18
      src/rollup.js
  2. 6
      src/utils/validateKeys.js

18
src/rollup.js

@ -39,20 +39,24 @@ const ALLOWED_KEYS = [
'useStrict' 'useStrict'
]; ];
export function rollup ( options ) { function checkOptions ( options ) {
if ( !options || !options.entry ) { if ( !options || !options.entry ) {
return Promise.reject( new Error( 'You must supply options.entry to rollup' ) ); return new Error( 'You must supply options.entry to rollup' );
} }
if ( options.transform || options.load || options.resolveId || options.resolveExternal ) { if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
return Promise.reject( new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' ) ); return new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' );
} }
const error = validateKeys( options, ALLOWED_KEYS ); const error = validateKeys( keys(options), ALLOWED_KEYS );
if ( error ) return error;
if ( error ) { return null;
return Promise.reject( error ); }
}
export function rollup ( options ) {
const error = checkOptions ( options );
if ( error ) return Promise.reject( error );
const bundle = new Bundle( options ); const bundle = new Bundle( options );

6
src/utils/validateKeys.js

@ -1,8 +1,4 @@
import { keys } from './object.js'; export default function validateKeys ( actualKeys, allowedKeys ) {
export default function validateKeys ( object, allowedKeys ) {
const actualKeys = keys( object );
let i = actualKeys.length; let i = actualKeys.length;
while ( i-- ) { while ( i-- ) {

Loading…
Cancel
Save