From a76709cabcc5a836b05341a79ad61984dd22a4f1 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Fri, 22 Dec 2017 14:21:17 -0800 Subject: [PATCH] Throw errors for users of 'ignore'/'only' options are passed in, but the filename is unknown. --- .../babel-core/src/config/config-chain.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/babel-core/src/config/config-chain.js b/packages/babel-core/src/config/config-chain.js index 06154c57e5..965273443d 100644 --- a/packages/babel-core/src/config/config-chain.js +++ b/packages/babel-core/src/config/config-chain.js @@ -517,11 +517,14 @@ function shouldIgnore( only: ?IgnoreList, dirname: string, ): boolean { - if (context.filename === null) return false; - // $FlowIgnore - Flow refinements aren't quite smart enough for this :( - const ctx: ConfigContextNamed = context; - if (ignore) { + if (context.filename === null) { + throw new Error( + `Configuration contains ignore checks, but no filename was passed to Babel`, + ); + } + // $FlowIgnore - Flow refinements aren't quite smart enough for this :( + const ctx: ConfigContextNamed = context; if (matchesPatterns(ctx, ignore, dirname)) { debug( "Ignored %o because it matched one of %O from %o", @@ -534,6 +537,14 @@ function shouldIgnore( } if (only) { + if (context.filename === null) { + throw new Error( + `Configuration contains ignore checks, but no filename was passed to Babel`, + ); + } + // $FlowIgnore - Flow refinements aren't quite smart enough for this :( + const ctx: ConfigContextNamed = context; + if (!matchesPatterns(ctx, only, dirname)) { debug( "Ignored %o because it failed to match one of %O from %o",