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

Commit

Permalink
Fix preflightChecks for ignored files
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Sep 17, 2018
1 parent 21bdef4 commit 22f1b81
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ export default function babel ( options ) {
if ( !filter( id ) ) return null;
if ( id === HELPERS ) return null;

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

if (!helpers) {
return { code };
}

if ( helpers === EXTERNAL && !externalHelpers ) {
warnOnce( this, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' );
Expand Down
20 changes: 13 additions & 7 deletions src/preflightCheck.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { join } from 'path';
import { join, dirname } from 'path';
import { transform } from '@babel/core';
import { INLINE, RUNTIME, EXTERNAL } from './constants.js';

Expand Down Expand Up @@ -28,18 +28,24 @@ function fallbackClassTransform () {
export default function createPreflightCheck () {
let preflightCheckResults = {};

return ( ctx, options, dir ) => {
if ( !preflightCheckResults[ dir ] ) {
return ( ctx, options, file ) => {
if ( preflightCheckResults[ file ] === undefined ) {
let helpers;

options = Object.assign( {}, options );
delete options.only;
delete options.ignore;

options.filename = join( dir, 'x.js' );
options.filename = join( dirname( file ), 'x.js' );

const inputCode = 'class Foo extends Bar {};\nexport default Foo;';
let check = transform( inputCode, options ).code;
const transformed = transform( inputCode, options );

if (!transformed) {
return (preflightCheckResults[ file ] = null);
}

let check = transformed.code;

if ( ~check.indexOf('class ') ) {
options.plugins = (options.plugins || []).concat( fallbackClassTransform );
Expand All @@ -61,9 +67,9 @@ export default function createPreflightCheck () {
ctx.error( UNEXPECTED_ERROR );
}

preflightCheckResults[ dir ] = helpers;
preflightCheckResults[ file ] = helpers;
}

return preflightCheckResults[ dir ];
return preflightCheckResults[ file ];
};
}

0 comments on commit 22f1b81

Please sign in to comment.