@@ -3,15 +3,11 @@ import { Argument, AllArguments } from './Arguments'
33
44type ArgumentsClass = 'plain' | 'with-predicate' | 'wildcard'
55export class RecordedArguments {
6- private _argumentsClass : ArgumentsClass
6+ private _argumentsClass ? : ArgumentsClass
77 private _value ?: any [ ]
8- private readonly _hasNoArguments : boolean = false
98
109 private constructor ( rawArguments : any [ ] | void ) {
11- if ( typeof rawArguments === 'undefined' ) {
12- this . _hasNoArguments = true
13- return this
14- }
10+ if ( typeof rawArguments === 'undefined' ) return this
1511
1612 this . _argumentsClass = this . classifyArguments ( rawArguments )
1713 this . _value = rawArguments
@@ -42,23 +38,22 @@ export class RecordedArguments {
4238 } )
4339 }
4440
45- get argumentsClass ( ) : ArgumentsClass {
41+ get argumentsClass ( ) : ArgumentsClass | undefined {
4642 return this . _argumentsClass
4743 }
4844
4945 get value ( ) : any [ ] | undefined {
5046 return this . _value
5147 }
5248
53- get hasNoArguments ( ) : boolean {
54- return this . _hasNoArguments
49+ public hasArguments ( ) : this is this & { argumentsClass : ArgumentsClass , value : any [ ] } {
50+ return Array . isArray ( this . _value )
5551 }
5652
57- public match ( other : RecordedArguments ) {
53+ public match ( other : RecordedArguments ) : boolean {
5854 if ( this . argumentsClass === 'wildcard' || other . argumentsClass === 'wildcard' ) return true
59- if ( this . hasNoArguments || other . hasNoArguments ) return this . hasNoArguments && other . hasNoArguments
55+ if ( ! this . hasArguments ( ) || ! other . hasArguments ( ) ) return ! this . hasArguments ( ) && ! other . hasArguments ( )
6056 if ( this . value . length !== other . value . length ) return false
61-
6257 return this . value . every ( ( argument , index ) => this . areArgumentsEqual ( argument , other . value [ index ] ) )
6358 }
6459
0 commit comments