File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,11 +2,7 @@ import * as angular from '@angular/compiler';
22import type * as babel from '@babel/types' ;
33
44import type { LocationInformation , NGNode , RawNGSpan } from './types.ts' ;
5- import {
6- getCharacterIndex ,
7- getCharacterLastIndex ,
8- sourceSpanToLocationInformation ,
9- } from './utils.ts' ;
5+ import { getCharacterIndex , sourceSpanToLocationInformation } from './utils.ts' ;
106
117export class Source {
128 text ;
@@ -19,10 +15,6 @@ export class Source {
1915 return getCharacterIndex ( this . text , pattern , index ) ;
2016 }
2117
22- getCharacterLastIndex ( pattern : RegExp | string , index : number ) {
23- return getCharacterLastIndex ( this . text , pattern , index ) ;
24- }
25-
2618 transformSpan ( span : RawNGSpan ) : LocationInformation {
2719 return sourceSpanToLocationInformation ( span ) ;
2820 }
Original file line number Diff line number Diff line change 1- import { getCharacterIndex , getCharacterLastIndex } from './utils.ts' ;
1+ import { getCharacterIndex } from './utils.ts' ;
22
33test ( 'getCharacterIndex' , ( ) => {
44 expect ( getCharacterIndex ( 'foobar' , / o / , 0 ) ) . toBe ( 1 ) ;
55 expect ( getCharacterIndex ( 'foobar' , / o / , 1 ) ) . toBe ( 1 ) ;
66 expect ( getCharacterIndex ( 'foobar' , 'o' , 0 ) ) . toBe ( 1 ) ;
77 expect ( ( ) => getCharacterIndex ( 'foobar' , '_' , 0 ) ) . toThrow ( ) ;
88} ) ;
9-
10- test ( 'getCharacterLastIndex' , ( ) => {
11- expect ( getCharacterLastIndex ( 'foobar' , / o / , 6 ) ) . toBe ( 2 ) ;
12- expect ( getCharacterLastIndex ( 'foobar' , / o / , 2 ) ) . toBe ( 2 ) ;
13- expect ( getCharacterLastIndex ( 'foobar' , 'o' , 6 ) ) . toBe ( 2 ) ;
14- expect ( ( ) => getCharacterLastIndex ( 'foobar' , '_' , 6 ) ) . toThrow ( ) ;
15- } ) ;
Original file line number Diff line number Diff line change @@ -8,29 +8,6 @@ function getCharacterSearchTestFunction(pattern: RegExp | string) {
88 return ( character : string ) => pattern . test ( character ) ;
99}
1010
11- export function getCharacterLastIndex (
12- text : string ,
13- pattern : RegExp | string ,
14- fromIndex : number ,
15- ) {
16- const test = getCharacterSearchTestFunction ( pattern ) ;
17-
18- for ( let index = fromIndex ; index >= 0 ; index -- ) {
19- const character = text [ index ] ;
20-
21- if ( test ( character ) ) {
22- return index ;
23- }
24- }
25-
26- /* c8 ignore next 4 @preserve */
27- throw new Error (
28- `Cannot find front char ${ pattern } from index ${ fromIndex } in ${ JSON . stringify (
29- text ,
30- ) } `,
31- ) ;
32- }
33-
3411export function getCharacterIndex (
3512 text : string ,
3613 pattern : RegExp | string ,
You can’t perform that action at this time.
0 commit comments