diff --git a/lib/constants.js b/lib/constants.js index 27b3e20..1e2d8d9 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -85,6 +85,11 @@ const POSIX_REGEX_SOURCE = { xdigit: 'A-Fa-f0-9' }; +const REPLACEMENTS = Object.create(null); +REPLACEMENTS['***'] = '*'; +REPLACEMENTS['**/**'] = '**'; +REPLACEMENTS['**/**/**'] = '**'; + module.exports = { MAX_LENGTH: 1024 * 64, POSIX_REGEX_SOURCE, @@ -98,11 +103,7 @@ module.exports = { REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g, // Replace globs with equivalent patterns to reduce parsing time. - REPLACEMENTS: { - '***': '*', - '**/**': '**', - '**/**/**': '**' - }, + REPLACEMENTS: REPLACEMENTS, // Digits CHAR_0: 48, /* 0 */ diff --git a/test/api.picomatch.js b/test/api.picomatch.js index 2fe67cf..24a554d 100644 --- a/test/api.picomatch.js +++ b/test/api.picomatch.js @@ -2,7 +2,7 @@ const assert = require('assert'); const picomatch = require('..'); -const { isMatch } = picomatch; +const { isMatch, makeRe } = picomatch; const assertTokens = (actual, expected) => { const keyValuePairs = actual.map(token => [token.type, token.value]); @@ -378,4 +378,10 @@ describe('picomatch', () => { }); }); }); + + describe('makeRe', () => { + it('should work when supplying constructor as input', () => { + assert.strictEqual(makeRe('constructor').source, '^(?:^(?:constructor)$)$'); + }); + }); });