@@ -347,26 +347,35 @@ export declare function Memoize(target: any, propertyName: string, descriptor: T
347
347
348
348
/** Collection of helper functions that can be used to throw errors. */
349
349
export declare namespace errors {
350
+ /**
351
+ * Minimal attributes to show a error message with the node source.
352
+ */
353
+ interface Node {
354
+ getSourceFile ( ) : {
355
+ getFilePath ( ) : StandardizedFilePath ;
356
+ getFullText ( ) : string ;
357
+ } ;
358
+ getStart ( ) : number ;
359
+ }
350
360
/** Base error class. */
351
361
abstract class BaseError extends Error {
352
- readonly message : string ;
353
362
protected constructor ( ) ;
354
363
}
355
364
/** Thrown when there is a problem with a provided argument. */
356
365
class ArgumentError extends BaseError {
357
- constructor ( argName : string , message : string ) ;
366
+ constructor ( argName : string , message : string , node ?: Node ) ;
358
367
}
359
368
/** Thrown when an argument is null or whitespace. */
360
369
class ArgumentNullOrWhitespaceError extends ArgumentError {
361
- constructor ( argName : string ) ;
370
+ constructor ( argName : string , node ?: Node ) ;
362
371
}
363
372
/** Thrown when an argument is out of range. */
364
373
class ArgumentOutOfRangeError extends ArgumentError {
365
- constructor ( argName : string , value : number , range : [ number , number ] ) ;
374
+ constructor ( argName : string , value : number , range : [ number , number ] , node ?: Node ) ;
366
375
}
367
376
/** Thrown when an argument does not match an expected type. */
368
377
class ArgumentTypeError extends ArgumentError {
369
- constructor ( argName : string , expectedType : string , actualType : string ) ;
378
+ constructor ( argName : string , expectedType : string , actualType : string , node ?: Node ) ;
370
379
}
371
380
/** Thrown when a file or directory path was not found. */
372
381
class PathNotFoundError extends BaseError {
@@ -384,11 +393,11 @@ export declare namespace errors {
384
393
}
385
394
/** Thrown when an action was taken that is not allowed. */
386
395
class InvalidOperationError extends BaseError {
387
- constructor ( message : string ) ;
396
+ constructor ( message : string , node ?: Node ) ;
388
397
}
389
398
/** Thrown when a certain behaviour or feature has not been implemented. */
390
399
class NotImplementedError extends BaseError {
391
- constructor ( message ?: string ) ;
400
+ constructor ( message ?: string , node ?: Node ) ;
392
401
}
393
402
/** Thrown when an operation is not supported. */
394
403
class NotSupportedError extends BaseError {
@@ -433,7 +442,7 @@ export declare namespace errors {
433
442
* Gets an error saying that a feature is not implemented for a certain syntax kind.
434
443
* @param kind - Syntax kind that isn't implemented.
435
444
*/
436
- function throwNotImplementedForSyntaxKindError ( kind : ts . SyntaxKind ) : never ;
445
+ function throwNotImplementedForSyntaxKindError ( kind : ts . SyntaxKind , node ?: Node ) : never ;
437
446
/**
438
447
* Throws an Argument
439
448
* @param value
@@ -445,12 +454,12 @@ export declare namespace errors {
445
454
* @param value - Value to check.
446
455
* @param errorMessage - Error message to throw when not defined.
447
456
*/
448
- function throwIfNullOrUndefined < T > ( value : T | undefined , errorMessage : string | ( ( ) => string ) ) : T ;
457
+ function throwIfNullOrUndefined < T > ( value : T | undefined , errorMessage : string | ( ( ) => string ) , node ?: Node ) : T ;
449
458
/**
450
459
* Throw if the value should have been the never type.
451
460
* @param value - Value to check.
452
461
*/
453
- function throwNotImplementedForNeverValueError ( value : never ) : never ;
462
+ function throwNotImplementedForNeverValueError ( value : never , sourceNode ?: Node ) : never ;
454
463
/**
455
464
* Throws an error if the actual value does not equal the expected value.
456
465
* @param actual - Actual value.
0 commit comments