From 59a515a1e5fbd1dde0048bb46875f2a115e50c8f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Sat, 28 Nov 2015 06:39:49 -0500 Subject: [PATCH] =?UTF-8?q?run=20preflight=20check=20per=20file=20?= =?UTF-8?q?=E2=80=93=20fixes=20#16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/rollup-plugin-babel/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/rollup-plugin-babel/index.js b/packages/rollup-plugin-babel/index.js index 1178b55e6..7f5387c6c 100644 --- a/packages/rollup-plugin-babel/index.js +++ b/packages/rollup-plugin-babel/index.js @@ -3,6 +3,12 @@ var babel = require( 'babel-core' ); var createFilter = require( 'rollup-pluginutils' ).createFilter; var assign = require( 'object-assign' ); +function preflightCheck ( localOpts ) { + var check = babel.transform( 'export default class Foo {}', localOpts ).code; + if ( ~check.indexOf( 'function _classCallCheck' ) ) throw new Error( 'External helpers are not enabled. Please add the "external-helpers-2" plugin or use the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#TK for more information' ); + if ( !~check.indexOf( 'export default' ) ) throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. If you\'re using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#TK for more information' ); +} + module.exports = function ( options ) { options = assign( {}, options || {} ); var usedHelpers = []; @@ -12,11 +18,6 @@ module.exports = function ( options ) { delete options.include; delete options.exclude; - // preflight check - var check = babel.transform( 'export default class Foo {}', assign({ filename: path.resolve( 'test.js' ) }, options ) ).code; - if ( ~check.indexOf( 'function _classCallCheck' ) ) throw new Error( 'External helpers are not enabled. Please add the "external-helpers-2" plugin or use the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#TK for more information' ); - if ( !~check.indexOf( 'export default' ) ) throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. If you\'re using the "es2015" preset, consider using "es2015-rollup" instead. See https://github.com/rollup/rollup-plugin-babel#TK for more information' ); - if ( options.sourceMap !== false ) options.sourceMaps = true; if ( options.sourceMaps !== false ) options.sourceMaps = true; delete options.sourceMap; @@ -25,7 +26,10 @@ module.exports = function ( options ) { transform: function ( code, id ) { if ( !filter( id ) ) return null; - var transformed = babel.transform( code, assign({ filename: id }, options ) ); + var localOpts = assign({ filename: id }, options ); + preflightCheck( localOpts ); + + var transformed = babel.transform( code, localOpts ); transformed.metadata.usedHelpers.forEach( function ( helper ) { if ( !~usedHelpers.indexOf( helper ) ) usedHelpers.push( helper );