Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 */
Expand Down
8 changes: 7 additions & 1 deletion test/api.picomatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -378,4 +378,10 @@ describe('picomatch', () => {
});
});
});

describe('makeRe', () => {
it('should work when supplying constructor as input', () => {
assert.strictEqual(makeRe('constructor').source, '^(?:^(?:constructor)$)$');
});
});
});