UNPKG

ts-simple-ast

Version:

TypeScript compiler wrapper for AST navigation and code generation.

75 lines (74 loc) 3.09 kB
import * as ts from "typescript"; import { Node } from "./../compiler"; import { NotImplementedError } from "./NotImplementedError"; /** * Thows if not a type. * @param value - Value to check the type of. * @param expectedType - Expected type. * @param argName - Argument name. */ export declare function throwIfNotType(value: any, expectedType: string, argName: string): void; /** * Throws if the value is not a string or is whitespace. * @param value - Value to check. * @param argName - Arg name. */ export declare function throwIfNotStringOrWhitespace(value: string, argName: string): void; /** * Throws a NotImplementedError if a node doesn't match the expected syntax kind. * @param node - Node. * @param syntaxKind - Syntax kind that's expected. * @param message - Optional message to throw. */ export declare function throwIfNotSyntaxKind(node: Node, syntaxKind: ts.SyntaxKind, message?: string): void; /** * Throws an ArgumentOutOfRangeError if an argument's value is out of an inclusive range. * @param value - Value. * @param range - Range. * @param argName - Argument name. */ export declare function throwIfOutOfRange(value: number, range: [number, number], argName: string): void; /** * Throws an ArgumentOutOfRangeError if an argument's range value is out of an inclusive range. * * Also throws when the start of the range is greater than the end. * @param actualRange - Range to check. * @param range - Range to check against. * @param argName - Argument name. */ export declare function throwIfRangeOutOfRange(actualRange: [number, number], range: [number, number], argName: string): void; /** * Gets an error saying that a feature is not implemented for a certain syntax kind. * @param syntaxKind - Syntax kind that isn't implemented. */ export declare function getNotImplementedForSyntaxKindError(syntaxKind: ts.SyntaxKind): NotImplementedError; /** * Throws an Argument * @param value * @param argName */ export declare function throwIfNegative(value: number, argName: string): void; /** * Throws when the value is null or undefined. * @param value - Value to check. * @param errorMessage - Error message to throw when not defined. */ export declare function throwIfNullOrUndefined<T>(value: T | undefined, errorMessage: string | (() => string)): T; /** * Throw if the value should have been the never type. * @param value - Value to check. */ export declare function getNotImplementedForNeverValueError(value: never): NotImplementedError; /** * Throws an error if the actual value does not equal the expected value. * @param actual - Actual value. * @param expected - Expected value. * @param description - Message to show in the error. Should be a full sentence that doesn't include the actual and expected values. */ export declare function throwIfNotEqual<T>(actual: T, expected: T, description: string): void; /** * Throws if true. * @param value - Value to check. * @param errorMessage - Error message to throw when true. */ export declare function throwIfTrue(value: boolean | undefined, errorMessage: string): void;