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

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 12, 2016
2 parents 8b61cfb + 9897ce7 commit 4d0fa37
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: node_js
node_js:
- 'stable'
- '0.12'
- '6'
- '4'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ rollup.rollup({
...,
plugins: [
babel({
plugins: ['external-helpers-2'],
plugins: ['external-helpers'],
externalHelpers: true
})
]
Expand Down
3 changes: 2 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ init:
environment:
matrix:
# node.js
- nodejs_version: 0.12
- nodejs_version: 4
- nodejs_version: 6
- nodejs_version: stable

install:
- ps: Install-Product node $env:nodejs_version
Expand Down
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"version": "2.6.1",
"description": "Seamless integration between Rollup and Babel.",
"main": "dist/rollup-plugin-babel.cjs.js",
"jsnext:main": "dist/rollup-plugin-babel.es6.js",
"jsnext:main": "dist/rollup-plugin-babel.es.js",
"files": [
"src",
"dist",
"dist/rollup-plugin-babel.cjs.js",
"dist/rollup-plugin-babel.es.js",
"README"
],
"keywords": [
Expand Down Expand Up @@ -38,13 +39,14 @@
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-runtime": "^6.9.0",
"babel-preset-es2015": "^6.9.0",
"babel-preset-es2015-rollup": "^1.1.1",
"buble": "^0.10.6",
"eslint": "^2.11.1",
"mocha": "^2.5.3",
"rollup": "^0.29.0",
"rollup-plugin-buble": "^0.10.0",
"source-map": "^0.5.6"
"babel-preset-es2015-rollup": "^3.0.0",
"buble": "^0.14.2",
"eslint": "^3.12.0",
"mocha": "^3.2.0",
"rollup": "^0.37.0",
"rollup-plugin-buble": "^0.14.0",
"source-map": "^0.5.6",
"source-map-support": "^0.4.6"
},
"repository": {
"type": "git",
Expand Down
5 changes: 3 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export default {
external: external,
targets: [
{ dest: 'dist/rollup-plugin-babel.cjs.js', format: 'cjs' },
{ dest: 'dist/rollup-plugin-babel.es6.js', format: 'es6' }
]
{ dest: 'dist/rollup-plugin-babel.es.js', format: 'es' }
],
sourceMap: true
};
8 changes: 7 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ export default function babel ( options ) {
if ( options.externalHelpersWhitelist ) externalHelpersWhitelist = options.externalHelpersWhitelist;
delete options.externalHelpersWhitelist;

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

return {
name: 'babel',

options ( options ) {
warn = options.onwarn || warn;
},

resolveId ( id ) {
if ( id === HELPERS ) return id;
},
Expand Down Expand Up @@ -68,7 +74,7 @@ export default function babel ( options ) {
} else {
usedHelpers.forEach( helper => {
if ( inlineHelpers[ helper ] ) {
warnOnce( `The '${helper}' Babel helper is used more than once in your code. It's strongly recommended that you use the "external-helpers" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information` );
warnOnce( warn, `The '${helper}' Babel helper is used more than once in your code. It's strongly recommended that you use the "external-helpers" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information` );
}

inlineHelpers[ helper ] = true;
Expand Down
3 changes: 2 additions & 1 deletion src/preflightCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ export default function preflightCheck ( options, dir ) {
let helpers;

options = assign( {}, options );
delete options.only;
options.filename = join( dir, 'x.js' );

options.plugins = options.plugins ? options.plugins.concat( classes ) : [ classes ];

const check = transform( 'export default class Foo {}', options ).code;

if ( !~check.indexOf( 'export default' ) && !~check.indexOf( 'export { Foo as 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#configuring-babel for more information' );
if ( !~check.indexOf( 'export default' ) && !~check.indexOf( 'export { Foo as default }' ) ) throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' );

if ( ~check.indexOf( 'import _classCallCheck from "babel-runtime' ) ) helpers = RUNTIME;
else if ( ~check.indexOf( 'function _classCallCheck' ) ) helpers = INLINE;
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export function assign ( target, source ) {
}

let warned = {};
export function warnOnce ( msg ) {
export function warnOnce ( warn, msg ) {
if ( warned[ msg ] ) return;
warned[ msg ] = true;
console.warn( msg ); // eslint-disable-line no-console
warn( msg );
}
22 changes: 12 additions & 10 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var rollup = require( 'rollup' );
var SourceMapConsumer = require( 'source-map' ).SourceMapConsumer;
var babelPlugin = require( '..' );

require( 'source-map-support' ).install();

process.chdir( __dirname );

function getLocation ( source, charIndex ) {
Expand All @@ -29,7 +31,6 @@ function getLocation ( source, charIndex ) {

const consoleWarn = console.warn;


describe( 'rollup-plugin-babel', function () {
this.timeout( 15000 );

Expand Down Expand Up @@ -106,17 +107,19 @@ describe( 'rollup-plugin-babel', function () {
entry: 'samples/class/main.js',
plugins: [ babelPlugin() ]
}).then( function ( bundle ) {
var target = 'log';
var generated = bundle.generate({ sourceMap: true });
var smc = new SourceMapConsumer( generated.map );

var loc = getLocation( generated.code, generated.code.indexOf( 'log' ) );
var loc = getLocation( generated.code, generated.code.indexOf( target ) );

var original = smc.originalPositionFor( loc );

assert.deepEqual( original, {
source: path.resolve( 'samples/class/main.js' ).split( path.sep ).join( '/' ),
line: 3,
column: 10,
name: null
name: target
});
});
});
Expand All @@ -137,7 +140,7 @@ describe( 'rollup-plugin-babel', function () {
assert.ok( false, 'promise should not fulfil' );
})
.catch( function ( err ) {
assert.ok( /es2015-rollup/.test( err.message ), 'Expected an error about external helpers or module transform, got "' + err.message + '"' );
assert.ok( /configuring-babel/.test( err.message ), 'Expected an error about external helpers or module transform, got "' + err.message + '"' );
});
});

Expand All @@ -146,7 +149,7 @@ describe( 'rollup-plugin-babel', function () {
entry: 'samples/runtime-helpers/main.js',
plugins: [ babelPlugin({ runtimeHelpers: true }) ],
onwarn: function ( msg ) {
assert.equal( msg, `Treating 'babel-runtime/helpers/classCallCheck' as external dependency` );
assert.equal( msg, 'Treating \'babel-runtime/helpers/classCallCheck\' as external dependency' );
}
}).then( function ( bundle ) {
var cjs = bundle.generate({ format: 'cjs' }).code;
Expand All @@ -159,7 +162,7 @@ describe( 'rollup-plugin-babel', function () {
entry: 'samples/named-function-helper/main.js',
plugins: [ babelPlugin() ],
onwarn: function ( msg ) {
assert.equal( msg, `Treating 'babel-runtime/helpers/classCallCheck' as external dependency` );
assert.equal( msg, 'Treating \'babel-runtime/helpers/classCallCheck\' as external dependency' );
}
}).then( function ( bundle ) {
var cjs = bundle.generate({ format: 'cjs' }).code;
Expand All @@ -176,15 +179,14 @@ describe( 'rollup-plugin-babel', function () {

it( 'warns on duplicated helpers', () => {
let messages = [];
console.warn = msg => messages.push( msg );

return rollup.rollup({
entry: 'samples/duplicated-helpers-warning/main.js',
plugins: [ babelPlugin() ]
plugins: [ babelPlugin() ],
onwarn: msg => messages.push( msg )
}).then( () => {
console.warn = consoleWarn;
assert.deepEqual( messages, [
`The 'classCallCheck' Babel helper is used more than once in your code. It's strongly recommended that you use the "external-helpers" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information`
'The \'classCallCheck\' Babel helper is used more than once in your code. It\'s strongly recommended that you use the "external-helpers" plugin or the "es2015-rollup" preset. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information'
]);
});
});
Expand Down

0 comments on commit 4d0fa37

Please sign in to comment.