Skip to content

Commit

Permalink
Use regex.test(str) instead of str.match(regex) (#152)
Browse files Browse the repository at this point in the history
This method returns a boolean so it should be faster and more memory
efficient.

In order to make this work, I needed to remove the global flag from the
regexes, because that makes the regexes mutable when run multiple times.
Since these are only used to test for any match, and not for any
matching groups or in any other way, we don't need this flag.
  • Loading branch information
lencioni committed Sep 18, 2018
1 parent 4bca1e1 commit c7987f4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/index.js
Expand Up @@ -19,7 +19,7 @@ function isPathReactClass(path, globalOptions) {
return true
}

if (node && matchers && node.name.match(matchers)) {
if (node && matchers && matchers.test(node.name)) {
return true
}

Expand Down Expand Up @@ -97,13 +97,13 @@ export default function(api) {
let classNameMatchers

if (state.opts.ignoreFilenames) {
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'gi')
ignoreFilenames = new RegExp(state.opts.ignoreFilenames.join('|'), 'i')
} else {
ignoreFilenames = undefined
}

if (state.opts.classNameMatchers) {
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'), 'g')
classNameMatchers = new RegExp(state.opts.classNameMatchers.join('|'))
} else {
classNameMatchers = undefined
}
Expand Down
6 changes: 5 additions & 1 deletion src/remove.js
Expand Up @@ -12,7 +12,11 @@ function isInside(scope, regex) {
return true
}

return filename.match(regex) !== null
if (!regex) {
return false
}

return regex.test(filename)
}

// Remove a specific path.
Expand Down

0 comments on commit c7987f4

Please sign in to comment.