minimatch 7.4.4 → 7.4.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,296 +0,0 @@
1
- // parse a single path portion
2
- import { parseClass } from './brace-expressions.js';
3
- import { assertValidPattern } from './assert-valid-pattern.js';
4
- const globUnescape = (s) => s.replace(/\\(.)/g, '$1');
5
- const regExpEscape = (s) => s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
6
- // "abc" -> { a:true, b:true, c:true }
7
- const charSet = (s) => s.split('').reduce((set, c) => {
8
- set[c] = true;
9
- return set;
10
- }, {});
11
- const plTypes = {
12
- '!': { open: '(?:(?!(?:', close: '))[^/]*?)' },
13
- '?': { open: '(?:', close: ')?' },
14
- '+': { open: '(?:', close: ')+' },
15
- '*': { open: '(?:', close: ')*' },
16
- '@': { open: '(?:', close: ')' },
17
- };
18
- // characters that need to be escaped in RegExp.
19
- const reSpecials = charSet('().*{}+?[]^$\\!');
20
- // characters that indicate we have to add the pattern start
21
- const addPatternStartSet = charSet('[.(');
22
- // any single thing other than /
23
- // don't need to escape / when using new RegExp()
24
- const qmark = '[^/]';
25
- // * => any number of characters
26
- const star = qmark + '*?';
27
- // TODO: take an offset and length, so we can sub-parse the extglobs
28
- export const parse = (options, pattern, debug) => {
29
- assertValidPattern(pattern);
30
- if (pattern === '')
31
- return '';
32
- let re = '';
33
- let hasMagic = false;
34
- let escaping = false;
35
- // ? => one single character
36
- const patternListStack = [];
37
- const negativeLists = [];
38
- let stateChar = false;
39
- let uflag = false;
40
- let pl;
41
- // . and .. never match anything that doesn't start with .,
42
- // even when options.dot is set. However, if the pattern
43
- // starts with ., then traversal patterns can match.
44
- let dotTravAllowed = pattern.charAt(0) === '.';
45
- let dotFileAllowed = options.dot || dotTravAllowed;
46
- const patternStart = () => dotTravAllowed
47
- ? ''
48
- : dotFileAllowed
49
- ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
50
- : '(?!\\.)';
51
- const subPatternStart = (p) => p.charAt(0) === '.'
52
- ? ''
53
- : options.dot
54
- ? '(?!(?:^|\\/)\\.{1,2}(?:$|\\/))'
55
- : '(?!\\.)';
56
- const clearStateChar = () => {
57
- if (stateChar) {
58
- // we had some state-tracking character
59
- // that wasn't consumed by this pass.
60
- switch (stateChar) {
61
- case '*':
62
- re += star;
63
- hasMagic = true;
64
- break;
65
- case '?':
66
- re += qmark;
67
- hasMagic = true;
68
- break;
69
- default:
70
- re += '\\' + stateChar;
71
- break;
72
- }
73
- debug('clearStateChar %j %j', stateChar, re);
74
- stateChar = false;
75
- }
76
- };
77
- for (let i = 0, c; i < pattern.length && (c = pattern.charAt(i)); i++) {
78
- debug('%s\t%s %s %j', pattern, i, re, c);
79
- // skip over any that are escaped.
80
- if (escaping) {
81
- // completely not allowed, even escaped.
82
- // should be impossible.
83
- /* c8 ignore start */
84
- if (c === '/') {
85
- return false;
86
- }
87
- /* c8 ignore stop */
88
- if (reSpecials[c]) {
89
- re += '\\';
90
- }
91
- re += c;
92
- escaping = false;
93
- continue;
94
- }
95
- switch (c) {
96
- // Should already be path-split by now.
97
- /* c8 ignore start */
98
- case '/': {
99
- return false;
100
- }
101
- /* c8 ignore stop */
102
- case '\\':
103
- clearStateChar();
104
- escaping = true;
105
- continue;
106
- // the various stateChar values
107
- // for the "extglob" stuff.
108
- case '?':
109
- case '*':
110
- case '+':
111
- case '@':
112
- case '!':
113
- debug('%s\t%s %s %j <-- stateChar', pattern, i, re, c);
114
- // if we already have a stateChar, then it means
115
- // that there was something like ** or +? in there.
116
- // Handle the stateChar, then proceed with this one.
117
- debug('call clearStateChar %j', stateChar);
118
- clearStateChar();
119
- stateChar = c;
120
- // if extglob is disabled, then +(asdf|foo) isn't a thing.
121
- // just clear the statechar *now*, rather than even diving into
122
- // the patternList stuff.
123
- if (options.noext)
124
- clearStateChar();
125
- continue;
126
- case '(': {
127
- if (!stateChar) {
128
- re += '\\(';
129
- continue;
130
- }
131
- const plEntry = {
132
- type: stateChar,
133
- start: i - 1,
134
- reStart: re.length,
135
- open: plTypes[stateChar].open,
136
- close: plTypes[stateChar].close,
137
- };
138
- debug(pattern, '\t', plEntry);
139
- patternListStack.push(plEntry);
140
- // negation is (?:(?!(?:js)(?:<rest>))[^/]*)
141
- re += plEntry.open;
142
- // next entry starts with a dot maybe?
143
- if (plEntry.start === 0 && plEntry.type !== '!') {
144
- dotTravAllowed = true;
145
- re += subPatternStart(pattern.slice(i + 1));
146
- }
147
- debug('plType %j %j', stateChar, re);
148
- stateChar = false;
149
- continue;
150
- }
151
- case ')': {
152
- const plEntry = patternListStack[patternListStack.length - 1];
153
- if (!plEntry) {
154
- re += '\\)';
155
- continue;
156
- }
157
- patternListStack.pop();
158
- // closing an extglob
159
- clearStateChar();
160
- hasMagic = true;
161
- pl = plEntry;
162
- // negation is (?:(?!js)[^/]*)
163
- // The others are (?:<pattern>)<type>
164
- re += pl.close;
165
- if (pl.type === '!') {
166
- negativeLists.push(Object.assign(pl, { reEnd: re.length }));
167
- }
168
- continue;
169
- }
170
- case '|': {
171
- const plEntry = patternListStack[patternListStack.length - 1];
172
- if (!plEntry) {
173
- re += '\\|';
174
- continue;
175
- }
176
- clearStateChar();
177
- re += '|';
178
- // next subpattern can start with a dot?
179
- if (plEntry.start === 0 && plEntry.type !== '!') {
180
- dotTravAllowed = true;
181
- re += subPatternStart(pattern.slice(i + 1));
182
- }
183
- continue;
184
- }
185
- // these are mostly the same in regexp and glob
186
- case '[':
187
- // swallow any state-tracking char before the [
188
- clearStateChar();
189
- const [src, needUflag, consumed, magic] = parseClass(pattern, i);
190
- if (consumed) {
191
- re += src;
192
- uflag = uflag || needUflag;
193
- i += consumed - 1;
194
- hasMagic = hasMagic || magic;
195
- }
196
- else {
197
- re += '\\[';
198
- }
199
- continue;
200
- case ']':
201
- re += '\\' + c;
202
- continue;
203
- default:
204
- // swallow any state char that wasn't consumed
205
- clearStateChar();
206
- re += regExpEscape(c);
207
- break;
208
- } // switch
209
- } // for
210
- // handle the case where we had a +( thing at the *end*
211
- // of the pattern.
212
- // each pattern list stack adds 3 chars, and we need to go through
213
- // and escape any | chars that were passed through as-is for the regexp.
214
- // Go through and escape them, taking care not to double-escape any
215
- // | chars that were already escaped.
216
- for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
217
- let tail;
218
- tail = re.slice(pl.reStart + pl.open.length);
219
- debug(pattern, 'setting tail', re, pl);
220
- // maybe some even number of \, then maybe 1 \, followed by a |
221
- tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, (_, $1, $2) => {
222
- if (!$2) {
223
- // the | isn't already escaped, so escape it.
224
- $2 = '\\';
225
- // should already be done
226
- /* c8 ignore start */
227
- }
228
- /* c8 ignore stop */
229
- // need to escape all those slashes *again*, without escaping the
230
- // one that we need for escaping the | character. As it works out,
231
- // escaping an even number of slashes can be done by simply repeating
232
- // it exactly after itself. That's why this trick works.
233
- //
234
- // I am sorry that you have to see this.
235
- return $1 + $1 + $2 + '|';
236
- });
237
- debug('tail=%j\n %s', tail, tail, pl, re);
238
- const t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\' + pl.type;
239
- hasMagic = true;
240
- re = re.slice(0, pl.reStart) + t + '\\(' + tail;
241
- }
242
- // handle trailing things that only matter at the very end.
243
- clearStateChar();
244
- if (escaping) {
245
- // trailing \\
246
- re += '\\\\';
247
- }
248
- // only need to apply the nodot start if the re starts with
249
- // something that could conceivably capture a dot
250
- const addPatternStart = addPatternStartSet[re.charAt(0)];
251
- // Hack to work around lack of negative lookbehind in JS
252
- // A pattern like: *.!(x).!(y|z) needs to ensure that a name
253
- // like 'a.xyz.yz' doesn't match. So, the first negative
254
- // lookahead, has to look ALL the way ahead, to the end of
255
- // the pattern.
256
- for (let n = negativeLists.length - 1; n > -1; n--) {
257
- const nl = negativeLists[n];
258
- const nlBefore = re.slice(0, nl.reStart);
259
- const nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
260
- let nlAfter = re.slice(nl.reEnd);
261
- const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter;
262
- // Handle nested stuff like *(*.js|!(*.json)), where open parens
263
- // mean that we should *not* include the ) in the bit that is considered
264
- // "after" the negated section.
265
- const closeParensBefore = nlBefore.split(')').length;
266
- const openParensBefore = nlBefore.split('(').length - closeParensBefore;
267
- let cleanAfter = nlAfter;
268
- for (let i = 0; i < openParensBefore; i++) {
269
- cleanAfter = cleanAfter.replace(/\)[+*?]?/, '');
270
- }
271
- nlAfter = cleanAfter;
272
- const dollar = nlAfter === '' ? '(?:$|\\/)' : '';
273
- re = nlBefore + nlFirst + nlAfter + dollar + nlLast;
274
- }
275
- // if the re is not "" at this point, then we need to make sure
276
- // it doesn't match against an empty path part.
277
- // Otherwise a/* will match a/, which it should not.
278
- if (re !== '' && hasMagic) {
279
- re = '(?=.)' + re;
280
- }
281
- if (addPatternStart) {
282
- re = patternStart() + re;
283
- }
284
- // if it's nocase, and the lcase/uppercase don't match, it's magic
285
- if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {
286
- hasMagic = pattern.toUpperCase() !== pattern.toLowerCase();
287
- }
288
- // skip the regexp for non-magical patterns
289
- // unescape anything in it, though, so that it'll be
290
- // an exact match against a file etc.
291
- if (!hasMagic) {
292
- return globUnescape(re);
293
- }
294
- return re;
295
- };
296
- //# sourceMappingURL=_parse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_parse.js","sourceRoot":"","sources":["../../src/_parse.ts"],"names":[],"mappings":"AAAA,8BAA8B;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAE9D,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;AAC7D,MAAM,YAAY,GAAG,CAAC,CAAS,EAAE,EAAE,CACjC,CAAC,CAAC,OAAO,C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nimport { MinimatchOptions } from './index.js'\nimport { assertValidPattern } from './assert-valid-pattern.js'\n\nconst globUnescape = (s: string) => s.replace(/\\\\(.)/g, '$1')\nconst regExpEscape = (s: string) =>\n s.replace(/[-[\\]{}()*+?.,\\\\^$|#\\s]/g, '\\\\$&')\n\n// \"abc\" -> { a:true, b:true, c:true }\nconst charSet = (s: string) =>\n s.split('').reduce((set: { [k: string]: boolean }, c) => {\n set[c] = true\n return set\n }, {})\n\nconst plTypes = {\n '!': { open: '(?:(?!(?:', close: '))[^/]*?)' },\n '?': { open: '(?:', close: ')?' },\n '+': { open: '(?:', close: ')+' },\n '*': { open: '(?:', close: ')*' },\n '@': { open: '(?:', close: ')' },\n}\n\n// characters that need to be escaped in RegExp.\nconst reSpecials = charSet('().*{}+?[]^$\\\\!')\n\n// characters that indicate we have to add the pattern start\nconst addPatternStartSet = charSet('[.(')\n\ntype StateChar = '!' | '?' | '+' | '*' | '@'\n\n// any single thing other than /\n// don't need to escape / when using new RegExp()\nconst qmark = '[^/]'\n\n// * => any number of characters\nconst star = qmark + '*?'\n\ninterface PatternListEntry {\n type: string\n start: number\n reStart: number\n open: string\n close: string\n}\n\ninterface NegativePatternListEntry extends PatternListEntry {\n reEnd: number\n}\n\nexport type MMRegExp = RegExp & {\n _src?: string\n _glob?: string\n}\n\n// TODO: take an offset and length, so we can sub-parse the extglobs\nexport const parse = (\n options: MinimatchOptions,\n pattern: string,\n debug: (...a: any[]) => void,\n): false | string => {\n assertValidPattern(pattern)\n\n if (pattern === '') return ''\n\n let re = ''\n let hasMagic = false\n let escaping = false\n // ? => one single character\n const patternListStack: PatternListEntry[] = []\n const negativeLists: NegativePatternListEntry[] = []\n let stateChar: StateChar | false = false\n let uflag = false\n let pl: PatternListEntry | undefined\n // . and .. never match anything that doesn't start with .,\n // even when options.dot is set. However, if the pattern\n // starts with ., then traversal patterns can match.\n let dotTravAllowed = pattern.charAt(0) === '.'\n let dotFileAllowed = options.dot || dotTravAllowed\n const patternStart = () =>\n dotTravAllowed\n ? ''\n : dotFileAllowed\n ? '(?!(?:^|\\\\/)\\\\.{1,2}(?:$|\\\\/))'\n : '(?!\\\\.)'\n const subPatternStart = (p: string) =>\n p.charAt(0) === '.'\n ? ''\n : options.dot\n ? '(?!(?:^|\\\\/)\\\\.{1,2}(?:$|\\\\/))'\n : '(?!\\\\.)'\n\n const clearStateChar = () => {\n if (stateChar) {\n // we had some state-tracking character\n // that wasn't consumed by this pass.\n switch (stateChar) {\n case '*':\n re += star\n hasMagic = true\n break\n case '?':\n re += qmark\n hasMagic = true\n break\n default:\n re += '\\\\' + stateChar\n break\n }\n debug('clearStateChar %j %j', stateChar, re)\n stateChar = false\n }\n }\n\n for (\n let i = 0, c: string;\n i < pattern.length && (c = pattern.charAt(i));\n i++\n ) {\n debug('%s\\t%s %s %j', pattern, i, re, c)\n\n // skip over any that are escaped.\n if (escaping) {\n // completely not allowed, even escaped.\n // should be impossible.\n /* c8 ignore start */\n if (c === '/') {\n return false\n }\n /* c8 ignore stop */\n\n if (reSpecials[c]) {\n re += '\\\\'\n }\n re += c\n escaping = false\n continue\n }\n\n switch (c) {\n // Should already be path-split by now.\n /* c8 ignore start */\n case '/': {\n return false\n }\n /* c8 ignore stop */\n\n case '\\\\':\n clearStateChar()\n escaping = true\n continue\n\n // the various stateChar values\n // for the \"extglob\" stuff.\n case '?':\n case '*':\n case '+':\n case '@':\n case '!':\n debug('%s\\t%s %s %j <-- stateChar', pattern, i, re, c)\n\n // if we already have a stateChar, then it means\n // that there was something like ** or +? in there.\n // Handle the stateChar, then proceed with this one.\n debug('call clearStateChar %j', stateChar)\n clearStateChar()\n stateChar = c\n // if extglob is disabled, then +(asdf|foo) isn't a thing.\n // just clear the statechar *now*, rather than even diving into\n // the patternList stuff.\n if (options.noext) clearStateChar()\n continue\n\n case '(': {\n if (!stateChar) {\n re += '\\\\('\n continue\n }\n\n const plEntry: PatternListEntry = {\n type: stateChar,\n start: i - 1,\n reStart: re.length,\n open: plTypes[stateChar].open,\n close: plTypes[stateChar].close,\n }\n debug(pattern, '\\t', plEntry)\n patternListStack.push(plEntry)\n // negation is (?:(?!(?:js)(?:<rest>))[^/]*)\n re += plEntry.open\n // next entry starts with a dot maybe?\n if (plEntry.start === 0 && plEntry.type !== '!') {\n dotTravAllowed = true\n re += subPatternStart(pattern.slice(i + 1))\n }\n debug('plType %j %j', stateChar, re)\n stateChar = false\n continue\n }\n\n case ')': {\n const plEntry = patternListStack[patternListStack.length - 1]\n if (!plEntry) {\n re += '\\\\)'\n continue\n }\n patternListStack.pop()\n\n // closing an extglob\n clearStateChar()\n hasMagic = true\n pl = plEntry\n // negation is (?:(?!js)[^/]*)\n // The others are (?:<pattern>)<type>\n re += pl.close\n if (pl.type === '!') {\n negativeLists.push(Object.assign(pl, { reEnd: re.length }))\n }\n continue\n }\n\n case '|': {\n const plEntry = patternListStack[patternListStack.length - 1]\n if (!plEntry) {\n re += '\\\\|'\n continue\n }\n\n clearStateChar()\n re += '|'\n // next subpattern can start with a dot?\n if (plEntry.start === 0 && plEntry.type !== '!') {\n dotTravAllowed = true\n re += subPatternStart(pattern.slice(i + 1))\n }\n continue\n }\n\n // these are mostly the same in regexp and glob\n case '[':\n // swallow any state-tracking char before the [\n clearStateChar()\n const [src, needUflag, consumed, magic] = parseClass(pattern, i)\n if (consumed) {\n re += src\n uflag = uflag || needUflag\n i += consumed - 1\n hasMagic = hasMagic || magic\n } else {\n re += '\\\\['\n }\n continue\n\n case ']':\n re += '\\\\' + c\n continue\n\n default:\n // swallow any state char that wasn't consumed\n clearStateChar()\n\n re += regExpEscape(c)\n break\n } // switch\n } // for\n\n // handle the case where we had a +( thing at the *end*\n // of the pattern.\n // each pattern list stack adds 3 chars, and we need to go through\n // and escape any | chars that were passed through as-is for the regexp.\n // Go through and escape them, taking care not to double-escape any\n // | chars that were already escaped.\n for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {\n let tail: string\n tail = re.slice(pl.reStart + pl.open.length)\n debug(pattern, 'setting tail', re, pl)\n // maybe some even number of \\, then maybe 1 \\, followed by a |\n tail = tail.replace(/((?:\\\\{2}){0,64})(\\\\?)\\|/g, (_, $1, $2) => {\n if (!$2) {\n // the | isn't already escaped, so escape it.\n $2 = '\\\\'\n // should already be done\n /* c8 ignore start */\n }\n /* c8 ignore stop */\n\n // need to escape all those slashes *again*, without escaping the\n // one that we need for escaping the | character. As it works out,\n // escaping an even number of slashes can be done by simply repeating\n // it exactly after itself. That's why this trick works.\n //\n // I am sorry that you have to see this.\n return $1 + $1 + $2 + '|'\n })\n\n debug('tail=%j\\n %s', tail, tail, pl, re)\n const t = pl.type === '*' ? star : pl.type === '?' ? qmark : '\\\\' + pl.type\n\n hasMagic = true\n re = re.slice(0, pl.reStart) + t + '\\\\(' + tail\n }\n\n // handle trailing things that only matter at the very end.\n clearStateChar()\n if (escaping) {\n // trailing \\\\\n re += '\\\\\\\\'\n }\n\n // only need to apply the nodot start if the re starts with\n // something that could conceivably capture a dot\n const addPatternStart = addPatternStartSet[re.charAt(0)]\n\n // Hack to work around lack of negative lookbehind in JS\n // A pattern like: *.!(x).!(y|z) needs to ensure that a name\n // like 'a.xyz.yz' doesn't match. So, the first negative\n // lookahead, has to look ALL the way ahead, to the end of\n // the pattern.\n for (let n = negativeLists.length - 1; n > -1; n--) {\n const nl = negativeLists[n]\n\n const nlBefore = re.slice(0, nl.reStart)\n const nlFirst = re.slice(nl.reStart, nl.reEnd - 8)\n let nlAfter = re.slice(nl.reEnd)\n const nlLast = re.slice(nl.reEnd - 8, nl.reEnd) + nlAfter\n\n // Handle nested stuff like *(*.js|!(*.json)), where open parens\n // mean that we should *not* include the ) in the bit that is considered\n // \"after\" the negated section.\n const closeParensBefore = nlBefore.split(')').length\n const openParensBefore = nlBefore.split('(').length - closeParensBefore\n let cleanAfter = nlAfter\n for (let i = 0; i < openParensBefore; i++) {\n cleanAfter = cleanAfter.replace(/\\)[+*?]?/, '')\n }\n nlAfter = cleanAfter\n\n const dollar = nlAfter === '' ? '(?:$|\\\\/)' : ''\n\n re = nlBefore + nlFirst + nlAfter + dollar + nlLast\n }\n\n // if the re is not \"\" at this point, then we need to make sure\n // it doesn't match against an empty path part.\n // Otherwise a/* will match a/, which it should not.\n if (re !== '' && hasMagic) {\n re = '(?=.)' + re\n }\n\n if (addPatternStart) {\n re = patternStart() + re\n }\n\n // if it's nocase, and the lcase/uppercase don't match, it's magic\n if (options.nocase && !hasMagic && !options.nocaseMagicOnly) {\n hasMagic = pattern.toUpperCase() !== pattern.toLowerCase()\n }\n\n // skip the regexp for non-magical patterns\n // unescape anything in it, though, so that it'll be\n // an exact match against a file etc.\n if (!hasMagic) {\n return globUnescape(re)\n }\n\n return re\n}\n"]}
@@ -1,2 +0,0 @@
1
- export declare const assertValidPattern: (pattern: any) => void;
2
- //# sourceMappingURL=assert-valid-pattern.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-valid-pattern.d.ts","sourceRoot":"","sources":["../../src/assert-valid-pattern.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,kBAAkB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,IAUlD,CAAA"}
@@ -1,10 +0,0 @@
1
- const MAX_PATTERN_LENGTH = 1024 * 64;
2
- export const assertValidPattern = (pattern) => {
3
- if (typeof pattern !== 'string') {
4
- throw new TypeError('invalid pattern');
5
- }
6
- if (pattern.length > MAX_PATTERN_LENGTH) {
7
- throw new TypeError('pattern is too long');
8
- }
9
- };
10
- //# sourceMappingURL=assert-valid-pattern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"assert-valid-pattern.js","sourceRoot":"","sources":["../../src/assert-valid-pattern.ts"],"names":[],"mappings":"AAAA,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAAE,CAAA;AACpC,MAAM,CAAC,MAAM,kBAAkB,GAA2B,CACxD,OAAY,EACe,EAAE;IAC7B,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,MAAM,IAAI,SAAS,CAAC,iBAAiB,CAAC,CAAA;KACvC;IAED,IAAI,OAAO,CAAC,MAAM,GAAG,kBAAkB,EAAE;QACvC,MAAM,IAAI,SAAS,CAAC,qBAAqB,CAAC,CAAA;KAC3C;AACH,CAAC,CAAA","sourcesContent":["const MAX_PATTERN_LENGTH = 1024 * 64\nexport const assertValidPattern: (pattern: any) => void = (\n pattern: any\n): asserts pattern is string => {\n if (typeof pattern !== 'string') {\n throw new TypeError('invalid pattern')\n }\n\n if (pattern.length > MAX_PATTERN_LENGTH) {\n throw new TypeError('pattern is too long')\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=extglob.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extglob.d.ts","sourceRoot":"","sources":["../../src/extglob.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,CAAA"}
@@ -1,3 +0,0 @@
1
- // translate an extglob into a regular expression
2
- export {};
3
- //# sourceMappingURL=extglob.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extglob.js","sourceRoot":"","sources":["../../src/extglob.ts"],"names":[],"mappings":"AAAA,iDAAiD","sourcesContent":["// translate an extglob into a regular expression\n\n// call into this when we get a [!?@+] followed by (\n// Walk down until we find the appropriate closing ),\n// and parse all the sections.\n\n\nexport {}\n"]}