diff --git a/packages/node-resolve/src/index.js b/packages/node-resolve/src/index.js index a675247aa..7e0614f58 100644 --- a/packages/node-resolve/src/index.js +++ b/packages/node-resolve/src/index.js @@ -292,7 +292,7 @@ export function nodeResolve(opts = {}) { return importee; } // ignore IDs with null character, these belong to other plugins - if (/\0/.test(importee)) return null; + if (importee && importee.includes('\0')) return null; const { custom = {} } = resolveOptions; const { 'node-resolve': { resolved: alreadyResolved } = {} } = custom; @@ -300,7 +300,7 @@ export function nodeResolve(opts = {}) { return alreadyResolved; } - if (/\0/.test(importer)) { + if (importer && importer.includes('\0')) { importer = undefined; } diff --git a/packages/pluginutils/src/attachScopes.ts b/packages/pluginutils/src/attachScopes.ts index fc6392ddb..b8a33a8ea 100755 --- a/packages/pluginutils/src/attachScopes.ts +++ b/packages/pluginutils/src/attachScopes.ts @@ -82,7 +82,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc let newScope: AttachedScope | undefined; // create new function scope - if (/Function/.test(node.type)) { + if (node.type.includes('Function')) { const func = node as estree.Function; newScope = new Scope({ parent: scope, @@ -106,7 +106,7 @@ const attachScopes: AttachScopes = function attachScopes(ast, propertyName = 'sc } // create new block scope - if (node.type === 'BlockStatement' && !/Function/.test(parent.type)) { + if (node.type === 'BlockStatement' && !parent.type.includes('Function')) { newScope = new Scope({ parent: scope, block: true diff --git a/packages/pluginutils/src/createFilter.ts b/packages/pluginutils/src/createFilter.ts index 9f2f093f6..86f9d3be5 100755 --- a/packages/pluginutils/src/createFilter.ts +++ b/packages/pluginutils/src/createFilter.ts @@ -54,11 +54,17 @@ const createFilter: CreateFilter = function createFilter(include?, exclude?, opt for (let i = 0; i < excludeMatchers.length; ++i) { const matcher = excludeMatchers[i]; + if (matcher instanceof RegExp) { + matcher.lastIndex = 0; + } if (matcher.test(pathId)) return false; } for (let i = 0; i < includeMatchers.length; ++i) { const matcher = includeMatchers[i]; + if (matcher instanceof RegExp) { + matcher.lastIndex = 0; + } if (matcher.test(pathId)) return true; } diff --git a/packages/pluginutils/test/createFilter.ts b/packages/pluginutils/test/createFilter.ts index 234bbc205..66116b5a4 100755 --- a/packages/pluginutils/test/createFilter.ts +++ b/packages/pluginutils/test/createFilter.ts @@ -175,3 +175,27 @@ test('normalizes path when pattern has resolution base', (t) => { t.truthy(filterPosix(resolve('test/a'))); t.truthy(filterWin(resolve('test/a'))); }); + +test('pass a regular expression to the include parameter', (t) => { + const filter = createFilter([/zxcvbnmasdfg/]); + t.truthy(filter(resolve('zxcvbnmasdfg'))); + t.falsy(filter(resolve('zxcvbnmasdfe'))); +}); + +test('pass a regular expression to the include parameter with g flag', (t) => { + const filter = createFilter([/zxcvbnmasdfg/g]); + t.truthy(filter(resolve('zxcvbnmasdfg'))); + t.truthy(filter(resolve('zxcvbnmasdfg'))); +}); + +test('pass a regular expression to the exclude parameter', (t) => { + const filter = createFilter(null, [/zxcvbnmasdfg/]); + t.falsy(filter(resolve('zxcvbnmasdfg'))); + t.truthy(filter(resolve('zxcvbnmasdfe'))); +}); + +test('pass a regular expression to the exclude parameter with g flag', (t) => { + const filter = createFilter(null, [/zxcvbnmasdfg/g]); + t.falsy(filter(resolve('zxcvbnmasdfg'))); + t.falsy(filter(resolve('zxcvbnmasdfg'))); +});