@@ -269,11 +269,11 @@ function getCustomParam(state: State, paramTypes: ParamTypes): string | null | u
269
269
}
270
270
271
271
function scanParameter ( state : State , dialect : Dialect , paramTypes : ParamTypes ) : Token {
272
- const curCh : any = state . input [ state . start ] ;
272
+ const curCh = state . input [ state . start ] ;
273
273
const nextChar = peek ( state ) ;
274
274
let matched = false ;
275
275
276
- if ( paramTypes . numbered && paramTypes . numbered . length && paramTypes . numbered . includes ( curCh ) ) {
276
+ if ( paramTypes . numbered ?. length && paramTypes . numbered . some ( ( type ) => type === curCh ) ) {
277
277
const endIndex = state . input
278
278
. slice ( state . start + 1 )
279
279
. split ( '' )
@@ -293,19 +293,14 @@ function scanParameter(state: State, dialect: Dialect, paramTypes: ParamTypes):
293
293
}
294
294
}
295
295
296
- if ( ! matched && paramTypes . named && paramTypes . named . length && paramTypes . named . includes ( curCh ) ) {
296
+ if ( ! matched && paramTypes . named ?. length && paramTypes . named . some ( ( type ) => type === curCh ) ) {
297
297
if ( ! isQuotedIdentifier ( nextChar , dialect ) ) {
298
298
while ( isAlphaNumeric ( peek ( state ) ) ) read ( state ) ;
299
299
matched = true ;
300
300
}
301
301
}
302
302
303
- if (
304
- ! matched &&
305
- paramTypes . quoted &&
306
- paramTypes . quoted . length &&
307
- paramTypes . quoted . includes ( curCh )
308
- ) {
303
+ if ( ! matched && paramTypes . quoted ?. length && paramTypes . quoted . some ( ( type ) => type === curCh ) ) {
309
304
if ( isQuotedIdentifier ( nextChar , dialect ) ) {
310
305
const quoteChar = read ( state ) as string ;
311
306
// end when we reach the end quote
@@ -462,32 +457,37 @@ function isString(ch: Char, dialect: Dialect): boolean {
462
457
return stringStart . includes ( ch ) ;
463
458
}
464
459
465
- function isCustomParam ( state : State , paramTypes : ParamTypes ) : boolean | undefined {
466
- return paramTypes ?. custom ?. some ( ( regex ) => {
460
+ function isCustomParam (
461
+ state : State ,
462
+ customParamType : NonNullable < ParamTypes [ 'custom' ] > ,
463
+ ) : boolean | undefined {
464
+ return customParamType . some ( ( regex ) => {
467
465
const reg = new RegExp ( `^(?:${ regex } )` , 'uy' ) ;
468
466
return reg . test ( state . input . slice ( state . start ) ) ;
469
467
} ) ;
470
468
}
471
469
472
470
function isParameter ( ch : Char , state : State , paramTypes : ParamTypes ) : boolean {
473
- const curCh : any = ch ;
471
+ if ( ! ch ) {
472
+ return false ;
473
+ }
474
474
const nextChar = peek ( state ) ;
475
475
if ( paramTypes . positional && ch === '?' ) return true ;
476
476
477
- if ( paramTypes . numbered && paramTypes . numbered . length && paramTypes . numbered . includes ( curCh ) ) {
477
+ if ( paramTypes . numbered ?. length && paramTypes . numbered . some ( ( type ) => ch === type ) ) {
478
478
if ( nextChar !== null && ! isNaN ( Number ( nextChar ) ) ) {
479
479
return true ;
480
480
}
481
481
}
482
482
483
483
if (
484
- ( paramTypes . named && paramTypes . named . length && paramTypes . named . includes ( curCh ) ) ||
485
- ( paramTypes . quoted && paramTypes . quoted . length && paramTypes . quoted . includes ( curCh ) )
484
+ ( paramTypes . named ?. length && paramTypes . named . some ( ( type ) => type === ch ) ) ||
485
+ ( paramTypes . quoted ?. length && paramTypes . quoted . some ( ( type ) => type === ch ) )
486
486
) {
487
487
return true ;
488
488
}
489
489
490
- if ( paramTypes . custom && paramTypes . custom . length && isCustomParam ( state , paramTypes ) ) {
490
+ if ( paramTypes . custom ?. length && isCustomParam ( state , paramTypes . custom ) ) {
491
491
return true ;
492
492
}
493
493
0 commit comments