1
1
import { generate } from 'astring'
2
2
import * as es from 'estree'
3
3
4
+ import { UNKNOWN_LOCATION } from '../constants'
4
5
import * as tsEs from '../typeChecker/tsESTree'
5
6
import { ErrorSeverity , ErrorType , NodeWithInferredType , SArray , SourceError , Type } from '../types'
6
7
import { simplify , stripIndent } from '../utils/formatters'
@@ -15,7 +16,7 @@ export class InvalidArrayIndexType implements SourceError {
15
16
constructor ( public node : NodeWithInferredType < es . Node > , public receivedType : Type ) { }
16
17
17
18
get location ( ) {
18
- return this . node . loc !
19
+ return this . node . loc ?? UNKNOWN_LOCATION
19
20
}
20
21
21
22
public explain ( ) {
@@ -38,7 +39,7 @@ export class ArrayAssignmentError implements SourceError {
38
39
) { }
39
40
40
41
get location ( ) {
41
- return this . node . loc !
42
+ return this . node . loc ?? UNKNOWN_LOCATION
42
43
}
43
44
44
45
public explain ( ) {
@@ -58,7 +59,7 @@ export class ReassignConstError implements SourceError {
58
59
constructor ( public node : NodeWithInferredType < es . AssignmentExpression > ) { }
59
60
60
61
get location ( ) {
61
- return this . node . loc !
62
+ return this . node . loc ?? UNKNOWN_LOCATION
62
63
}
63
64
64
65
public explain ( ) {
@@ -82,7 +83,7 @@ export class DifferentAssignmentError implements SourceError {
82
83
) { }
83
84
84
85
get location ( ) {
85
- return this . node . loc !
86
+ return this . node . loc ?? UNKNOWN_LOCATION
86
87
}
87
88
88
89
public explain ( ) {
@@ -115,7 +116,7 @@ export class CyclicReferenceError implements SourceError {
115
116
constructor ( public node : NodeWithInferredType < es . Node > ) { }
116
117
117
118
get location ( ) {
118
- return this . node . loc !
119
+ return this . node . loc ?? UNKNOWN_LOCATION
119
120
}
120
121
121
122
public explain ( ) {
@@ -148,7 +149,7 @@ export class DifferentNumberArgumentsError implements SourceError {
148
149
) { }
149
150
150
151
get location ( ) {
151
- return this . node . loc !
152
+ return this . node . loc ?? UNKNOWN_LOCATION
152
153
}
153
154
154
155
public explain ( ) {
@@ -171,7 +172,7 @@ export class InvalidArgumentTypesError implements SourceError {
171
172
) { }
172
173
173
174
get location ( ) {
174
- return this . node . loc !
175
+ return this . node . loc ?? UNKNOWN_LOCATION
175
176
}
176
177
177
178
public explain ( ) {
@@ -268,7 +269,7 @@ export class InvalidTestConditionError implements SourceError {
268
269
) { }
269
270
270
271
get location ( ) {
271
- return this . node . loc !
272
+ return this . node . loc ?? UNKNOWN_LOCATION
272
273
}
273
274
274
275
public explain ( ) {
@@ -293,7 +294,7 @@ export class UndefinedIdentifierError implements SourceError {
293
294
constructor ( public node : NodeWithInferredType < es . Identifier > , public name : string ) { }
294
295
295
296
get location ( ) {
296
- return this . node . loc !
297
+ return this . node . loc ?? UNKNOWN_LOCATION
297
298
}
298
299
299
300
public explain ( ) {
@@ -320,7 +321,7 @@ export class ConsequentAlternateMismatchError implements SourceError {
320
321
) { }
321
322
322
323
get location ( ) {
323
- return this . node . loc !
324
+ return this . node . loc ?? UNKNOWN_LOCATION
324
325
}
325
326
326
327
public explain ( ) {
@@ -348,7 +349,7 @@ export class CallingNonFunctionType implements SourceError {
348
349
constructor ( public node : NodeWithInferredType < es . CallExpression > , public callerType : Type ) { }
349
350
350
351
get location ( ) {
351
- return this . node . loc !
352
+ return this . node . loc ?? UNKNOWN_LOCATION
352
353
}
353
354
354
355
public explain ( ) {
@@ -379,7 +380,7 @@ export class InconsistentPredicateTestError implements SourceError {
379
380
) { }
380
381
381
382
get location ( ) {
382
- return this . node . loc !
383
+ return this . node . loc ?? UNKNOWN_LOCATION
383
384
}
384
385
385
386
public explain ( ) {
@@ -413,7 +414,7 @@ export class TypeMismatchError implements SourceError {
413
414
) { }
414
415
415
416
get location ( ) {
416
- return this . node . loc !
417
+ return this . node . loc ?? UNKNOWN_LOCATION
417
418
}
418
419
419
420
public explain ( ) {
@@ -432,7 +433,7 @@ export class TypeNotFoundError implements SourceError {
432
433
constructor ( public node : tsEs . Node , public name : string ) { }
433
434
434
435
get location ( ) {
435
- return this . node . loc !
436
+ return this . node . loc ?? UNKNOWN_LOCATION
436
437
}
437
438
438
439
public explain ( ) {
@@ -451,7 +452,7 @@ export class FunctionShouldHaveReturnValueError implements SourceError {
451
452
constructor ( public node : tsEs . FunctionDeclaration | tsEs . ArrowFunctionExpression ) { }
452
453
453
454
get location ( ) {
454
- return this . node . loc !
455
+ return this . node . loc ?? UNKNOWN_LOCATION
455
456
}
456
457
457
458
public explain ( ) {
@@ -470,7 +471,7 @@ export class TypeNotCallableError implements SourceError {
470
471
constructor ( public node : tsEs . CallExpression , public typeName : string ) { }
471
472
472
473
get location ( ) {
473
- return this . node . loc !
474
+ return this . node . loc ?? UNKNOWN_LOCATION
474
475
}
475
476
476
477
public explain ( ) {
@@ -493,7 +494,7 @@ export class TypecastError implements SourceError {
493
494
) { }
494
495
495
496
get location ( ) {
496
- return this . node . loc !
497
+ return this . node . loc ?? UNKNOWN_LOCATION
497
498
}
498
499
499
500
public explain ( ) {
@@ -512,7 +513,7 @@ export class TypeNotAllowedError implements SourceError {
512
513
constructor ( public node : tsEs . TSType , public name : string ) { }
513
514
514
515
get location ( ) {
515
- return this . node . loc !
516
+ return this . node . loc ?? UNKNOWN_LOCATION
516
517
}
517
518
518
519
public explain ( ) {
@@ -531,7 +532,7 @@ export class UndefinedVariableTypeError implements SourceError {
531
532
constructor ( public node : tsEs . Node , public name : string ) { }
532
533
533
534
get location ( ) {
534
- return this . node . loc !
535
+ return this . node . loc ?? UNKNOWN_LOCATION
535
536
}
536
537
537
538
public explain ( ) {
@@ -558,7 +559,7 @@ export class InvalidNumberOfArgumentsTypeError implements SourceError {
558
559
}
559
560
560
561
get location ( ) {
561
- return this . node . loc !
562
+ return this . node . loc ?? UNKNOWN_LOCATION
562
563
}
563
564
564
565
public explain ( ) {
@@ -582,7 +583,7 @@ export class InvalidNumberOfTypeArgumentsForGenericTypeError implements SourceEr
582
583
constructor ( public node : tsEs . Node , public name : string , public expected : number ) { }
583
584
584
585
get location ( ) {
585
- return this . node . loc !
586
+ return this . node . loc ?? UNKNOWN_LOCATION
586
587
}
587
588
588
589
public explain ( ) {
@@ -601,7 +602,7 @@ export class TypeNotGenericError implements SourceError {
601
602
constructor ( public node : tsEs . Node , public name : string ) { }
602
603
603
604
get location ( ) {
604
- return this . node . loc !
605
+ return this . node . loc ?? UNKNOWN_LOCATION
605
606
}
606
607
607
608
public explain ( ) {
@@ -620,7 +621,7 @@ export class TypeAliasNameNotAllowedError implements SourceError {
620
621
constructor ( public node : tsEs . TSTypeAliasDeclaration , public name : string ) { }
621
622
622
623
get location ( ) {
623
- return this . node . loc !
624
+ return this . node . loc ?? UNKNOWN_LOCATION
624
625
}
625
626
626
627
public explain ( ) {
@@ -639,7 +640,7 @@ export class TypeParameterNameNotAllowedError implements SourceError {
639
640
constructor ( public node : tsEs . TSTypeParameter , public name : string ) { }
640
641
641
642
get location ( ) {
642
- return this . node . loc !
643
+ return this . node . loc ?? UNKNOWN_LOCATION
643
644
}
644
645
645
646
public explain ( ) {
@@ -658,7 +659,7 @@ export class InvalidIndexTypeError implements SourceError {
658
659
constructor ( public node : tsEs . MemberExpression , public typeName : string ) { }
659
660
660
661
get location ( ) {
661
- return this . node . loc !
662
+ return this . node . loc ?? UNKNOWN_LOCATION
662
663
}
663
664
664
665
public explain ( ) {
@@ -677,7 +678,7 @@ export class InvalidArrayAccessTypeError implements SourceError {
677
678
constructor ( public node : tsEs . MemberExpression , public typeName : string ) { }
678
679
679
680
get location ( ) {
680
- return this . node . loc !
681
+ return this . node . loc ?? UNKNOWN_LOCATION
681
682
}
682
683
683
684
public explain ( ) {
@@ -696,7 +697,7 @@ export class ConstNotAssignableTypeError implements SourceError {
696
697
constructor ( public node : tsEs . AssignmentExpression , public name : string ) { }
697
698
698
699
get location ( ) {
699
- return this . node . loc !
700
+ return this . node . loc ?? UNKNOWN_LOCATION
700
701
}
701
702
702
703
public explain ( ) {
@@ -715,7 +716,7 @@ export class DuplicateTypeAliasError implements SourceError {
715
716
constructor ( public node : tsEs . TSTypeAliasDeclaration , public name : string ) { }
716
717
717
718
get location ( ) {
718
- return this . node . loc !
719
+ return this . node . loc ?? UNKNOWN_LOCATION
719
720
}
720
721
721
722
public explain ( ) {
0 commit comments