File tree Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Expand file tree Collapse file tree 1 file changed +6
-10
lines changed Original file line number Diff line number Diff line change @@ -561,24 +561,20 @@ function escape(str: string) {
561561}
562562
563563/**
564- * Escape and repeat a string for regular expressions.
564+ * Escape and repeat loose characters for regular expressions.
565565 */
566- function repeat ( str : string ) {
567- return `${ escape ( str ) } +` ;
566+ function looseReplacer ( value : string , loose : string ) {
567+ return loose ? `${ escape ( value ) } +` : escape ( value ) ;
568568}
569569
570570/**
571571 * Encode all non-delimiter characters using the encode function.
572572 */
573573function toStringify ( loose : string ) {
574- if ( loose ) {
575- const re = new RegExp ( `[^${ escape ( loose ) } ]+|(.)` , "g" ) ;
576- const replacer = ( value : string , loose : string ) =>
577- loose ? repeat ( value ) : escape ( value ) ;
578- return ( value : string ) => value . replace ( re , replacer ) ;
579- }
574+ if ( ! loose ) return escape ;
580575
581- return escape ;
576+ const re = new RegExp ( `[^${ escape ( loose ) } ]+|(.)` , "g" ) ;
577+ return ( value : string ) => value . replace ( re , looseReplacer ) ;
582578}
583579
584580/**
You can’t perform that action at this time.
0 commit comments