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 searchPath: string
private minimatch: IMinimatch private minimatch: IMinimatch
private rootRegExp: RegExp private rootRegExp: RegExp
private trailingSlash: boolean = false private trailingSlash: boolean
constructor(pattern: string) { constructor(pattern: string) {
pattern = pattern || '' pattern = pattern || ''
@ -32,11 +32,21 @@ export class Pattern {
.endsWith(path.sep) .endsWith(path.sep)
pattern = pathHelper.safeTrimTrailingSeparator(pattern) pattern = pathHelper.safeTrimTrailingSeparator(pattern)
// Set search path // Search path
// Set root regexp const searchSegments: string[] = []
this.searchPath = (undefined as unknown) as string for (const literal of this.getLiterals(pattern)) {
this.rootRegExp = (undefined as unknown) as RegExp if (!literal) {
this.initializePaths(pattern) 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 // Create minimatch
const minimatchOptions: IMinimatchOptions = { const minimatchOptions: IMinimatchOptions = {
@ -122,27 +132,6 @@ export class Pattern {
return 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 * Splits a pattern into segments and attempts to unescape each segment
* to create a literal segment. Otherwise creates an empty segment. * to create a literal segment. Otherwise creates an empty segment.