From dcb0f91f383513d0e5f67f849b4ecb15eaf81c5c Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Mon, 13 Mar 2017 16:24:06 -0700 Subject: [PATCH] Ignore files if they don't match only OR they do match ignore. --- packages/babel-core/src/util.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/babel-core/src/util.js b/packages/babel-core/src/util.js index 674f8abc5d..51d42086c0 100644 --- a/packages/babel-core/src/util.js +++ b/packages/babel-core/src/util.js @@ -126,20 +126,22 @@ export function booleanify(val: any): boolean | any { export function shouldIgnore( filename: string, - ignore: Array = [], + ignore: Array, only?: Array, ): boolean { filename = filename.replace(/\\/g, "/"); + if (ignore && ignore.length) { + for (const pattern of ignore) { + if (matchesPattern(pattern, filename)) return true; + } + } + if (only) { for (const pattern of only) { - if (_shouldIgnore(pattern, filename)) return false; + if (matchesPattern(pattern, filename)) return false; } return true; - } else if (ignore.length) { - for (const pattern of ignore) { - if (_shouldIgnore(pattern, filename)) return true; - } } return false; @@ -150,7 +152,7 @@ export function shouldIgnore( * Otherwise returns result of matching pattern Regex with filename. */ -function _shouldIgnore(pattern: Function | RegExp, filename: string) { +function matchesPattern(pattern: Function | RegExp, filename: string) { if (typeof pattern === "function") { return pattern(filename); } else {