@@ -482,8 +482,8 @@ defineProperties(String.prototype, {
482482 let str = this . substring ( from , val ? val . index : this . length ) ;
483483 if ( str ) push ( str ) ;
484484 if ( val ) {
485- let pos = findPairs ( this , { "{" : num => ++ num , "}" : num => ++ num } ) ;
486- let code = this . substring ( val . index + 2 , pos ) ;
485+ let pos = findPairs ( this , { "{" : num => ++ num , "}" : num => -- num } ) ;
486+ let code = this . substring ( val . index + 2 , pos - 1 ) ;
487487 if ( code ) push ( code , true ) ;
488488 from = pos + 1 ;
489489 }
@@ -595,21 +595,20 @@ function findPairs(this: string | void, stringOrOperators: string | string[] |
595595 depthArg ?: number ) {
596596 const [ string , operators , location , depth ] =
597597 stringOrOperators instanceof Array || typeof stringOrOperators == "string" ||
598- stringOrOperators instanceof String ?
599- [
600- typeof stringOrOperators == "string" ?
601- stringOrOperators . split ( "" ) : stringOrOperators as string [ ] ,
602- operatorsOrLocation as Of < ( depth : number ) => number > ,
603- locationOrDepth as number || 0 ,
604- depthArg == null ? - 1 : depthArg as number
605- ] :
606- [
607- ( this as string ) . split ( "" ) ,
608- stringOrOperators as Of < ( depth : number ) => number > ,
609- operatorsOrLocation as number || 0 ,
610- locationOrDepth == null ? - 1 : locationOrDepth as number
611- ] ;
598+ stringOrOperators instanceof String ? [
599+ typeof stringOrOperators == "string" ?
600+ stringOrOperators . split ( "" ) : stringOrOperators as string [ ] ,
601+ operatorsOrLocation as Of < ( depth : number ) => number > ,
602+ locationOrDepth as number || 0 ,
603+ depthArg == null ? - 1 : depthArg as number
604+ ] : [
605+ ( this as string ) . split ( "" ) ,
606+ stringOrOperators as Of < ( depth : number ) => number > ,
607+ operatorsOrLocation as number || 0 ,
608+ locationOrDepth == null ? - 1 : locationOrDepth as number
609+ ] ;
612610 if ( depth == 0 ) return location ;
611+ if ( string [ location ] == null ) throw new Error ( ) ;
613612 const operation = operators [ string [ location ] ] ;
614613 const newDepth = operation ? operation ( depth == - 1 ? 0 : depth ) : depth ;
615614 return findPairs ( string , operators , location + 1 , newDepth ) ;
0 commit comments