1
0
Fork 0
pull/271/head
eric sciple 2019-12-21 03:39:15 -05:00
parent 8a7a45e5ef
commit a8700a3cd0
1 changed files with 16 additions and 27 deletions

View File

@ -12,7 +12,7 @@ export class Pattern {
searchPath: string
private minimatch: IMinimatch
private rootRegExp: RegExp
private trailingSlash: boolean = false
private trailingSlash: boolean
constructor(pattern: string) {
pattern = pattern || ''
@ -32,11 +32,21 @@ export class Pattern {
.endsWith(path.sep)
pattern = pathHelper.safeTrimTrailingSeparator(pattern)
// Set search path
// Set root regexp
this.searchPath = (undefined as unknown) as string
this.rootRegExp = (undefined as unknown) as RegExp
this.initializePaths(pattern)
// Search path
const searchSegments: string[] = []
for (const literal of this.getLiterals(pattern)) {
if (!literal) {
break
}
searchSegments.push(literal)
}
this.searchPath = new Path(searchSegments).toString()
// Root RegExp (required when determining partial match)
this.rootRegExp = new RegExp(
this.regExpEscape(searchSegments[0]),
IS_WINDOWS ? 'i' : ''
)
// Create minimatch
const minimatchOptions: IMinimatchOptions = {
@ -122,27 +132,6 @@ export class Pattern {
return pattern
}
/**
* Initializes the search path and root regexp
*/
private initializePaths(pattern: string): void {
// Build the search path
const searchSegments: string[] = []
for (const literal of this.getLiterals(pattern)) {
if (!literal) {
break
}
searchSegments.push(literal)
}
this.searchPath = new Path(searchSegments).toString()
// Store the root segment (required when determining partial match)
this.rootRegExp = new RegExp(
this.regExpEscape(searchSegments[0]),
IS_WINDOWS ? 'i' : ''
)
}
/**
* Splits a pattern into segments and attempts to unescape each segment
* to create a literal segment. Otherwise creates an empty segment.