Skip to content

Commit 903e50b

Browse files
committed
add braceExpandMax option, format
1 parent a50a110 commit 903e50b

File tree

15 files changed

+329
-142
lines changed

15 files changed

+329
-142
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ Returns a function that tests its
157157
supplied argument, suitable for use with `Array.filter`. Example:
158158

159159
```javascript
160-
var javascripts = fileList.filter(minimatch.filter('*.js', { matchBase: true }))
160+
var javascripts = fileList.filter(
161+
minimatch.filter('*.js', { matchBase: true }),
162+
)
161163
```
162164

163165
### minimatch.escape(pattern, options = {})

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"presnap": "npm run prepare",
3535
"test": "tap",
3636
"snap": "tap",
37-
"format": "prettier --write . --log-level warn",
37+
"format": "prettier --write .",
3838
"benchmark": "node benchmark/index.js",
3939
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
4040
},

src/ast.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ export class AST {
172172
for (const p of parts) {
173173
if (p === '') continue
174174
/* c8 ignore start */
175-
if (typeof p !== 'string' && !(p instanceof AST && p.#parent === this)) {
175+
if (
176+
typeof p !== 'string' &&
177+
!(p instanceof AST && p.#parent === this)
178+
) {
176179
throw new Error('invalid part: ' + p)
177180
}
178181
/* c8 ignore stop */
@@ -182,9 +185,11 @@ export class AST {
182185

183186
toJSON() {
184187
const ret: any[] =
185-
this.type === null
186-
? this.#parts.slice().map(p => (typeof p === 'string' ? p : p.toJSON()))
187-
: [this.type, ...this.#parts.map(p => (p as AST).toJSON())]
188+
this.type === null ?
189+
this.#parts
190+
.slice()
191+
.map(p => (typeof p === 'string' ? p : p.toJSON()))
192+
: [this.type, ...this.#parts.map(p => (p as AST).toJSON())]
188193
if (this.isStart() && !this.type) ret.unshift([])
189194
if (
190195
this.isEnd() &&
@@ -484,9 +489,9 @@ export class AST {
484489
const src = this.#parts
485490
.map(p => {
486491
const [re, _, hasMagic, uflag] =
487-
typeof p === 'string'
488-
? AST.#parseGlob(p, this.#hasMagic, noEmpty)
489-
: p.toRegExpSource(allowDot)
492+
typeof p === 'string' ?
493+
AST.#parseGlob(p, this.#hasMagic, noEmpty)
494+
: p.toRegExpSource(allowDot)
490495
this.#hasMagic = this.#hasMagic || hasMagic
491496
this.#uflag = this.#uflag || uflag
492497
return re
@@ -518,7 +523,10 @@ export class AST {
518523
// sub-pattern will be preventing it anyway.
519524
const needNoDot = !dot && !allowDot && aps.has(src.charAt(0))
520525

521-
start = needNoTrav ? startNoTraversal : needNoDot ? startNoDot : ''
526+
start =
527+
needNoTrav ? startNoTraversal
528+
: needNoDot ? startNoDot
529+
: ''
522530
}
523531
}
524532
}
@@ -562,9 +570,9 @@ export class AST {
562570

563571
// XXX abstract out this map method
564572
let bodyDotAllowed =
565-
!repeated || allowDot || dot || !startNoDot
566-
? ''
567-
: this.#partsToRegExp(true)
573+
!repeated || allowDot || dot || !startNoDot ?
574+
''
575+
: this.#partsToRegExp(true)
568576
if (bodyDotAllowed === body) {
569577
bodyDotAllowed = ''
570578
}
@@ -578,21 +586,17 @@ export class AST {
578586
final = (this.isStart() && !dot ? startNoDot : '') + starNoEmpty
579587
} else {
580588
const close =
581-
this.type === '!'
582-
? // !() must match something,but !(x) can match ''
583-
'))' +
584-
(this.isStart() && !dot && !allowDot ? startNoDot : '') +
585-
star +
586-
')'
587-
: this.type === '@'
588-
? ')'
589-
: this.type === '?'
590-
? ')?'
591-
: this.type === '+' && bodyDotAllowed
592-
? ')'
593-
: this.type === '*' && bodyDotAllowed
594-
? `)?`
595-
: `)${this.type}`
589+
this.type === '!' ?
590+
// !() must match something,but !(x) can match ''
591+
'))' +
592+
(this.isStart() && !dot && !allowDot ? startNoDot : '') +
593+
star +
594+
')'
595+
: this.type === '@' ? ')'
596+
: this.type === '?' ? ')?'
597+
: this.type === '+' && bodyDotAllowed ? ')'
598+
: this.type === '*' && bodyDotAllowed ? `)?`
599+
: `)${this.type}`
596600
final = start + body + close
597601
}
598602
return [

src/brace-expressions.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
// this works across all unicode locales
33

44
// { <posix class>: [<translation>, /u flag required, negated]
5-
const posixClasses: { [k: string]: [e: string, u: boolean, n?: boolean] } = {
6-
'[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
7-
'[:alpha:]': ['\\p{L}\\p{Nl}', true],
8-
'[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
9-
'[:blank:]': ['\\p{Zs}\\t', true],
10-
'[:cntrl:]': ['\\p{Cc}', true],
11-
'[:digit:]': ['\\p{Nd}', true],
12-
'[:graph:]': ['\\p{Z}\\p{C}', true, true],
13-
'[:lower:]': ['\\p{Ll}', true],
14-
'[:print:]': ['\\p{C}', true],
15-
'[:punct:]': ['\\p{P}', true],
16-
'[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
17-
'[:upper:]': ['\\p{Lu}', true],
18-
'[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
19-
'[:xdigit:]': ['A-Fa-f0-9', false],
20-
}
5+
const posixClasses: { [k: string]: [e: string, u: boolean, n?: boolean] } =
6+
{
7+
'[:alnum:]': ['\\p{L}\\p{Nl}\\p{Nd}', true],
8+
'[:alpha:]': ['\\p{L}\\p{Nl}', true],
9+
'[:ascii:]': ['\\x' + '00-\\x' + '7f', false],
10+
'[:blank:]': ['\\p{Zs}\\t', true],
11+
'[:cntrl:]': ['\\p{Cc}', true],
12+
'[:digit:]': ['\\p{Nd}', true],
13+
'[:graph:]': ['\\p{Z}\\p{C}', true, true],
14+
'[:lower:]': ['\\p{Ll}', true],
15+
'[:print:]': ['\\p{C}', true],
16+
'[:punct:]': ['\\p{P}', true],
17+
'[:space:]': ['\\p{Z}\\t\\r\\n\\v\\f', true],
18+
'[:upper:]': ['\\p{Lu}', true],
19+
'[:word:]': ['\\p{L}\\p{Nl}\\p{Nd}\\p{Pc}', true],
20+
'[:xdigit:]': ['A-Fa-f0-9', false],
21+
}
2122

2223
// only need to escape a few things inside of brace expressions
2324
// escapes: [ \ ] -
@@ -163,11 +164,9 @@ export const parseClass = (
163164
const sranges = '[' + (negate ? '^' : '') + rangesToString(ranges) + ']'
164165
const snegs = '[' + (negate ? '' : '^') + rangesToString(negs) + ']'
165166
const comb =
166-
ranges.length && negs.length
167-
? '(' + sranges + '|' + snegs + ')'
168-
: ranges.length
169-
? sranges
170-
: snegs
167+
ranges.length && negs.length ? '(' + sranges + '|' + snegs + ')'
168+
: ranges.length ? sranges
169+
: snegs
171170

172171
return [comb, uflag, endPos - pos, true]
173172
}

src/escape.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ export const escape = (
2323
// that make those magic, and escaping ! as [!] isn't valid,
2424
// because [!]] is a valid glob class meaning not ']'.
2525
if (magicalBraces) {
26-
return windowsPathsNoEscape
27-
? s.replace(/[?*()[\]{}]/g, '[$&]')
26+
return windowsPathsNoEscape ?
27+
s.replace(/[?*()[\]{}]/g, '[$&]')
2828
: s.replace(/[?*()[\]\\{}]/g, '\\$&')
2929
}
30-
return windowsPathsNoEscape
31-
? s.replace(/[?*()[\]]/g, '[$&]')
30+
return windowsPathsNoEscape ?
31+
s.replace(/[?*()[\]]/g, '[$&]')
3232
: s.replace(/[?*()[\]\\]/g, '\\$&')
3333
}

0 commit comments

Comments
 (0)