@@ -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,34 @@ 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 ( state : State , customParamType : NonNullable < ParamTypes [ 'custom' ] > ) : boolean {
461
+ return customParamType . some ( ( regex ) => {
467
462
const reg = new RegExp ( `^(?:${ regex } )` , 'uy' ) ;
468
463
return reg . test ( state . input . slice ( state . start ) ) ;
469
464
} ) ;
470
465
}
471
466
472
467
function isParameter ( ch : Char , state : State , paramTypes : ParamTypes ) : boolean {
473
- const curCh : any = ch ;
468
+ if ( ! ch ) {
469
+ return false ;
470
+ }
474
471
const nextChar = peek ( state ) ;
475
472
if ( paramTypes . positional && ch === '?' ) return true ;
476
473
477
- if ( paramTypes . numbered && paramTypes . numbered . length && paramTypes . numbered . includes ( curCh ) ) {
474
+ if ( paramTypes . numbered ?. length && paramTypes . numbered . some ( ( type ) => ch === type ) ) {
478
475
if ( nextChar !== null && ! isNaN ( Number ( nextChar ) ) ) {
479
476
return true ;
480
477
}
481
478
}
482
479
483
480
if (
484
- ( paramTypes . named && paramTypes . named . length && paramTypes . named . includes ( curCh ) ) ||
485
- ( paramTypes . quoted && paramTypes . quoted . length && paramTypes . quoted . includes ( curCh ) )
481
+ ( paramTypes . named ?. length && paramTypes . named . some ( ( type ) => type === ch ) ) ||
482
+ ( paramTypes . quoted ?. length && paramTypes . quoted . some ( ( type ) => type === ch ) )
486
483
) {
487
484
return true ;
488
485
}
489
486
490
- if ( paramTypes . custom && paramTypes . custom . length && isCustomParam ( state , paramTypes ) ) {
487
+ if ( paramTypes . custom ?. length && isCustomParam ( state , paramTypes . custom ) ) {
491
488
return true ;
492
489
}
493
490
0 commit comments