From 05916d3635bfe174b2c296aa35f2092d071530d3 Mon Sep 17 00:00:00 2001 From: Jan Nicklas Date: Sun, 20 Nov 2022 00:25:29 +0100 Subject: [PATCH] feat: allow providing custom error messages to `OrThrow` methods (#1327) Also shows the source of an error. --- deno/common/ts_morph_common.d.ts | 29 +- deno/common/ts_morph_common.js | 83 ++- deno/ts_morph.d.ts | 634 +++++++++--------- deno/ts_morph.js | 514 +++++++------- packages/common/lib/ts-morph-common.d.ts | 29 +- packages/common/src/errors.ts | 106 ++- packages/common/src/tests/errorsTests.ts | 335 +++++---- packages/ts-morph/lib/ts-morph.d.ts | 634 +++++++++--------- .../generation/createDeclarationFile.ts | 2 +- packages/ts-morph/src/Project.ts | 8 +- .../src/compiler/ast/base/AmbientableNode.ts | 6 +- .../src/compiler/ast/base/AsyncableNode.ts | 6 +- .../src/compiler/ast/base/AwaitableNode.ts | 4 +- .../src/compiler/ast/base/BodyableNode.ts | 6 +- .../src/compiler/ast/base/DecoratableNode.ts | 5 +- .../ast/base/DotDotDotTokenableNode.ts | 6 +- .../ast/base/ExclamationTokenableNode.ts | 6 +- .../compiler/ast/base/GeneratorableNode.ts | 6 +- .../ast/base/HeritageClauseableNode.ts | 8 +- .../src/compiler/ast/base/ModifierableNode.ts | 8 +- .../src/compiler/ast/base/ModuledNode.ts | 43 +- .../src/compiler/ast/base/OverrideableNode.ts | 6 +- .../ast/base/QuestionDotTokenableNode.ts | 6 +- .../ast/base/QuestionTokenableNode.ts | 6 +- .../src/compiler/ast/base/ReadonlyableNode.ts | 6 +- .../src/compiler/ast/base/ReturnTypedNode.ts | 6 +- .../src/compiler/ast/base/StaticableNode.ts | 6 +- .../ast/base/TypeElementMemberedNode.ts | 21 +- .../src/compiler/ast/base/TypedNode.ts | 6 +- .../ast/base/export/ExportGetableNode.ts | 12 +- .../InitializerExpressionGetableNode.ts | 14 +- .../compiler/ast/base/name/NameableNode.ts | 12 +- .../compiler/ast/binding/BindingElement.ts | 4 +- .../ast/class/GetAccessorDeclaration.ts | 8 +- .../ast/class/SetAccessorDeclaration.ts | 8 +- .../ast/class/base/AbstractableNode.ts | 6 +- .../class/base/ClassLikeDeclarationBase.ts | 12 +- .../ts-morph/src/compiler/ast/common/Node.ts | 129 ++-- .../src/compiler/ast/decorator/Decorator.ts | 4 +- .../src/compiler/ast/doc/JSDocTemplateTag.ts | 4 +- .../ast/doc/base/JSDocPropertyLikeTag.ts | 6 +- .../doc/base/JSDocTypeExpressionableTag.ts | 6 +- .../ast/expression/ElementAccessExpression.ts | 4 +- .../expressioned/ExpressionableNode.ts | 14 +- .../expressioned/ExpressionedNode.ts | 8 +- .../object/ShorthandPropertyAssignment.ts | 8 +- .../compiler/ast/function/OverloadableNode.ts | 6 +- .../src/compiler/ast/jsx/JsxAttribute.ts | 4 +- .../compiler/ast/module/ExportDeclaration.ts | 8 +- .../compiler/ast/module/ExportSpecifier.ts | 4 +- .../ast/module/ExternalModuleReference.ts | 4 +- .../src/compiler/ast/module/ImportClause.ts | 12 +- .../compiler/ast/module/ImportDeclaration.ts | 16 +- .../ast/module/ImportEqualsDeclaration.ts | 5 +- .../ast/module/ModuleChildableNode.ts | 6 +- .../compiler/ast/statement/BreakStatement.ts | 4 +- .../src/compiler/ast/statement/CatchClause.ts | 4 +- .../ast/statement/ContinueStatement.ts | 4 +- .../compiler/ast/statement/ForStatement.ts | 12 +- .../compiler/ast/statement/StatementedNode.ts | 20 +- .../compiler/ast/statement/TryStatement.ts | 8 +- .../src/compiler/ast/type/ImportTypeNode.ts | 9 +- .../src/compiler/ast/type/MappedTypeNode.ts | 16 +- .../ast/type/TypeParameterDeclaration.ts | 8 +- .../compiler/ast/type/TypePredicateNode.ts | 8 +- .../ast/variable/VariableDeclaration.ts | 4 +- .../ts-morph/src/compiler/symbols/Symbol.ts | 27 +- .../src/compiler/tools/TypeChecker.ts | 4 +- packages/ts-morph/src/compiler/types/Type.ts | 34 +- .../src/compiler/types/TypeParameter.ts | 8 +- packages/ts-morph/src/fileSystem/Directory.ts | 4 +- .../textManipulators/UnwrapTextManipulator.ts | 2 +- .../src/tests/compiler/tools/errors.ts | 62 ++ 73 files changed, 1708 insertions(+), 1395 deletions(-) create mode 100644 packages/ts-morph/src/tests/compiler/tools/errors.ts diff --git a/deno/common/ts_morph_common.d.ts b/deno/common/ts_morph_common.d.ts index 9ae952a99..d2f3c2c4e 100644 --- a/deno/common/ts_morph_common.d.ts +++ b/deno/common/ts_morph_common.d.ts @@ -347,26 +347,35 @@ export declare function Memoize(target: any, propertyName: string, descriptor: T /** Collection of helper functions that can be used to throw errors. */ export declare namespace errors { + /** + * Minimal attributes to show a error message with the node source. + */ + interface Node { + getSourceFile(): { + getFilePath(): StandardizedFilePath; + getFullText(): string; + }; + getStart(): number; + } /** Base error class. */ abstract class BaseError extends Error { - readonly message: string; protected constructor(); } /** Thrown when there is a problem with a provided argument. */ class ArgumentError extends BaseError { - constructor(argName: string, message: string); + constructor(argName: string, message: string, node?: Node); } /** Thrown when an argument is null or whitespace. */ class ArgumentNullOrWhitespaceError extends ArgumentError { - constructor(argName: string); + constructor(argName: string, node?: Node); } /** Thrown when an argument is out of range. */ class ArgumentOutOfRangeError extends ArgumentError { - constructor(argName: string, value: number, range: [number, number]); + constructor(argName: string, value: number, range: [number, number], node?: Node); } /** Thrown when an argument does not match an expected type. */ class ArgumentTypeError extends ArgumentError { - constructor(argName: string, expectedType: string, actualType: string); + constructor(argName: string, expectedType: string, actualType: string, node?: Node); } /** Thrown when a file or directory path was not found. */ class PathNotFoundError extends BaseError { @@ -384,11 +393,11 @@ export declare namespace errors { } /** Thrown when an action was taken that is not allowed. */ class InvalidOperationError extends BaseError { - constructor(message: string); + constructor(message: string, node?: Node); } /** Thrown when a certain behaviour or feature has not been implemented. */ class NotImplementedError extends BaseError { - constructor(message?: string); + constructor(message?: string, node?: Node); } /** Thrown when an operation is not supported. */ class NotSupportedError extends BaseError { @@ -433,7 +442,7 @@ export declare namespace errors { * Gets an error saying that a feature is not implemented for a certain syntax kind. * @param kind - Syntax kind that isn't implemented. */ - function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind): never; + function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind, node?: Node): never; /** * Throws an Argument * @param value @@ -445,12 +454,12 @@ export declare namespace errors { * @param value - Value to check. * @param errorMessage - Error message to throw when not defined. */ - function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string)): T; + function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string), node?: Node): T; /** * Throw if the value should have been the never type. * @param value - Value to check. */ - function throwNotImplementedForNeverValueError(value: never): never; + function throwNotImplementedForNeverValueError(value: never, sourceNode?: Node): never; /** * Throws an error if the actual value does not equal the expected value. * @param actual - Actual value. diff --git a/deno/common/ts_morph_common.js b/deno/common/ts_morph_common.js index 71fa6f812..22220f264 100644 --- a/deno/common/ts_morph_common.js +++ b/deno/common/ts_morph_common.js @@ -319,34 +319,35 @@ function getKindCache() { var errors; (function (errors) { class BaseError extends Error { - constructor(message) { - super(message); - this.message = message; - this.message = message; + constructor(message, node) { + const nodeLocation = node && getPrettyNodeLocation(node); + const messageWithLocation = nodeLocation ? `${message}\n\n${nodeLocation}` : message; + super(messageWithLocation); + this.message = messageWithLocation; } } errors.BaseError = BaseError; class ArgumentError extends BaseError { - constructor(argName, message) { - super(`Argument Error (${argName}): ${message}`); + constructor(argName, message, node) { + super(`Argument Error (${argName}): ${message}`, node); } } errors.ArgumentError = ArgumentError; class ArgumentNullOrWhitespaceError extends ArgumentError { - constructor(argName) { - super(argName, "Cannot be null or whitespace."); + constructor(argName, node) { + super(argName, "Cannot be null or whitespace.", node); } } errors.ArgumentNullOrWhitespaceError = ArgumentNullOrWhitespaceError; class ArgumentOutOfRangeError extends ArgumentError { - constructor(argName, value, range) { - super(argName, `Range is ${range[0]} to ${range[1]}, but ${value} was provided.`); + constructor(argName, value, range, node) { + super(argName, `Range is ${range[0]} to ${range[1]}, but ${value} was provided.`, node); } } errors.ArgumentOutOfRangeError = ArgumentOutOfRangeError; class ArgumentTypeError extends ArgumentError { - constructor(argName, expectedType, actualType) { - super(argName, `Expected type '${expectedType}', but was '${actualType}'.`); + constructor(argName, expectedType, actualType, node) { + super(argName, `Expected type '${expectedType}', but was '${actualType}'.`, node); } } errors.ArgumentTypeError = ArgumentTypeError; @@ -371,14 +372,14 @@ var errors; } errors.FileNotFoundError = FileNotFoundError; class InvalidOperationError extends BaseError { - constructor(message) { - super(message); + constructor(message, node) { + super(message, node); } } errors.InvalidOperationError = InvalidOperationError; class NotImplementedError extends BaseError { - constructor(message = "Not implemented.") { - super(message); + constructor(message = "Not implemented.", node) { + super(message, node); } } errors.NotImplementedError = NotImplementedError; @@ -416,8 +417,8 @@ var errors; throwIfOutOfRange(actualRange[1], range, argName); } errors.throwIfRangeOutOfRange = throwIfRangeOutOfRange; - function throwNotImplementedForSyntaxKindError(kind) { - throw new NotImplementedError(`Not implemented feature for syntax kind '${getSyntaxKindName(kind)}'.`); + function throwNotImplementedForSyntaxKindError(kind, node) { + throw new NotImplementedError(`Not implemented feature for syntax kind '${getSyntaxKindName(kind)}'.`, node); } errors.throwNotImplementedForSyntaxKindError = throwNotImplementedForSyntaxKindError; function throwIfNegative(value, argName) { @@ -425,17 +426,17 @@ var errors; throw new ArgumentError(argName, "Expected a non-negative value."); } errors.throwIfNegative = throwIfNegative; - function throwIfNullOrUndefined(value, errorMessage) { + function throwIfNullOrUndefined(value, errorMessage, node) { if (value == null) - throw new InvalidOperationError(typeof errorMessage === "string" ? errorMessage : errorMessage()); + throw new InvalidOperationError(typeof errorMessage === "string" ? errorMessage : errorMessage(), node); return value; } errors.throwIfNullOrUndefined = throwIfNullOrUndefined; - function throwNotImplementedForNeverValueError(value) { + function throwNotImplementedForNeverValueError(value, sourceNode) { const node = value; if (node != null && typeof node.kind === "number") - return throwNotImplementedForSyntaxKindError(node.kind); - throw new NotImplementedError(`Not implemented value: ${JSON.stringify(value)}`); + return throwNotImplementedForSyntaxKindError(node.kind, sourceNode); + throw new NotImplementedError(`Not implemented value: ${JSON.stringify(value)}`, sourceNode); } errors.throwNotImplementedForNeverValueError = throwNotImplementedForNeverValueError; function throwIfNotEqual(actual, expected, description) { @@ -449,6 +450,42 @@ var errors; } errors.throwIfTrue = throwIfTrue; })(errors || (errors = {})); +function getPrettyNodeLocation(node) { + const source = getSourceLocation(node); + if (!source) + return undefined; + return `${source.filePath}:${source.loc.line}:${source.loc.character}\n` + + `> ${source.loc.line} | ${source.lineText}`; +} +function getSourceLocation(node) { + if (!isNode(node)) + return; + const sourceFile = node.getSourceFile(); + const sourceCode = sourceFile.getFullText(); + const start = node.getStart(); + const lineStart = sourceCode.lastIndexOf("\n", start) + 1; + const nextNewLinePos = sourceCode.indexOf("\n", start); + const lineEnd = nextNewLinePos === -1 ? sourceCode.length : nextNewLinePos; + const textStart = (start - lineStart > 40) ? start - 37 : lineStart; + const textEnd = (lineEnd - textStart > 80) ? textStart + 77 : lineEnd; + let lineText = ""; + if (textStart !== lineStart) + lineText += "..."; + lineText += sourceCode.substring(textStart, textEnd); + if (textEnd !== lineEnd) + lineText += "..."; + return { + filePath: sourceFile.getFilePath(), + loc: { + line: StringUtils.getLineNumberAtPos(sourceCode, start), + character: start - lineStart + 1, + }, + lineText, + }; +} +function isNode(node) { + return typeof node === "object" && node !== null && ("getSourceFile" in node) && ("getStart" in node); +} const CharCodes = { ASTERISK: "*".charCodeAt(0), diff --git a/deno/ts_morph.d.ts b/deno/ts_morph.d.ts index 42fa98f4b..77d9db287 100644 --- a/deno/ts_morph.d.ts +++ b/deno/ts_morph.d.ts @@ -201,7 +201,7 @@ export declare class Directory { /** Gets the directory path's base name. */ getBaseName(): string; /** Gets the parent directory or throws if it doesn't exist or was never added to the project. */ - getParentOrThrow(): Directory; + getParentOrThrow(message?: string | (() => string)): Directory; /** Gets the parent directory if it exists and was added to the project. */ getParent(): Directory | undefined; /** @@ -541,7 +541,7 @@ export declare class Project { * Gets a directory by the specified path or throws if it doesn't exist. * @param dirPath - Path to create the directory at. */ - getDirectoryOrThrow(dirPath: string): Directory; + getDirectoryOrThrow(dirPath: string, message?: string | (() => string)): Directory; /** * Gets a directory by the specified path or returns undefined if it doesn't exist. * @param dirPath - Directory path. @@ -637,7 +637,7 @@ export declare class Project { * Gets the specified ambient module symbol or throws if not found. * @param moduleName - The ambient module name with or without quotes. */ - getAmbientModuleOrThrow(moduleName: string): Symbol; + getAmbientModuleOrThrow(moduleName: string, message?: string | (() => string)): Symbol; /** Gets the ambient module symbols (ex. modules in the @types folder or node_modules). */ getAmbientModules(): Symbol[]; /** Saves all the unsaved source files to the file system and deletes all deleted files. */ @@ -912,7 +912,7 @@ export interface AmbientableNode { /** Gets the declare keyword or undefined if none exists. */ getDeclareKeyword(): Node | undefined; /** Gets the declare keyword or throws if it doesn't exist. */ - getDeclareKeywordOrThrow(): Node; + getDeclareKeywordOrThrow(message?: string | (() => string)): Node; /** Gets if the node is ambient. */ isAmbient(): boolean; /** @@ -973,7 +973,7 @@ export interface AsyncableNode { /** Gets the async keyword or undefined if none exists. */ getAsyncKeyword(): Node | undefined; /** Gets the async keyword or throws if none exists. */ - getAsyncKeywordOrThrow(): Node; + getAsyncKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is async. * @param value - If it should be async or not. @@ -990,7 +990,7 @@ export interface AwaitableNode { /** Gets the await token or undefined if none exists. */ getAwaitKeyword(): Node | undefined; /** Gets the await token or throws if none exists. */ - getAwaitKeywordOrThrow(): Node; + getAwaitKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is awaited. * @param value - If it should be awaited or not. @@ -1022,7 +1022,7 @@ export declare function BodyableNode string)): Node; /** Gets the body if it exists. */ getBody(): Node | undefined; /** Gets the body text without leading whitespace, leading indentation, or trailing whitespace. Returns undefined if there is no body. */ @@ -1107,7 +1107,7 @@ export interface DotDotDotTokenableNode { /** Gets the dot dot dot token (...) if it exists or returns undefined */ getDotDotDotToken(): Node | undefined; /** Gets the dot dot dot token (...) if it exists or throws if not. */ - getDotDotDotTokenOrThrow(): Node; + getDotDotDotTokenOrThrow(message?: string | (() => string)): Node; } declare type DotDotDotTokenableNodeExtensionType = Node | undefined; /** Gets the exclamation token node or throws. */ - getExclamationTokenNodeOrThrow(): Node; + getExclamationTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a exclamation token. * @param value - If it should have a exclamation token or not. @@ -1158,13 +1158,13 @@ export interface ExportGetableNode { /** Gets the export keyword or undefined if none exists. */ getExportKeyword(): Node | undefined; /** Gets the export keyword or throws if none exists. */ - getExportKeywordOrThrow(): Node; + getExportKeywordOrThrow(message?: string | (() => string)): Node; /** If the node has the default keyword. */ hasDefaultKeyword(): boolean; /** Gets the default keyword or undefined if none exists. */ getDefaultKeyword(): Node | undefined; /** Gets the default keyword or throws if none exists. */ - getDefaultKeywordOrThrow(): Node; + getDefaultKeywordOrThrow(message?: string | (() => string)): Node; /** Gets if the node is exported from a namespace, is a default export, or is a named export. */ isExported(): boolean; /** Gets if this node is a default export of a file. */ @@ -1220,7 +1220,7 @@ export interface GeneratorableNode { /** Gets the asterisk token or undefined if none exists. */ getAsteriskToken(): Node | undefined; /** Gets the asterisk token or throws if none exists. */ - getAsteriskTokenOrThrow(): Node; + getAsteriskTokenOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is a generator. * @param value - If it should be a generator or not. @@ -1316,7 +1316,7 @@ export interface InitializerExpressionGetableNode { /** Gets the initializer if it's a certain kind. */ getInitializerIfKind(kind: TKind): KindToExpressionMappings[TKind] | undefined; /** Gets the initializer or throw. */ - getInitializerOrThrow(): Expression; + getInitializerOrThrow(message?: string | (() => string)): Expression; } declare type InitializerExpressionGetableNodeExtensionType = Node>): ExportDeclaration[]; - getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration | undefined; + getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration | undefined; /** * Gets the first export declaration that matches a module specifier, or undefined if it doesn't exist. * @param module - Module specifier to get the export declaration by. @@ -1480,12 +1480,12 @@ export interface ModuledNode { * Gets the first export declaration that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export declaration by. */ - getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration; + getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration; /** * Gets the first export declaration that matches a module specifier, or throws if it doesn't exist. * @param module - Module specifier to get the export declaration by. */ - getExportDeclarationOrThrow(moduleSpecifier: string): ExportDeclaration; + getExportDeclarationOrThrow(moduleSpecifier: string, message?: string | (() => string)): ExportDeclaration; /** Get the export declarations. */ getExportDeclarations(): ExportDeclaration[]; /** @@ -1519,13 +1519,13 @@ export interface ModuledNode { * Gets the first export assignment that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export assignment by. */ - getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean): ExportAssignment; + getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean, message?: string | (() => string)): ExportAssignment; /** Get the file's export assignments. */ getExportAssignments(): ExportAssignment[]; /** Gets the default export symbol. */ getDefaultExportSymbol(): Symbol | undefined; /** Gets the default export symbol or throws if it doesn't exist. */ - getDefaultExportSymbolOrThrow(): Symbol; + getDefaultExportSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the export symbols. */ getExportSymbols(): Symbol[]; /** @@ -1576,11 +1576,11 @@ export interface NameableNodeSpecific { /** Gets the name node if it exists. */ getNameNode(): Identifier | undefined; /** Gets the name node if it exists, or throws. */ - getNameNodeOrThrow(): Identifier; + getNameNodeOrThrow(message?: string | (() => string)): Identifier; /** Gets the name if it exists. */ getName(): string | undefined; /** Gets the name if it exists, or throws. */ - getNameOrThrow(): string; + getNameOrThrow(message?: string | (() => string)): string; /** Removes the name from the node. */ removeName(): this; } @@ -1643,7 +1643,7 @@ export interface OverrideableNode { /** Gets the override keyword or undefined if none exists. */ getOverrideKeyword(): Node | undefined; /** Gets the override keyword or throws if none exists. */ - getOverrideKeywordOrThrow(): Node; + getOverrideKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node has an override keyword. * @param value - If it should have an override keyword or not. @@ -1712,7 +1712,7 @@ export interface QuestionDotTokenableNode { /** Gets the question dot token node or returns undefined if it doesn't exist. */ getQuestionDotTokenNode(): Node | undefined; /** Gets the question dot token node or throws. */ - getQuestionDotTokenNodeOrThrow(): Node; + getQuestionDotTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question dot token. * @param value - If it should have a question dot token or not. @@ -1731,7 +1731,7 @@ export interface QuestionTokenableNode { /** Gets the question token node or returns undefined if it doesn't exist. */ getQuestionTokenNode(): Node | undefined; /** Gets the question token node or throws. */ - getQuestionTokenNodeOrThrow(): Node; + getQuestionTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question token. * @param value - If it should have a question token or not. @@ -1750,7 +1750,7 @@ export interface ReadonlyableNode { /** Gets the readonly keyword, or undefined if none exists. */ getReadonlyKeyword(): Node | undefined; /** Gets the readonly keyword, or throws if none exists. */ - getReadonlyKeywordOrThrow(): Node; + getReadonlyKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if this node is readonly. * @param value - If readonly or not. @@ -1767,7 +1767,7 @@ export interface ReturnTypedNode { /** Gets the return type node or undefined if none exists. */ getReturnTypeNode(): TypeNode | undefined; /** Gets the return type node or throws if none exists. */ - getReturnTypeNodeOrThrow(): TypeNode; + getReturnTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the return type of the node. * @param textOrWriterFunction - Text or writer function to set the return type with. @@ -1826,7 +1826,7 @@ export interface StaticableNode { /** Gets the static keyword, or undefined if none exists. */ getStaticKeyword(): Node | undefined; /** Gets the static keyword, or throws if none exists. */ - getStaticKeywordOrThrow(): Node; + getStaticKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is static. * @param value - If it should be static or not. @@ -1915,7 +1915,7 @@ export interface TypedNode { /** Gets the type node or undefined if none exists. */ getTypeNode(): TypeNode | undefined; /** Gets the type node or throws if none exists. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type. * @param textOrWriterFunction - Text or writer function to set the type with. @@ -2219,7 +2219,7 @@ export declare class ArrayBindingPattern extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BindingElementBase: Constructor & Constructor & Constructor & typeof Node; @@ -2230,7 +2230,7 @@ export declare class BindingElement extends BindingElementBase string)): PropertyName; /** * Gets binding element's property name node or returns undefined if not found. * @@ -2240,7 +2240,7 @@ export declare class BindingElement extends BindingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ObjectBindingPattern extends Node { @@ -2249,7 +2249,7 @@ export declare class ObjectBindingPattern extends Node /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function AbstractableNode>(Base: T): Constructor & T; @@ -2260,7 +2260,7 @@ export interface AbstractableNode { /** Gets the abstract keyword or undefined if it doesn't exist. */ getAbstractKeyword(): Node | undefined; /** Gets the abstract keyword or throws if it doesn't exist. */ - getAbstractKeywordOrThrow(): Node; + getAbstractKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is abstract. * @param isAbstract - If it should be abstract or not. @@ -2285,7 +2285,7 @@ interface ClassLikeDeclarationBaseSpecific { /** Removes the extends expression, if it exists. */ removeExtends(): this; /** Gets the extends expression or throws if it doesn't exist. */ - getExtendsOrThrow(): ExpressionWithTypeArguments; + getExtendsOrThrow(message?: string | (() => string)): ExpressionWithTypeArguments; /** Gets the extends expression or returns undefined if it doesn't exist. */ getExtends(): ExpressionWithTypeArguments | undefined; /** @@ -2701,7 +2701,7 @@ interface ClassLikeDeclarationBaseSpecific { * * Note: Use getBaseTypes if you need to get the mixins. */ - getBaseClassOrThrow(): ClassDeclaration; + getBaseClassOrThrow(message?: string | (() => string)): ClassDeclaration; /** * Gets the base class. * @@ -2743,7 +2743,7 @@ export declare class ClassDeclaration extends ClassDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ClassElement extends Node { @@ -2757,7 +2757,7 @@ export declare class ClassExpression extends ClassExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ClassStaticBlockDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2783,7 +2783,7 @@ export declare class ClassStaticBlockDeclaration extends ClassStaticBlockDeclara /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentClassElement extends ClassElement { @@ -2825,7 +2825,7 @@ export declare class ConstructorDeclaration extends ConstructorDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const GetAccessorDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2839,13 +2839,13 @@ export declare class GetAccessorDeclaration extends GetAccessorDeclarationBase string)): SetAccessorDeclaration; /** Gets the structure equivalent to this node. */ getStructure(): GetAccessorDeclarationStructure; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const MethodDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2884,7 +2884,7 @@ export declare class MethodDeclaration extends MethodDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertyDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2906,7 +2906,7 @@ export declare class PropertyDeclaration extends PropertyDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SetAccessorDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2920,13 +2920,13 @@ export declare class SetAccessorDeclaration extends SetAccessorDeclarationBase string)): GetAccessorDeclaration; /** Gets the structure equivalent to this node. */ getStructure(): SetAccessorDeclarationStructure; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentRange extends TextRange { @@ -3351,7 +3351,7 @@ export declare class Node { */ print(options?: PrintNodeOptions): string; /** Gets the symbol or throws an error if it doesn't exist. */ - getSymbolOrThrow(): Symbol; + getSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the compiler symbol or undefined if it doesn't exist. */ getSymbol(): Symbol | undefined; /** @@ -3368,7 +3368,7 @@ export declare class Node { * WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break. * @param name - Name of the local symbol. */ - getLocalOrThrow(name: string): Symbol; + getLocalOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the specified local symbol by name or returns undefined if it doesn't exist. * @@ -3399,7 +3399,7 @@ export declare class Node { * Gets the node as the specified kind if it is equal to that kind, otherwise throws. * @param kind - Syntax kind. */ - asKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + asKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Returns if the node is the specified kind. * @@ -3416,12 +3416,12 @@ export declare class Node { * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => node is T): T; + getFirstChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => boolean): Node; + getFirstChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the first child by a condition. * @param condition - Condition. @@ -3436,12 +3436,12 @@ export declare class Node { * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => node is T): T; + getLastChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => boolean): Node; + getLastChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the last child by a condition. * @param condition - Condition. @@ -3456,12 +3456,12 @@ export declare class Node { * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => node is T): T; + getFirstDescendantOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => boolean): Node; + getFirstDescendantOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the first descendant by a condition. * @param condition - Condition. @@ -3476,12 +3476,12 @@ export declare class Node { * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => node is T): T; + getPreviousSiblingOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => boolean): Node; + getPreviousSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the previous sibling. * @param condition - Optional condition for getting the previous sibling. @@ -3496,12 +3496,12 @@ export declare class Node { * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => node is T): T; + getNextSiblingOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => boolean): Node; + getNextSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the next sibling. * @param condition - Optional condition for getting the next sibling. @@ -3532,7 +3532,7 @@ export declare class Node { */ getChildAtIndex(index: number): Node; /** Gets the child syntax list or throws if it doesn't exist. */ - getChildSyntaxListOrThrow(): SyntaxList; + getChildSyntaxListOrThrow(message?: string | (() => string)): SyntaxList; /** Gets the child syntax list if it exists. */ getChildSyntaxList(): SyntaxList | undefined; /** @@ -3640,19 +3640,19 @@ export declare class Node { /** Get the node's parent. */ getParent(): Node | undefined; /** Gets the parent or throws an error if it doesn't exist. */ - getParentOrThrow(): Node; + getParentOrThrow(message?: string | (() => string)): Node; /** * Goes up the parents (ancestors) of the node while a condition is true. * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T): T; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T, message?: string | (() => string)): T; /** * Goes up the parents (ancestors) of the node while a condition is true. * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean): Node; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean, message?: string | (() => string)): Node; /** * Goes up the parents (ancestors) of the node while a condition is true. * Returns undefined if the initial parent doesn't match the condition. @@ -3670,7 +3670,7 @@ export declare class Node { * Throws if the initial parent is not the specified syntax kind. * @param kind - Syntax kind to check for. */ - getParentWhileKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getParentWhileKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Goes up the parents (ancestors) of the node while the parent is the specified syntax kind. * Returns undefined if the initial parent is not the specified syntax kind. @@ -3682,7 +3682,7 @@ export declare class Node { /** Gets if this node is in a syntax list. */ isInSyntaxList(): boolean; /** Gets the parent if it's a syntax list or throws an error otherwise. */ - getParentSyntaxListOrThrow(): SyntaxList; + getParentSyntaxListOrThrow(message?: string | (() => string)): SyntaxList; /** Gets the parent if it's a syntax list. */ getParentSyntaxList(): SyntaxList | undefined; /** Gets the child index of this node relative to the parent. */ @@ -3777,7 +3777,7 @@ export declare class Node { * Gets the first child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstChildByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first child by syntax kind. * @param kind - Syntax kind. @@ -3787,7 +3787,7 @@ export declare class Node { * Gets the first child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstChildIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first child if it matches the specified syntax kind. * @param kind - Syntax kind. @@ -3797,7 +3797,7 @@ export declare class Node { * Gets the last child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getLastChildByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the last child by syntax kind. * @param kind - Syntax kind. @@ -3807,7 +3807,7 @@ export declare class Node { * Gets the last child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getLastChildIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the last child if it matches the specified syntax kind. * @param kind - Syntax kind. @@ -3818,7 +3818,7 @@ export declare class Node { * @param index - Child index to get. * @param kind - Expected kind. */ - getChildAtIndexIfKindOrThrow(index: number, kind: TKind): KindToNodeMappings[TKind]; + getChildAtIndexIfKindOrThrow(index: number, kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the child at the specified index if it's the specified kind or returns undefined. * @param index - Child index to get. @@ -3829,12 +3829,12 @@ export declare class Node { * Gets the previous sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getPreviousSiblingIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getPreviousSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the next sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getNextSiblingIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getNextSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the previous sibling if it matches the specified kind. * @param kind - Kind to check. @@ -3846,22 +3846,22 @@ export declare class Node { */ getNextSiblingIfKind(kind: TKind): KindToNodeMappings[TKind] | undefined; /** Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T): T; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T, message?: string | (() => string)): T; /** Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean): Node; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean, message?: string | (() => string)): Node; /** Gets the parent if it matches a certain condition. */ getParentIf(condition: (parent: Node | undefined, node: Node) => parent is T): T | undefined; /** Gets the parent if it matches a certain condition. */ getParentIf(condition: (parent: Node | undefined, node: Node) => boolean): Node | undefined; /** Gets the parent if it's a certain syntax kind or throws. */ - getParentIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getParentIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** Gets the parent if it's a certain syntax kind. */ getParentIfKind(kind: TKind): KindToNodeMappings[TKind] | undefined; /** * Gets the first ancestor by syntax kind or throws if not found. * @param kind - Syntax kind. */ - getFirstAncestorByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstAncestorByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Get the first ancestor by syntax kind. * @param kind - Syntax kind. @@ -3896,7 +3896,7 @@ export declare class Node { * Gets the first descendant by syntax kind or throws. * @param kind - Syntax kind. */ - getFirstDescendantByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstDescendantByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first descendant by syntax kind. * @param kind - Syntax kind. @@ -4532,7 +4532,7 @@ export declare class SyntaxList extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TextRange { @@ -4597,7 +4597,7 @@ export declare class Decorator extends DecoratorBase { */ setIsDecoratorFactory(isDecoratorFactory: boolean): this; /** Gets the call expression if a decorator factory, or throws. */ - getCallExpressionOrThrow(): CallExpression; + getCallExpressionOrThrow(message?: string | (() => string)): CallExpression; /** Gets the call expression if a decorator factory. */ getCallExpression(): CallExpression | undefined; /** Gets the decorator's arguments from its call expression. */ @@ -4680,7 +4680,7 @@ export declare class Decorator extends DecoratorBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function JSDocPropertyLikeTag>(Base: T): Constructor & T; @@ -4689,7 +4689,7 @@ export interface JSDocPropertyLikeTag { /** Gets the type expression node of the JS doc tag if it exists. */ getTypeExpression(): JSDocTypeExpression | undefined; /** Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; /** Gets the name of the JS doc property like tag. */ getName(): string; /** Gets the name node of the JS doc property like tag. */ @@ -4705,7 +4705,7 @@ export interface JSDocTypeExpressionableTag { /** Gets the type expression node of the JS doc tag if it exists. */ getTypeExpression(): JSDocTypeExpression | undefined; /** Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; } declare type JSDocTypeExpressionableTagExtensionType = Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc all type. */ @@ -4787,7 +4787,7 @@ export declare class JSDocAllType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc augments tag node. */ @@ -4795,7 +4795,7 @@ export declare class JSDocAugmentsTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc author tag node. */ @@ -4803,7 +4803,7 @@ export declare class JSDocAuthorTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc callback tag node. */ @@ -4811,7 +4811,7 @@ export declare class JSDocCallbackTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc class tag node. */ @@ -4819,7 +4819,7 @@ export declare class JSDocClassTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc deprecated tag node. */ @@ -4827,7 +4827,7 @@ export declare class JSDocDeprecatedTag extends JSDocTag /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc enum tag node. */ @@ -4835,7 +4835,7 @@ export declare class JSDocEnumTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocFunctionTypeBase: Constructor & typeof JSDocType; @@ -4845,7 +4845,7 @@ export declare class JSDocFunctionType extends JSDocFunctionTypeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc implements tag node. */ @@ -4853,7 +4853,7 @@ export declare class JSDocImplementsTag extends JSDocTag /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link node. */ @@ -4861,7 +4861,7 @@ export declare class JSDocLink extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link code node. */ @@ -4869,7 +4869,7 @@ export declare class JSDocLinkCode extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link plain node. */ @@ -4877,7 +4877,7 @@ export declare class JSDocLinkPlain extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc member name node. */ @@ -4885,7 +4885,7 @@ export declare class JSDocMemberName extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc namepath type. */ @@ -4895,7 +4895,7 @@ export declare class JSDocNamepathType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc name reference. */ @@ -4905,7 +4905,7 @@ export declare class JSDocNameReference extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc non-nullable type. */ @@ -4916,7 +4916,7 @@ export declare class JSDocNonNullableType extends JSDocType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc nullable type. */ @@ -4927,7 +4927,7 @@ export declare class JSDocNullableType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc optional type. */ @@ -4937,7 +4937,7 @@ export declare class JSDocOptionalType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc override tag node. */ @@ -4945,7 +4945,7 @@ export declare class JSDocOverrideTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocParameterTagBase: Constructor & typeof JSDocTag; @@ -4955,7 +4955,7 @@ export declare class JSDocParameterTag extends JSDocParameterTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc private tag node. */ @@ -4963,7 +4963,7 @@ export declare class JSDocPrivateTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocPropertyTagBase: Constructor & typeof JSDocTag; @@ -4973,7 +4973,7 @@ export declare class JSDocPropertyTag extends JSDocPropertyTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc protected tag node. */ @@ -4981,7 +4981,7 @@ export declare class JSDocProtectedTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc public tag node. */ @@ -4989,7 +4989,7 @@ export declare class JSDocPublicTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc readonly tag node. */ @@ -4997,7 +4997,7 @@ export declare class JSDocReadonlyTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocReturnTagBase: Constructor & typeof JSDocTag; @@ -5007,7 +5007,7 @@ export declare class JSDocReturnTag extends JSDocReturnTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocSeeTagBase: Constructor & typeof JSDocTag; @@ -5017,7 +5017,7 @@ export declare class JSDocSeeTag extends JSDocSeeTagBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc signature node. */ @@ -5027,7 +5027,7 @@ export declare class JSDocSignature extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocTagBase: typeof Node; @@ -5081,11 +5081,11 @@ export declare class JSDocTemplateTag extends JSDocTemplateTagBase string)): JSDocTypeExpression; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc text node. */ @@ -5093,7 +5093,7 @@ export declare class JSDocText extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocThisTagBase: Constructor & typeof JSDocTag; @@ -5103,7 +5103,7 @@ export declare class JSDocThisTag extends JSDocThisTagBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type node. */ @@ -5115,7 +5115,7 @@ export declare class JSDocTypedefTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type expression node. */ @@ -5125,7 +5125,7 @@ export declare class JSDocTypeExpression extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type literal. */ @@ -5137,7 +5137,7 @@ export declare class JSDocTypeLiteral extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type tag node. */ @@ -5147,7 +5147,7 @@ export declare class JSDocTypeTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc unknown tag node. */ @@ -5155,7 +5155,7 @@ export declare class JSDocUnknownTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc unknown type. */ @@ -5163,7 +5163,7 @@ export declare class JSDocUnknownType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc variadic type. */ @@ -5173,7 +5173,7 @@ export declare class JSDocVariadicType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentEnumMember extends Node { @@ -5268,7 +5268,7 @@ export declare class EnumDeclaration extends EnumDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const EnumMemberBase: Constructor & Constructor & Constructor & typeof Node; @@ -5296,7 +5296,7 @@ export declare class EnumMember extends EnumMemberBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ArrayDestructuringAssignmentBase: typeof AssignmentExpression; @@ -5307,7 +5307,7 @@ export declare class ArrayDestructuringAssignment extends ArrayDestructuringAssi /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ArrayLiteralExpression extends PrimaryExpression { @@ -5360,7 +5360,7 @@ export declare class ArrayLiteralExpression extends PrimaryExpression; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AsExpressionBase: Constructor & Constructor & typeof Expression; @@ -5369,7 +5369,7 @@ export declare class AsExpression extends AsExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssignmentExpressionBase: typeof BinaryExpression; @@ -5385,7 +5385,7 @@ export declare class AwaitExpression extends AwaitExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BinaryExpressionBase: typeof Expression; @@ -5414,7 +5414,7 @@ export declare class CommaListExpression extends CommaListExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ConditionalExpressionBase: typeof Expression; @@ -5433,7 +5433,7 @@ export declare class ConditionalExpression extends ConditionalExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DeleteExpressionBase: Constructor & typeof UnaryExpression; @@ -5442,7 +5442,7 @@ export declare class DeleteExpression extends DeleteExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ElementAccessExpressionBase: Constructor & Constructor & typeof MemberExpression; @@ -5451,7 +5451,7 @@ export declare class ElementAccessExpression; + getArgumentExpressionOrThrow(message?: string | (() => string)): Expression; } export declare class Expression extends Node { @@ -5465,7 +5465,7 @@ export interface ExpressionableNode { /** Gets the expression if it exists or returns undefined. */ getExpression(): Expression | undefined; /** Gets the expression if it exists or throws. */ - getExpressionOrThrow(): Expression; + getExpressionOrThrow(message?: string | (() => string)): Expression; /** Gets the expression if it is of the specified syntax kind or returns undefined. */ getExpressionIfKind(kind: TKind): KindToExpressionMappings[TKind] | undefined; /** Gets the expression if it is of the specified syntax kind or throws. */ @@ -5543,7 +5543,7 @@ export declare class ImportExpression extends ImportExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class LeftHandSideExpression extends UpdateExpression { @@ -5565,7 +5565,7 @@ export declare class MetaProperty extends MetaPropertyBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NewExpressionBase: Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -5574,7 +5574,7 @@ export declare class NewExpression extends NewExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NonNullExpressionBase: Constructor & typeof LeftHandSideExpression; @@ -5583,7 +5583,7 @@ export declare class NonNullExpression extends NonNullExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentObjectLiteralElement extends ObjectLiteralElement { @@ -5597,7 +5597,7 @@ export declare class ObjectDestructuringAssignment extends ObjectDestructuringAs /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ObjectLiteralElement extends Node { @@ -5797,7 +5797,7 @@ export declare class ObjectLiteralExpression extends ObjectLiteralExpressionBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertyAssignmentBase: Constructor & Constructor & Constructor & typeof ObjectLiteralElement; @@ -5824,7 +5824,7 @@ export declare class PropertyAssignment extends PropertyAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ShorthandPropertyAssignmentBase: Constructor & Constructor & Constructor & typeof ObjectLiteralElement; @@ -5833,11 +5833,11 @@ export declare class ShorthandPropertyAssignment extends ShorthandPropertyAssign /** Gets if the shorthand property assignment has an object assignment initializer. */ hasObjectAssignmentInitializer(): boolean; /** Gets the object assignment initializer or throws if it doesn't exist. */ - getObjectAssignmentInitializerOrThrow(): Expression; + getObjectAssignmentInitializerOrThrow(message?: string | (() => string)): Expression; /** Gets the object assignment initializer if it exists. */ getObjectAssignmentInitializer(): Expression | undefined; /** Gets the equals token or throws if it doesn't exist. */ - getEqualsTokenOrThrow(): Node; + getEqualsTokenOrThrow(message?: string | (() => string)): Node; /** Gets the equals token if it exists. */ getEqualsToken(): Node | undefined; /** @@ -5863,7 +5863,7 @@ export declare class ShorthandPropertyAssignment extends ShorthandPropertyAssign /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SpreadAssignmentBase: Constructor & typeof ObjectLiteralElement; @@ -5879,7 +5879,7 @@ export declare class SpreadAssignment extends SpreadAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const OmittedExpressionBase: typeof Expression; @@ -5888,7 +5888,7 @@ export declare class OmittedExpression extends OmittedExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ParenthesizedExpressionBase: Constructor & typeof Expression; @@ -5897,7 +5897,7 @@ export declare class ParenthesizedExpression extends ParenthesizedExpressionBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PartiallyEmittedExpressionBase: Constructor & typeof Expression; @@ -5906,7 +5906,7 @@ export declare class PartiallyEmittedExpression extends PartiallyEmittedExpressi /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PostfixUnaryExpressionBase: typeof UnaryExpression; @@ -5919,7 +5919,7 @@ export declare class PostfixUnaryExpression extends PostfixUnaryExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PrefixUnaryExpressionBase: typeof UnaryExpression; @@ -5932,7 +5932,7 @@ export declare class PrefixUnaryExpression extends PrefixUnaryExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class PrimaryExpression extends MemberExpression { @@ -5949,7 +5949,7 @@ export declare class SatisfiesExpression extends SatisfiesExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SpreadElementBase: Constructor & typeof Expression; @@ -5958,7 +5958,7 @@ export declare class SpreadElement extends SpreadElementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperElementAccessExpressionBase: Constructor & typeof ElementAccessExpression; @@ -5967,7 +5967,7 @@ export declare class SuperElementAccessExpression extends SuperElementAccessExpr /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperExpressionBase: typeof PrimaryExpression; @@ -5976,7 +5976,7 @@ export declare class SuperExpression extends SuperExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperPropertyAccessExpressionBase: Constructor & typeof PropertyAccessExpression; @@ -5985,7 +5985,7 @@ export declare class SuperPropertyAccessExpression extends SuperPropertyAccessEx /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ThisExpressionBase: typeof PrimaryExpression; @@ -5994,7 +5994,7 @@ export declare class ThisExpression extends ThisExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeAssertionBase: Constructor & Constructor & typeof UnaryExpression; @@ -6003,7 +6003,7 @@ export declare class TypeAssertion extends TypeAssertionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeOfExpressionBase: Constructor & typeof UnaryExpression; @@ -6012,7 +6012,7 @@ export declare class TypeOfExpression extends TypeOfExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class UnaryExpression extends Expression { @@ -6027,7 +6027,7 @@ export declare class VoidExpression extends VoidExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const YieldExpressionBase: Constructor & Constructor & typeof Expression; @@ -6036,7 +6036,7 @@ export declare class YieldExpression extends YieldExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ArrowFunctionBase: Constructor & Constructor & Constructor & Constructor & typeof Expression; @@ -6047,7 +6047,7 @@ export declare class ArrowFunction extends ArrowFunctionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -6088,7 +6088,7 @@ export declare class FunctionDeclaration extends FunctionDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionExpressionBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -6097,7 +6097,7 @@ export declare class FunctionExpression extends FunctionExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function FunctionLikeDeclaration>(Base: T): Constructor & T; @@ -6115,7 +6115,7 @@ export interface OverloadableNode { /** Gets the implementation or undefined if it doesn't exist. */ getImplementation(): this | undefined; /** Gets the implementation or throws if it doesn't exist. */ - getImplementationOrThrow(): this; + getImplementationOrThrow(message?: string | (() => string)): this; /** Gets if this is not the implementation. */ isOverload(): boolean; /** Gets if this is the implementation. */ @@ -6164,7 +6164,7 @@ export declare class ParameterDeclaration extends ParameterDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class HeritageClause extends Node { @@ -6185,7 +6185,7 @@ export declare class HeritageClause extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CallSignatureDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6201,7 +6201,7 @@ export declare class CallSignatureDeclaration extends CallSignatureDeclarationBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentTypeElement extends TypeElement { @@ -6220,7 +6220,7 @@ export declare class ConstructSignatureDeclaration extends ConstructSignatureDec /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IndexSignatureDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6254,7 +6254,7 @@ export declare class IndexSignatureDeclaration extends IndexSignatureDeclaration /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const InterfaceDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -6280,7 +6280,7 @@ export declare class InterfaceDeclaration extends InterfaceDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const MethodSignatureBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6296,7 +6296,7 @@ export declare class MethodSignature extends MethodSignatureBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertySignatureBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6312,7 +6312,7 @@ export declare class PropertySignature extends PropertySignatureBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeElement extends Node { @@ -6372,7 +6372,7 @@ declare const JsxAttributeBase: Constructor & typeof Node; export declare class JsxAttribute extends JsxAttributeBase { /** Gets the JSX attribute's initializer or throws if it doesn't exist. */ - getInitializerOrThrow(): StringLiteral | JsxElement | JsxSelfClosingElement | JsxFragment | JsxExpression; + getInitializerOrThrow(message?: string | (() => string)): StringLiteral | JsxElement | JsxSelfClosingElement | JsxFragment | JsxExpression; /** Gets the JSX attribute's initializer or returns undefined if it doesn't exist. */ getInitializer(): JsxElement | JsxExpression | JsxFragment | JsxSelfClosingElement | StringLiteral | undefined; /** @@ -6395,7 +6395,7 @@ export declare class JsxAttribute extends JsxAttributeBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxClosingElementBase: Constructor & typeof Node; @@ -6404,14 +6404,14 @@ export declare class JsxClosingElement extends JsxClosingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxClosingFragment extends Expression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxElementBase: typeof PrimaryExpression; @@ -6443,7 +6443,7 @@ export declare class JsxElement extends JsxElementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxExpressionBase: Constructor & Constructor & typeof Expression; @@ -6452,7 +6452,7 @@ export declare class JsxExpression extends JsxExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxFragment extends PrimaryExpression { @@ -6465,7 +6465,7 @@ export declare class JsxFragment extends PrimaryExpression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxOpeningElementBase: Constructor & Constructor & typeof Expression; @@ -6474,14 +6474,14 @@ export declare class JsxOpeningElement extends JsxOpeningElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxOpeningFragment extends Expression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxSelfClosingElementBase: Constructor & Constructor & typeof PrimaryExpression; @@ -6497,7 +6497,7 @@ export declare class JsxSelfClosingElement extends JsxSelfClosingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxSpreadAttributeBase: Constructor & typeof Node; @@ -6515,7 +6515,7 @@ export declare class JsxSpreadAttribute extends JsxSpreadAttributeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxTextBase: Constructor & typeof Node; @@ -6526,7 +6526,7 @@ export declare class JsxText extends JsxTextBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export interface ImplementedKindToNodeMappings { @@ -6816,7 +6816,7 @@ export declare class BigIntLiteral extends BigIntLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TrueLiteralBase: typeof PrimaryExpression; @@ -6834,7 +6834,7 @@ export declare class TrueLiteral extends TrueLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FalseLiteralBase: typeof PrimaryExpression; @@ -6852,7 +6852,7 @@ export declare class FalseLiteral extends FalseLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NullLiteralBase: typeof PrimaryExpression; @@ -6861,7 +6861,7 @@ export declare class NullLiteral extends NullLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NumericLiteralBase: typeof LiteralExpression; @@ -6877,7 +6877,7 @@ export declare class NumericLiteral extends NumericLiteralBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** Quote type for a string literal. */ @@ -6907,7 +6907,7 @@ export declare class RegularExpressionLiteral extends RegularExpressionLiteralBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const StringLiteralBase: typeof LiteralExpression; @@ -6929,7 +6929,7 @@ export declare class StringLiteral extends StringLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NoSubstitutionTemplateLiteralBase: typeof LiteralExpression; @@ -6948,7 +6948,7 @@ export declare class NoSubstitutionTemplateLiteral extends NoSubstitutionTemplat /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TaggedTemplateExpression extends MemberExpression { @@ -6964,7 +6964,7 @@ export declare class TaggedTemplateExpression extends MemberExpression; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateExpressionBase: typeof PrimaryExpression; @@ -6985,7 +6985,7 @@ export declare class TemplateExpression extends TemplateExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateHeadBase: Constructor & typeof Node; @@ -6994,7 +6994,7 @@ export declare class TemplateHead extends TemplateHeadBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateMiddleBase: Constructor & typeof Node; @@ -7003,7 +7003,7 @@ export declare class TemplateMiddle extends TemplateMiddleBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateSpanBase: Constructor & typeof Node; @@ -7014,7 +7014,7 @@ export declare class TemplateSpan extends TemplateSpanBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateTailBase: Constructor & typeof Node; @@ -7023,7 +7023,7 @@ export declare class TemplateTail extends TemplateTailBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssertClauseBase: typeof Node; @@ -7038,7 +7038,7 @@ export declare class AssertClause extends AssertClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssertEntryBase: Constructor & typeof Node; @@ -7053,7 +7053,7 @@ export declare class AssertEntry extends AssertEntryBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportAssignmentBase: Constructor & typeof Statement; @@ -7080,7 +7080,7 @@ export declare class ExportAssignment extends ExportAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportDeclarationBase: typeof Statement; @@ -7093,7 +7093,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase string)): NamespaceExport; /** Sets the namespace export name. */ setNamespaceExport(name: string): this; /** @@ -7111,7 +7111,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase string)): SourceFile; /** Gets the source file referenced in the module specifier. */ getModuleSpecifierSourceFile(): SourceFile | undefined; /** Gets if the module specifier starts with `./` or `../`. */ @@ -7164,7 +7164,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportSpecifierBase: typeof Node; @@ -7202,7 +7202,7 @@ export declare class ExportSpecifier extends ExportSpecifierBase string)): Symbol; /** Gets the local target symbol of the export specifier or undefined if it doesn't exist. */ getLocalTargetSymbol(): Symbol | undefined; /** Gets all the declarations referenced by the export specifier. */ @@ -7219,14 +7219,14 @@ export declare class ExportSpecifier extends ExportSpecifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExternalModuleReferenceBase: Constructor & typeof Node; export declare class ExternalModuleReference extends ExternalModuleReferenceBase { /** Gets the source file referenced or throws if it can't find it. */ - getReferencedSourceFileOrThrow(): SourceFile; + getReferencedSourceFileOrThrow(message?: string | (() => string)): SourceFile; /** Gets if the external module reference is relative. */ isRelative(): boolean; /** Gets the source file referenced or returns undefined if it can't find it. */ @@ -7234,7 +7234,7 @@ export declare class ExternalModuleReference extends ExternalModuleReferenceBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportClauseBase: typeof Node; @@ -7245,15 +7245,15 @@ export declare class ImportClause extends ImportClauseBase { /** Sets if this import declaration is type only. */ setIsTypeOnly(value: boolean): this; /** Gets the default import or throws if it doesn't exit. */ - getDefaultImportOrThrow(): Identifier; + getDefaultImportOrThrow(message?: string | (() => string)): Identifier; /** Gets the default import or returns undefined if it doesn't exist. */ getDefaultImport(): Identifier | undefined; /** Gets the named bindings of the import clause or throws if it doesn't exist. */ - getNamedBindingsOrThrow(): NamespaceImport | NamedImports; + getNamedBindingsOrThrow(message?: string | (() => string)): NamespaceImport | NamedImports; /** Gets the named bindings of the import clause or returns undefined if it doesn't exist. */ getNamedBindings(): NamespaceImport | NamedImports | undefined; /** Gets the namespace import if it exists or throws. */ - getNamespaceImportOrThrow(): Identifier; + getNamespaceImportOrThrow(message?: string | (() => string)): Identifier; /** Gets the namespace import identifier, if it exists. */ getNamespaceImport(): Identifier | undefined; /** Gets the namespace import identifier, if it exists. */ @@ -7261,7 +7261,7 @@ export declare class ImportClause extends ImportClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportDeclarationBase: typeof Statement; @@ -7286,7 +7286,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): SourceFile; /** Gets the source file referenced in the module specifier or returns undefined if it can't find it. */ getModuleSpecifierSourceFile(): SourceFile | undefined; /** Gets if the module specifier starts with `./` or `../`. */ @@ -7303,7 +7303,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): Identifier; /** Gets the default import or returns undefined if it doesn't exist. */ getDefaultImport(): Identifier | undefined; /** @@ -7317,7 +7317,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): Identifier; /** Gets the namespace import identifier, if it exists. */ getNamespaceImport(): Identifier | undefined; /** @@ -7350,7 +7350,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): ImportClause; /** Gets the import clause or returns undefined if it doesn't exist. */ getImportClause(): ImportClause | undefined; /** Sets the elements in an assert clause. */ @@ -7367,7 +7367,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportEqualsDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -7392,13 +7392,13 @@ export declare class ImportEqualsDeclaration extends ImportEqualsDeclarationBase */ setExternalModuleReference(sourceFile: SourceFile): this; /** Gets the source file referenced in the external module reference or throws if it doesn't exist. */ - getExternalModuleReferenceSourceFileOrThrow(): SourceFile; + getExternalModuleReferenceSourceFileOrThrow(message?: string | (() => string)): SourceFile; /** Gets the source file referenced in the external module reference or returns undefined if it doesn't exist. */ getExternalModuleReferenceSourceFile(): SourceFile | undefined; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportSpecifierBase: typeof Node; @@ -7450,7 +7450,7 @@ export declare class ImportSpecifier extends ImportSpecifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ModuleBlockBase: Constructor & typeof Statement; @@ -7459,7 +7459,7 @@ export declare class ModuleBlock extends ModuleBlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function ModuleChildableNode>(Base: T): Constructor & T; @@ -7468,7 +7468,7 @@ export interface ModuleChildableNode { /** Gets the parent module declaration or undefined if it doesn't exist. */ getParentModule(): ModuleDeclaration | undefined; /** Gets the parent module declaration or throws if it doesn't exist. */ - getParentModuleOrThrow(): ModuleDeclaration; + getParentModuleOrThrow(message?: string | (() => string)): ModuleDeclaration; } declare type ModuleChildableNodeExtensionType = Node; @@ -7515,7 +7515,7 @@ export declare class ModuleDeclaration extends ModuleDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare enum ModuleDeclarationKind { @@ -7532,7 +7532,7 @@ export declare class NamedExports extends NamedExportsBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamedImportsBase: typeof Node; @@ -7543,7 +7543,7 @@ export declare class NamedImports extends NamedImportsBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamespaceExportBase: Constructor & typeof Node; @@ -7558,7 +7558,7 @@ export declare class NamespaceExport extends NamespaceExportBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamespaceImportBase: Constructor & typeof Node; @@ -7573,7 +7573,7 @@ export declare class NamespaceImport extends NamespaceImportBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class FileReference extends TextRange { @@ -7890,7 +7890,7 @@ export declare class SourceFile extends SourceFileBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare function CommonIdentifierBase>(Base: T): Constructor & T; @@ -7919,7 +7919,7 @@ export declare class ComputedPropertyName extends ComputedPropertyNameBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IdentifierBase: Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -7934,7 +7934,7 @@ export declare class Identifier extends IdentifierBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PrivateIdentifierBase: Constructor & Constructor & Constructor & typeof Node; @@ -7943,7 +7943,7 @@ export declare class PrivateIdentifier extends PrivateIdentifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class QualifiedName extends Node { @@ -7954,7 +7954,7 @@ export declare class QualifiedName extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BlockBase: Constructor & Constructor & typeof Statement; @@ -7963,18 +7963,18 @@ export declare class Block extends BlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class BreakStatement extends Statement { /** Gets this break statement's label or undefined if it does not exist. */ getLabel(): Identifier | undefined; /** Gets this break statement's label or throw if it does not exist. */ - getLabelOrThrow(): Identifier; + getLabelOrThrow(message?: string | (() => string)): Identifier; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CaseBlockBase: Constructor & typeof Node; @@ -7995,7 +7995,7 @@ export declare class CaseBlock extends CaseBlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CaseClauseBase: Constructor & Constructor & Constructor & Constructor & typeof Node; @@ -8006,7 +8006,7 @@ export declare class CaseClause extends CaseClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CatchClauseBase: typeof Node; @@ -8017,11 +8017,11 @@ export declare class CatchClause extends CatchClauseBase { /** Gets this catch clause's variable declaration or undefined if none exists. */ getVariableDeclaration(): VariableDeclaration | undefined; /** Gets this catch clause's variable declaration or throws if none exists. */ - getVariableDeclarationOrThrow(): VariableDeclaration; + getVariableDeclarationOrThrow(message?: string | (() => string)): VariableDeclaration; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentStatement extends Statement { @@ -8031,11 +8031,11 @@ export declare class ContinueStatement extends Statement { /** Gets this continue statement's label or undefined if it does not exist. */ getLabel(): Identifier | undefined; /** Gets this continue statement's label or throw if it does not exist. */ - getLabelOrThrow(): Identifier; + getLabelOrThrow(message?: string | (() => string)): Identifier; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DebuggerStatementBase: typeof Statement; @@ -8044,7 +8044,7 @@ export declare class DebuggerStatement extends DebuggerStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DefaultClauseBase: Constructor & Constructor & typeof Node; @@ -8055,7 +8055,7 @@ export declare class DefaultClause extends DefaultClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DoStatementBase: Constructor & typeof IterationStatement; @@ -8064,7 +8064,7 @@ export declare class DoStatement extends DoStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const EmptyStatementBase: typeof Statement; @@ -8073,7 +8073,7 @@ export declare class EmptyStatement extends EmptyStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExpressionStatementBase: Constructor & Constructor & typeof Statement; @@ -8082,7 +8082,7 @@ export declare class ExpressionStatement extends ExpressionStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForInStatementBase: Constructor & typeof IterationStatement; @@ -8093,7 +8093,7 @@ export declare class ForInStatement extends ForInStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForOfStatementBase: Constructor & Constructor & typeof IterationStatement; @@ -8104,7 +8104,7 @@ export declare class ForOfStatement extends ForOfStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForStatementBase: typeof IterationStatement; @@ -8113,19 +8113,19 @@ export declare class ForStatement extends ForStatementBase { /** Gets this for statement's initializer or undefined if none exists. */ getInitializer(): VariableDeclarationList | Expression | undefined; /** Gets this for statement's initializer or throws if none exists. */ - getInitializerOrThrow(): Expression | VariableDeclarationList; + getInitializerOrThrow(message?: string | (() => string)): Expression | VariableDeclarationList; /** Gets this for statement's condition or undefined if none exists. */ getCondition(): Expression | undefined; /** Gets this for statement's condition or throws if none exists. */ - getConditionOrThrow(): Expression; + getConditionOrThrow(message?: string | (() => string)): Expression; /** Gets this for statement's incrementor. */ getIncrementor(): Expression | undefined; /** Gets this for statement's incrementor or throws if none exists. */ - getIncrementorOrThrow(): Expression; + getIncrementorOrThrow(message?: string | (() => string)): Expression; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IfStatementBase: Constructor & typeof Statement; @@ -8140,7 +8140,7 @@ export declare class IfStatement extends IfStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IterationStatement extends Statement { @@ -8158,7 +8158,7 @@ export declare class LabeledStatement extends LabeledStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NotEmittedStatementBase: typeof Statement; @@ -8167,7 +8167,7 @@ export declare class NotEmittedStatement extends NotEmittedStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ReturnStatementBase: Constructor & typeof Statement; @@ -8176,7 +8176,7 @@ export declare class ReturnStatement extends ReturnStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const StatementBase: Constructor & typeof Node; @@ -8607,7 +8607,7 @@ export declare class SwitchStatement extends SwitchStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ThrowStatementBase: Constructor & typeof Statement; @@ -8616,7 +8616,7 @@ export declare class ThrowStatement extends ThrowStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TryStatementBase: typeof Statement; @@ -8627,15 +8627,15 @@ export declare class TryStatement extends TryStatementBase { /** Gets this try statement's catch clause or undefined if none exists. */ getCatchClause(): CatchClause | undefined; /** Gets this try statement's catch clause or throws if none exists. */ - getCatchClauseOrThrow(): CatchClause; + getCatchClauseOrThrow(message?: string | (() => string)): CatchClause; /** Gets this try statement's finally block or undefined if none exists. */ getFinallyBlock(): Block | undefined; /** Gets this try statement's finally block or throws if none exists. */ - getFinallyBlockOrThrow(): Block; + getFinallyBlockOrThrow(message?: string | (() => string)): Block; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const VariableStatementBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -8686,7 +8686,7 @@ export declare class VariableStatement extends VariableStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const WhileStatementBase: Constructor & typeof IterationStatement; @@ -8695,7 +8695,7 @@ export declare class WhileStatement extends WhileStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const WithStatementBase: Constructor & typeof Statement; @@ -8706,7 +8706,7 @@ export declare class WithStatement extends WithStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ArrayTypeNode extends TypeNode { @@ -8715,7 +8715,7 @@ export declare class ArrayTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ConditionalTypeNode extends TypeNode { @@ -8746,7 +8746,7 @@ export declare class ConditionalTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ConstructorTypeNodeBase: Constructor & Constructor & typeof FunctionOrConstructorTypeNodeBase; @@ -8755,7 +8755,7 @@ export declare class ConstructorTypeNode extends ConstructorTypeNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExpressionWithTypeArgumentsBase: Constructor & typeof NodeWithTypeArguments; @@ -8764,7 +8764,7 @@ export declare class ExpressionWithTypeArguments extends ExpressionWithTypeArgum /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionOrConstructorTypeNodeBaseBase: Constructor & typeof TypeNode; @@ -8778,7 +8778,7 @@ export declare class FunctionTypeNode extends FunctionTypeNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ImportTypeAssertionContainer extends Node { @@ -8788,7 +8788,7 @@ export declare class ImportTypeAssertionContainer extends Node; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ImportTypeNode extends NodeWithTypeArguments { @@ -8805,17 +8805,17 @@ export declare class ImportTypeNode extends NodeWithTypeArguments string)): EntityName; /** Gets the qualifier of the import type if it exists or returns undefined. */ getQualifier(): EntityName | undefined; /** Gets the import type assertion container if it exists. */ getAssertions(): ImportTypeAssertionContainer | undefined; /** Gets the import type assertion container if it exists or throws. */ - getAssertionsOrThrow(): ImportTypeAssertionContainer; + getAssertionsOrThrow(message?: string | (() => string)): ImportTypeAssertionContainer; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IndexedAccessTypeNode extends TypeNode { @@ -8834,7 +8834,7 @@ export declare class IndexedAccessTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class InferTypeNode extends TypeNode { @@ -8847,7 +8847,7 @@ export declare class InferTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IntersectionTypeNode extends TypeNode { @@ -8856,7 +8856,7 @@ export declare class IntersectionTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class LiteralTypeNode extends TypeNode { @@ -8865,32 +8865,32 @@ export declare class LiteralTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class MappedTypeNode extends TypeNode { /** Gets the mapped type node's name type node if any. */ getNameTypeNode(): TypeNode | undefined; /** Gets the mapped type node's name type node or throws if it doesn't exist. */ - getNameTypeNodeOrThrow(): TypeNode; + getNameTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** Gets the mapped type's readonly token. */ getReadonlyToken(): Node | Node | Node | undefined; /** Gets the mapped type's readonly token or throws if not exist. */ - getReadonlyTokenOrThrow(): Node | Node | Node; + getReadonlyTokenOrThrow(message?: string | (() => string)): Node | Node | Node; /** Gets the mapped type's question token. */ getQuestionToken(): Node | Node | Node | undefined; /** Gets the mapped type's question token or throws if not exist. */ - getQuestionTokenOrThrow(): Node | Node | Node; + getQuestionTokenOrThrow(message?: string | (() => string)): Node | Node | Node; /** Gets the mapped type node's type parameter. */ getTypeParameter(): TypeParameterDeclaration; /** Gets the mapped type node's type node if it exists or returns undefined when not. */ getTypeNode(): TypeNode | undefined; /** Gets the mapped type node's type node if it exists or throws when undefined. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamedTupleMemberBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeNode; @@ -8908,7 +8908,7 @@ export declare class NamedTupleMember extends NamedTupleMemberBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ParenthesizedTypeNode extends TypeNode { @@ -8922,7 +8922,7 @@ export declare class ParenthesizedTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TemplateLiteralTypeNode extends TypeNode { @@ -8941,14 +8941,14 @@ export declare class TemplateLiteralTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ThisTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TupleTypeNode extends TypeNode { @@ -8957,7 +8957,7 @@ export declare class TupleTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeAliasDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -8973,7 +8973,7 @@ export declare class TypeAliasDeclaration extends TypeAliasDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeLiteralNodeBase: Constructor & typeof TypeNode; @@ -8982,7 +8982,7 @@ export declare class TypeLiteralNode extends TypeLiteralNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeNode extends Node { @@ -9001,7 +9001,7 @@ export declare class TypeOperatorTypeNode extends TypeNode /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** Variance of the type parameter. */ @@ -9022,7 +9022,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** Gets the constraint of the type parameter. */ getConstraint(): TypeNode | undefined; /** Gets the constraint of the type parameter or throws if it doesn't exist. */ - getConstraintOrThrow(): TypeNode; + getConstraintOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type parameter constraint. * @param text - Text to set as the constraint. @@ -9033,7 +9033,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** Gets the default node of the type parameter. */ getDefault(): TypeNode | undefined; /** Gets the default node of the type parameter or throws if it doesn't exist. */ - getDefaultOrThrow(): TypeNode; + getDefaultOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type parameter default type node. * @param text - Text to set as the default type node. @@ -9057,7 +9057,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** @@ -9075,15 +9075,15 @@ export declare class TypePredicateNode extends TypeNode { /** Gets the asserts modifier if it exists. */ getAssertsModifier(): Node | undefined; /** Gets the asserts modifier if it exists or throws otherwise. */ - getAssertsModifierOrThrow(): Node; + getAssertsModifierOrThrow(message?: string | (() => string)): Node; /** Gets the type name if it exists or returns undefined when it asserts a condition. */ getTypeNode(): TypeNode | undefined; /** Gets the type name if it exists or throws when it asserts a condition. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeQueryNode extends NodeWithTypeArguments { @@ -9092,7 +9092,7 @@ export declare class TypeQueryNode extends NodeWithTypeArguments; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeReferenceNode extends NodeWithTypeArguments { @@ -9101,7 +9101,7 @@ export declare class TypeReferenceNode extends NodeWithTypeArguments; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class UnionTypeNode extends TypeNode { @@ -9110,7 +9110,7 @@ export declare class UnionTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const VariableDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof Node; @@ -9119,7 +9119,7 @@ export declare class VariableDeclaration extends VariableDeclarationBase string)): VariableStatement; /** Gets the corresponding variable statement if it exists. Returns undefined for variable declarations in for statements. */ getVariableStatement(): VariableStatement | undefined; /** @@ -9132,7 +9132,7 @@ export declare class VariableDeclaration extends VariableDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare enum VariableDeclarationKind { @@ -9180,7 +9180,7 @@ export declare class VariableDeclarationList extends VariableDeclarationListBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class Signature { @@ -9210,11 +9210,11 @@ export declare class Symbol { /** Gets the escaped name. */ getEscapedName(): string; /** Gets the aliased symbol or throws if it doesn't exist. */ - getAliasedSymbolOrThrow(): Symbol; + getAliasedSymbolOrThrow(message?: string | (() => string)): Symbol; /** Follows a single alias to get the immediately aliased symbol or returns undefined if it doesn't exist. */ getImmediatelyAliasedSymbol(): Symbol | undefined; /** Follows a single alias to get the immediately aliased symbol or throws if it doesn't exist. */ - getImmediatelyAliasedSymbolOrThrow(): Symbol; + getImmediatelyAliasedSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the aliased symbol or returns undefined if it doesn't exist. */ getAliasedSymbol(): Symbol | undefined; /** @@ -9240,7 +9240,7 @@ export declare class Symbol { */ hasFlags(flags: SymbolFlags): boolean; /** Gets the value declaration of a symbol or throws if it doesn't exist. */ - getValueDeclarationOrThrow(): Node; + getValueDeclarationOrThrow(message?: string | (() => string)): Node; /** Gets the value declaration of the symbol or returns undefined if it doesn't exist. */ getValueDeclaration(): Node | undefined; /** Gets the symbol declarations. */ @@ -9249,7 +9249,7 @@ export declare class Symbol { * Gets the export of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getExportOrThrow(name: string): Symbol; + getExportOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the export of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the export. @@ -9261,7 +9261,7 @@ export declare class Symbol { * Gets the global export of the symbol by the specified name or throws if not exists. * @param name - Name of the global export. */ - getGlobalExportOrThrow(name: string): Symbol; + getGlobalExportOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the global export of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the global export. @@ -9273,7 +9273,7 @@ export declare class Symbol { * Gets the member of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getMemberOrThrow(name: string): Symbol; + getMemberOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the member of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the member. @@ -9969,7 +9969,7 @@ export declare class TypeChecker { * Gets the resolved signature from a node or throws if the signature cannot be resolved. * @param node - Node to get the signature from. */ - getResolvedSignatureOrThrow(node: CallLikeExpression): Signature; + getResolvedSignatureOrThrow(node: CallLikeExpression, message?: string | (() => string)): Signature; /** * Gets the base type of a literal type. * @@ -10006,13 +10006,13 @@ export declare class Type { /** Gets the alias symbol if it exists. */ getAliasSymbol(): Symbol | undefined; /** Gets the alias symbol if it exists, or throws. */ - getAliasSymbolOrThrow(): Symbol; + getAliasSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the alias type arguments. */ getAliasTypeArguments(): Type[]; /** Gets the apparent type. */ getApparentType(): Type; /** Gets the array element type or throws if it doesn't exist (ex. for `T[]` it would be `T`). */ - getArrayElementTypeOrThrow(): Type; + getArrayElementTypeOrThrow(message?: string | (() => string)): Type; /** Gets the array element type or returns undefined if it doesn't exist (ex. for `T[]` it would be `T`). */ getArrayElementType(): Type | undefined; /** Gets the base types. */ @@ -10028,11 +10028,11 @@ export declare class Type { /** Gets the construct signatures. */ getConstructSignatures(): Signature[]; /** Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow(): Type; + getConstraintOrThrow(message?: string | (() => string)): Type; /** Gets the constraint or returns undefined if it doesn't exist. */ getConstraint(): Type | undefined; /** Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow(): Type; + getDefaultOrThrow(message?: string | (() => string)): Type; /** Gets the default type or returns undefined if it doesn't exist. */ getDefault(): Type | undefined; /** Gets the properties of the type. */ @@ -10095,7 +10095,7 @@ export declare class Type { * - Given generic type `Promise` returns the same `Promise`. * - Given `string` throws an error. */ - getTargetTypeOrThrow(): Type; + getTargetTypeOrThrow(message?: string | (() => string)): Type; /** Gets type arguments. */ getTypeArguments(): Type[]; /** Gets the individual element types of the tuple. */ @@ -10107,7 +10107,7 @@ export declare class Type { /** Gets the value of a literal or returns undefined if this is not a literal type. */ getLiteralValue(): string | number | ts.PseudoBigInt | undefined; /** Gets the value of the literal or throws if this is not a literal type. */ - getLiteralValueOrThrow(): string | number | ts.PseudoBigInt; + getLiteralValueOrThrow(message?: string | (() => string)): string | number | ts.PseudoBigInt; /** * Gets the fresh type of the literal or returns undefined if this is not a literal type. * @@ -10119,7 +10119,7 @@ export declare class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralFreshTypeOrThrow(): Type; + getLiteralFreshTypeOrThrow(message?: string | (() => string)): Type; /** * Gets the regular type of the literal or returns undefined if this is not a literal type. * @@ -10131,11 +10131,11 @@ export declare class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralRegularTypeOrThrow(): Type; + getLiteralRegularTypeOrThrow(message?: string | (() => string)): Type; /** Gets the symbol of the type. */ getSymbol(): Symbol | undefined; /** Gets the symbol of the type or throws. */ - getSymbolOrThrow(): Symbol; + getSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets if this is an anonymous type. */ isAnonymous(): boolean; /** Gets if this is an any type. */ @@ -10201,11 +10201,11 @@ export declare class Type { export declare class TypeParameter extends Type { /** Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow(): Type; + getConstraintOrThrow(message?: string | (() => string)): Type; /** Gets the constraint type. */ getConstraint(): Type | undefined; /** Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow(): Type; + getDefaultOrThrow(message?: string | (() => string)): Type; /** Gets the default type or undefined if it doesn't exist. */ getDefault(): Type | undefined; } diff --git a/deno/ts_morph.js b/deno/ts_morph.js index bc97e8acd..63089ddde 100644 --- a/deno/ts_morph.js +++ b/deno/ts_morph.js @@ -549,8 +549,8 @@ function AmbientableNode(Base) { hasDeclareKeyword() { return this.getDeclareKeyword() != null; } - getDeclareKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getDeclareKeyword(), "Expected to find a declare keyword."); + getDeclareKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDeclareKeyword(), message !== null && message !== void 0 ? message : "Expected to find a declare keyword.", this); } getDeclareKeyword() { return this.getFirstModifierByKind(SyntaxKind.DeclareKeyword); @@ -2255,7 +2255,7 @@ function getReplacementText(node) { else if (Node.isBodyable(node)) return node.getBodyOrThrow(); else - throw new errors.NotImplementedError(`Not implemented unwrap scenario for ${node.getKindName()}.`); + errors.throwNotImplementedForSyntaxKindError(node.getKind(), node); } } } @@ -2793,8 +2793,8 @@ function AsyncableNode(Base) { getAsyncKeyword() { return this.getFirstModifierByKind(SyntaxKind.AsyncKeyword); } - getAsyncKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getAsyncKeyword(), "Expected to find an async keyword."); + getAsyncKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getAsyncKeyword(), message !== null && message !== void 0 ? message : "Expected to find an async keyword.", this); } setIsAsync(value) { this.toggleModifier("async", value); @@ -2823,7 +2823,7 @@ function AwaitableNode(Base) { const awaitModifier = this.compilerNode.awaitModifier; return this._getNodeFromCompilerNodeIfExists(awaitModifier); } - getAwaitKeywordOrThrow() { + getAwaitKeywordOrThrow(message) { return errors.throwIfNullOrUndefined(this.getAwaitKeyword(), "Expected to find an await token."); } setIsAwaited(value) { @@ -3044,8 +3044,8 @@ class Node { else return printNode(this.compilerNode, this._sourceFile.compilerNode, options); } - getSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getSymbol(), "Could not find the node's symbol."); + getSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getSymbol(), message !== null && message !== void 0 ? message : "Could not find the node's symbol.", this); } getSymbol() { const boundSymbol = this.compilerNode.symbol; @@ -3063,8 +3063,8 @@ class Node { getSymbolsInScope(meaning) { return this._context.typeChecker.getSymbolsInScope(this, meaning); } - getLocalOrThrow(name) { - return errors.throwIfNullOrUndefined(this.getLocal(name), `Expected to find local symbol with name: ${name}`); + getLocalOrThrow(name, message) { + return errors.throwIfNullOrUndefined(this.getLocal(name), message !== null && message !== void 0 ? message : `Expected to find local symbol with name: ${name}`, this); } getLocal(name) { const locals = this._getCompilerLocals(); @@ -3109,8 +3109,8 @@ class Node { } return ArrayUtils.binarySearch(this._childStringRanges, new InStringRangeComparer()) !== -1; } - asKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.asKind(kind), () => `Expected the node to be of kind ${getSyntaxKindName(kind)}, but it was ${getSyntaxKindName(this.getKind())}.`); + asKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.asKind(kind), message !== null && message !== void 0 ? message : (() => `Expected the node to be of kind ${getSyntaxKindName(kind)}, but it was ${getSyntaxKindName(this.getKind())}.`), this); } isKind(kind) { return this.getKind() === kind; @@ -3123,22 +3123,22 @@ class Node { return undefined; } } - getFirstChildOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getFirstChild(condition), "Could not find a child that matched the specified condition."); + getFirstChildOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getFirstChild(condition), message !== null && message !== void 0 ? message : "Could not find a child that matched the specified condition.", this); } getFirstChild(condition) { const firstChild = this._getCompilerFirstChild(getWrappedCondition(this, condition)); return this._getNodeFromCompilerNodeIfExists(firstChild); } - getLastChildOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getLastChild(condition), "Could not find a child that matched the specified condition."); + getLastChildOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getLastChild(condition), message !== null && message !== void 0 ? message : "Could not find a child that matched the specified condition.", this); } getLastChild(condition) { const lastChild = this._getCompilerLastChild(getWrappedCondition(this, condition)); return this._getNodeFromCompilerNodeIfExists(lastChild); } - getFirstDescendantOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getFirstDescendant(condition), "Could not find a descendant that matched the specified condition."); + getFirstDescendantOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getFirstDescendant(condition), message !== null && message !== void 0 ? message : "Could not find a descendant that matched the specified condition.", this); } getFirstDescendant(condition) { for (const descendant of this._getDescendantsIterator()) { @@ -3147,15 +3147,15 @@ class Node { } return undefined; } - getPreviousSiblingOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getPreviousSibling(condition), "Could not find the previous sibling."); + getPreviousSiblingOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getPreviousSibling(condition), message !== null && message !== void 0 ? message : "Could not find the previous sibling.", this); } getPreviousSibling(condition) { const previousSibling = this._getCompilerPreviousSibling(getWrappedCondition(this, condition)); return this._getNodeFromCompilerNodeIfExists(previousSibling); } - getNextSiblingOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getNextSibling(condition), "Could not find the next sibling."); + getNextSiblingOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getNextSibling(condition), message !== null && message !== void 0 ? message : "Could not find the next sibling.", this); } getNextSibling(condition) { const nextSibling = this._getCompilerNextSibling(getWrappedCondition(this, condition)); @@ -3187,8 +3187,8 @@ class Node { } } } - getChildSyntaxListOrThrow() { - return errors.throwIfNullOrUndefined(this.getChildSyntaxList(), "A child syntax list was expected."); + getChildSyntaxListOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getChildSyntaxList(), message !== null && message !== void 0 ? message : "A child syntax list was expected.", this); } getChildSyntaxList() { let node = this; @@ -3532,11 +3532,11 @@ class Node { getParent() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.parent); } - getParentOrThrow() { - return errors.throwIfNullOrUndefined(this.getParent(), "Expected to find a parent."); + getParentOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getParent(), message !== null && message !== void 0 ? message : "Expected to find a parent.", this); } - getParentWhileOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getParentWhile(condition), "The initial parent did not match the provided condition."); + getParentWhileOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getParentWhile(condition), message !== null && message !== void 0 ? message : "The initial parent did not match the provided condition.", this); } getParentWhile(condition) { let node = undefined; @@ -3547,8 +3547,8 @@ class Node { } return node; } - getParentWhileKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getParentWhileKind(kind), `The initial parent was not a syntax kind of ${getSyntaxKindName(kind)}.`); + getParentWhileKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getParentWhileKind(kind), message !== null && message !== void 0 ? message : `The initial parent was not a syntax kind of ${getSyntaxKindName(kind)}.`, this); } getParentWhileKind(kind) { return this.getParentWhile(n => n.getKind() === kind); @@ -3562,8 +3562,8 @@ class Node { isInSyntaxList() { return this.getParentSyntaxList() != null; } - getParentSyntaxListOrThrow() { - return errors.throwIfNullOrUndefined(this.getParentSyntaxList(), "Expected the parent to be a syntax list."); + getParentSyntaxListOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getParentSyntaxList(), message !== null && message !== void 0 ? message : "Expected the parent to be a syntax list.", this); } getParentSyntaxList() { const kind = this.getKind(); @@ -3766,47 +3766,47 @@ class Node { getChildrenOfKind(kind) { return this._getCompilerChildrenOfKind(kind).map(c => this._getNodeFromCompilerNode(c)); } - getFirstChildByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getFirstChildByKind(kind), `A child of the kind ${getSyntaxKindName(kind)} was expected.`); + getFirstChildByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getFirstChildByKind(kind), message !== null && message !== void 0 ? message : `A child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } getFirstChildByKind(kind) { const child = this._getCompilerChildrenOfKind(kind)[0]; return child == null ? undefined : this._getNodeFromCompilerNode(child); } - getFirstChildIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getFirstChildIfKind(kind), `A first child of the kind ${getSyntaxKindName(kind)} was expected.`); + getFirstChildIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getFirstChildIfKind(kind), message !== null && message !== void 0 ? message : `A first child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } getFirstChildIfKind(kind) { const firstChild = this._getCompilerFirstChild(); return firstChild != null && firstChild.kind === kind ? this._getNodeFromCompilerNode(firstChild) : undefined; } - getLastChildByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getLastChildByKind(kind), `A child of the kind ${getSyntaxKindName(kind)} was expected.`); + getLastChildByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getLastChildByKind(kind), message !== null && message !== void 0 ? message : `A child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } getLastChildByKind(kind) { const children = this._getCompilerChildrenOfKind(kind); const lastChild = children[children.length - 1]; return this._getNodeFromCompilerNodeIfExists(lastChild); } - getLastChildIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getLastChildIfKind(kind), `A last child of the kind ${getSyntaxKindName(kind)} was expected.`); + getLastChildIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getLastChildIfKind(kind), message !== null && message !== void 0 ? message : `A last child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } getLastChildIfKind(kind) { const lastChild = this._getCompilerLastChild(); return lastChild != null && lastChild.kind === kind ? this._getNodeFromCompilerNode(lastChild) : undefined; } - getChildAtIndexIfKindOrThrow(index, kind) { - return errors.throwIfNullOrUndefined(this.getChildAtIndexIfKind(index, kind), `Child at index ${index} was expected to be ${getSyntaxKindName(kind)}`); + getChildAtIndexIfKindOrThrow(index, kind, message) { + return errors.throwIfNullOrUndefined(this.getChildAtIndexIfKind(index, kind), message !== null && message !== void 0 ? message : `Child at index ${index} was expected to be ${getSyntaxKindName(kind)}`, this); } getChildAtIndexIfKind(index, kind) { const node = this._getCompilerChildAtIndex(index); return node.kind === kind ? this._getNodeFromCompilerNode(node) : undefined; } - getPreviousSiblingIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getPreviousSiblingIfKind(kind), `A previous sibling of kind ${getSyntaxKindName(kind)} was expected.`); + getPreviousSiblingIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getPreviousSiblingIfKind(kind), message !== null && message !== void 0 ? message : `A previous sibling of kind ${getSyntaxKindName(kind)} was expected.`, this); } - getNextSiblingIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getNextSiblingIfKind(kind), `A next sibling of kind ${getSyntaxKindName(kind)} was expected.`); + getNextSiblingIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getNextSiblingIfKind(kind), message !== null && message !== void 0 ? message : `A next sibling of kind ${getSyntaxKindName(kind)} was expected.`, this); } getPreviousSiblingIfKind(kind) { const previousSibling = this._getCompilerPreviousSibling(); @@ -3818,20 +3818,20 @@ class Node { const nextSibling = this._getCompilerNextSibling(); return nextSibling != null && nextSibling.kind === kind ? this._getNodeFromCompilerNode(nextSibling) : undefined; } - getParentIfOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getParentIf(condition), "The parent did not match the provided condition."); + getParentIfOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getParentIf(condition), message !== null && message !== void 0 ? message : "The parent did not match the provided condition.", this); } getParentIf(condition) { return condition(this.getParent(), this) ? this.getParent() : undefined; } - getParentIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getParentIfKind(kind), `The parent was not a syntax kind of ${getSyntaxKindName(kind)}.`); + getParentIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getParentIfKind(kind), message !== null && message !== void 0 ? message : `The parent was not a syntax kind of ${getSyntaxKindName(kind)}.`, this); } getParentIfKind(kind) { return this.getParentIf(n => n !== undefined && n.getKind() === kind); } - getFirstAncestorByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getFirstAncestorByKind(kind), `Expected an ancestor with a syntax kind of ${getSyntaxKindName(kind)}.`); + getFirstAncestorByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getFirstAncestorByKind(kind), message !== null && message !== void 0 ? message : `Expected an ancestor with a syntax kind of ${getSyntaxKindName(kind)}.`, this); } getFirstAncestorByKind(kind) { for (const parent of this._getAncestorsIterator(kind === SyntaxKind.SyntaxList)) { @@ -3840,8 +3840,8 @@ class Node { } return undefined; } - getFirstAncestorOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getFirstAncestor(condition), `Expected to find an ancestor that matched the provided condition.`); + getFirstAncestorOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getFirstAncestor(condition), message !== null && message !== void 0 ? message : `Expected to find an ancestor that matched the provided condition.`, this); } getFirstAncestor(condition) { for (const ancestor of this._getAncestorsIterator(false)) { @@ -3856,8 +3856,8 @@ class Node { descendants.push(this._getNodeFromCompilerNode(descendant)); return descendants; } - getFirstDescendantByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getFirstDescendantByKind(kind), `A descendant of kind ${getSyntaxKindName(kind)} was expected to be found.`); + getFirstDescendantByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getFirstDescendantByKind(kind), message !== null && message !== void 0 ? message : `A descendant of kind ${getSyntaxKindName(kind)} was expected to be found.`, this); } getFirstDescendantByKind(kind) { for (const descendant of this._getCompilerDescendantsOfKindIterator(kind)) @@ -5785,8 +5785,8 @@ function BodiedNode(Base) { function BodyableNode(Base) { return class extends Base { - getBodyOrThrow() { - return errors.throwIfNullOrUndefined(this.getBody(), "Expected to find the node's body."); + getBodyOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getBody(), message !== null && message !== void 0 ? message : "Expected to find the node's body.", this); } getBody() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.body); @@ -5859,8 +5859,8 @@ function DecoratableNode(Base) { getDecorator(nameOrFindFunction) { return getNodeByNameOrFindFunction(this.getDecorators(), nameOrFindFunction); } - getDecoratorOrThrow(nameOrFindFunction) { - return errors.throwIfNullOrUndefined(this.getDecorator(nameOrFindFunction), () => getNotFoundErrorMessageForNameOrFindFunction("decorator", nameOrFindFunction)); + getDecoratorOrThrow(nameOrFindFunction, message) { + return errors.throwIfNullOrUndefined(this.getDecorator(nameOrFindFunction), message !== null && message !== void 0 ? message : (() => getNotFoundErrorMessageForNameOrFindFunction("decorator", nameOrFindFunction)), this); } getDecorators() { return getCompilerNodeDecorators(this.compilerNode).map(d => this._getNodeFromCompilerNode(d)); @@ -5945,8 +5945,8 @@ function areDecoratorsOnSameLine(parent, currentDecorators) { function DotDotDotTokenableNode(Base) { return class extends Base { - getDotDotDotTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getDotDotDotToken(), "Expected to find a dot dot dot token (...)."); + getDotDotDotTokenOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDotDotDotToken(), message !== null && message !== void 0 ? message : "Expected to find a dot dot dot token (...).", this); } getDotDotDotToken() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.dotDotDotToken); @@ -5962,8 +5962,8 @@ function ExclamationTokenableNode(Base) { getExclamationTokenNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.exclamationToken); } - getExclamationTokenNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getExclamationTokenNode(), "Expected to find an exclamation token."); + getExclamationTokenNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getExclamationTokenNode(), message !== null && message !== void 0 ? message : "Expected to find an exclamation token.", this); } setHasExclamationToken(value) { const exclamationTokenNode = this.getExclamationTokenNode(); @@ -6015,8 +6015,8 @@ function ExportGetableNode(Base) { return throwForNotModifierableNode(); return this.getFirstModifierByKind(SyntaxKind.ExportKeyword); } - getExportKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getExportKeyword(), "Expected to find an export keyword."); + getExportKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getExportKeyword(), message !== null && message !== void 0 ? message : "Expected to find an export keyword.", this); } hasDefaultKeyword() { return this.getDefaultKeyword() != null; @@ -6030,8 +6030,8 @@ function ExportGetableNode(Base) { return throwForNotModifierableNode(); return this.getFirstModifierByKind(SyntaxKind.DefaultKeyword); } - getDefaultKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefaultKeyword(), "Expected to find a default keyword."); + getDefaultKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefaultKeyword(), message !== null && message !== void 0 ? message : "Expected to find a default keyword.", this); } isExported() { if (this.hasExportKeyword()) @@ -8732,8 +8732,8 @@ function GeneratorableNode(Base) { getAsteriskToken() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.asteriskToken); } - getAsteriskTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getAsteriskToken(), "Expected to find an asterisk token."); + getAsteriskTokenOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getAsteriskToken(), message !== null && message !== void 0 ? message : "Expected to find an asterisk token.", this); } setIsGenerator(value) { const asteriskToken = this.getAsteriskToken(); @@ -8784,8 +8784,8 @@ function HeritageClauseableNode(Base) { const heritageClauses = this.compilerNode.heritageClauses; return (_a = heritageClauses === null || heritageClauses === void 0 ? void 0 : heritageClauses.map(c => this._getNodeFromCompilerNode(c))) !== null && _a !== void 0 ? _a : []; } - getHeritageClauseByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getHeritageClauseByKind(kind), `Expected to have heritage clause of kind ${getSyntaxKindName(kind)}.`); + getHeritageClauseByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getHeritageClauseByKind(kind), message !== null && message !== void 0 ? message : (() => `Expected to have heritage clause of kind ${getSyntaxKindName(kind)}.`), this); } getHeritageClauseByKind(kind) { return this.getHeritageClauses().find(c => c.compilerNode.token === kind); @@ -8872,8 +8872,8 @@ function InitializerExpressionGetableNode(Base) { hasInitializer() { return this.compilerNode.initializer != null; } - getInitializerIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getInitializerIfKind(kind), `Expected to find an initializer of kind '${getSyntaxKindName(kind)}'.`); + getInitializerIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getInitializerIfKind(kind), message !== null && message !== void 0 ? message : `Expected to find an initializer of kind '${getSyntaxKindName(kind)}'.`, this); } getInitializerIfKind(kind) { const initializer = this.getInitializer(); @@ -8881,8 +8881,8 @@ function InitializerExpressionGetableNode(Base) { return undefined; return initializer; } - getInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getInitializer(), "Expected to find an initializer."); + getInitializerOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message !== null && message !== void 0 ? message : "Expected to find an initializer.", this); } getInitializer() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.initializer); @@ -9005,8 +9005,8 @@ function ModifierableNode(Base) { getModifiers() { return this.getCompilerModifiers().map(m => this._getNodeFromCompilerNode(m)); } - getFirstModifierByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getFirstModifierByKind(kind), `Expected a modifier of syntax kind: ${getSyntaxKindName(kind)}`); + getFirstModifierByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getFirstModifierByKind(kind), message !== null && message !== void 0 ? message : (() => `Expected a modifier of syntax kind: ${getSyntaxKindName(kind)}`), this); } getFirstModifierByKind(kind) { for (const modifier of this.getCompilerModifiers()) { @@ -9181,8 +9181,8 @@ function ModuledNode(Base) { return conditionOrModuleSpecifier; } } - getImportDeclarationOrThrow(conditionOrModuleSpecifier) { - return errors.throwIfNullOrUndefined(this.getImportDeclaration(conditionOrModuleSpecifier), "Expected to find an import with the provided condition."); + getImportDeclarationOrThrow(conditionOrModuleSpecifier, message) { + return errors.throwIfNullOrUndefined(this.getImportDeclaration(conditionOrModuleSpecifier), message !== null && message !== void 0 ? message : "Expected to find an import with the provided condition.", this); } getImportDeclarations() { return this.getStatements().filter(Node.isImportDeclaration); @@ -9220,8 +9220,8 @@ function ModuledNode(Base) { return conditionOrModuleSpecifier; } } - getExportDeclarationOrThrow(conditionOrModuleSpecifier) { - return errors.throwIfNullOrUndefined(this.getExportDeclaration(conditionOrModuleSpecifier), "Expected to find an export declaration with the provided condition."); + getExportDeclarationOrThrow(conditionOrModuleSpecifier, message) { + return errors.throwIfNullOrUndefined(this.getExportDeclaration(conditionOrModuleSpecifier), message !== null && message !== void 0 ? message : "Expected to find an export declaration with the provided condition.", this); } getExportDeclarations() { return this.getStatements().filter(Node.isExportDeclaration); @@ -9253,8 +9253,8 @@ function ModuledNode(Base) { getExportAssignment(condition) { return this.getExportAssignments().find(condition); } - getExportAssignmentOrThrow(condition) { - return errors.throwIfNullOrUndefined(this.getExportAssignment(condition), "Expected to find an export assignment with the provided condition."); + getExportAssignmentOrThrow(condition, message) { + return errors.throwIfNullOrUndefined(this.getExportAssignment(condition), message !== null && message !== void 0 ? message : "Expected to find an export assignment with the provided condition.", this); } getExportAssignments() { return this.getStatements().filter(Node.isExportAssignment); @@ -9265,8 +9265,8 @@ function ModuledNode(Base) { return undefined; return sourceFileSymbol.getExport("default"); } - getDefaultExportSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefaultExportSymbol(), "Expected to find a default export symbol"); + getDefaultExportSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefaultExportSymbol(), message !== null && message !== void 0 ? message : "Expected to find a default export symbol"); } getExportSymbols() { const symbol = this.getSymbol(); @@ -9438,15 +9438,15 @@ function NameableNodeInternal(Base) { getNameNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.name); } - getNameNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getNameNode(), "Expected to have a name node."); + getNameNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNameNode(), message !== null && message !== void 0 ? message : "Expected to have a name node.", this); } getName() { var _a, _b; return (_b = (_a = this.getNameNode()) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : undefined; } - getNameOrThrow() { - return errors.throwIfNullOrUndefined(this.getName(), "Expected to have a name."); + getNameOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getName(), message !== null && message !== void 0 ? message : "Expected to have a name.", this); } rename(newName) { if (newName === this.getName()) @@ -9528,8 +9528,8 @@ function OverrideableNode(Base) { getOverrideKeyword() { return this.getFirstModifierByKind(SyntaxKind.OverrideKeyword); } - getOverrideKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getOverrideKeyword(), "Expected to find an override keyword."); + getOverrideKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getOverrideKeyword(), message !== null && message !== void 0 ? message : "Expected to find an override keyword.", this); } setHasOverrideKeyword(value) { this.toggleModifier("override", value); @@ -9611,8 +9611,8 @@ function QuestionDotTokenableNode(Base) { getQuestionDotTokenNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.questionDotToken); } - getQuestionDotTokenNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getQuestionDotTokenNode(), "Expected to find a question dot token."); + getQuestionDotTokenNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getQuestionDotTokenNode(), message !== null && message !== void 0 ? message : "Expected to find a question dot token.", this); } setHasQuestionDotToken(value) { const questionDotTokenNode = this.getQuestionDotTokenNode(); @@ -9667,8 +9667,8 @@ function QuestionTokenableNode(Base) { getQuestionTokenNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.questionToken); } - getQuestionTokenNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getQuestionTokenNode(), "Expected to find a question token."); + getQuestionTokenNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getQuestionTokenNode(), message !== null && message !== void 0 ? message : "Expected to find a question token.", this); } setHasQuestionToken(value) { const questionTokenNode = this.getQuestionTokenNode(); @@ -9722,8 +9722,8 @@ function ReadonlyableNode(Base) { getReadonlyKeyword() { return this.getFirstModifierByKind(SyntaxKind.ReadonlyKeyword); } - getReadonlyKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getReadonlyKeyword(), "Expected to find a readonly keyword."); + getReadonlyKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getReadonlyKeyword(), message !== null && message !== void 0 ? message : "Expected to find a readonly keyword.", this); } setIsReadonly(value) { this.toggleModifier("readonly", value); @@ -9751,8 +9751,8 @@ function ReturnTypedNode(Base) { getReturnTypeNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); } - getReturnTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getReturnTypeNode(), "Expected to find a return type node."); + getReturnTypeNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getReturnTypeNode(), message !== null && message !== void 0 ? message : "Expected to find a return type node.", this); } setReturnType(textOrWriterFunction) { const text = getTextFromStringOrWriter(this._getWriterWithQueuedChildIndentation(), textOrWriterFunction); @@ -9898,8 +9898,8 @@ function StaticableNode(Base) { getStaticKeyword() { return this.getFirstModifierByKind(SyntaxKind.StaticKeyword); } - getStaticKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getStaticKeyword(), "Expected to find a static keyword."); + getStaticKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getStaticKeyword(), message !== null && message !== void 0 ? message : "Expected to find a static keyword.", this); } setIsStatic(value) { this.toggleModifier("static", value); @@ -10049,8 +10049,8 @@ function TypedNode(Base) { getTypeNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); } - getTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Expected to find a type node."); + getTypeNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message !== null && message !== void 0 ? message : "Expected to find a type node.", this); } setType(textOrWriterFunction) { const text = getTextFromStringOrWriter(this._getWriterWithQueuedChildIndentation(), textOrWriterFunction); @@ -10175,8 +10175,8 @@ function TypeElementMemberedNode(Base) { getConstructSignature(findFunction) { return this.getConstructSignatures().find(findFunction); } - getConstructSignatureOrThrow(findFunction) { - return errors.throwIfNullOrUndefined(this.getConstructSignature(findFunction), "Expected to find a construct signature with the provided condition."); + getConstructSignatureOrThrow(findFunction, message) { + return errors.throwIfNullOrUndefined(this.getConstructSignature(findFunction), message !== null && message !== void 0 ? message : "Expected to find a construct signature with the provided condition.", this); } getConstructSignatures() { return this.compilerNode.members.filter(m => m.kind === SyntaxKind.ConstructSignature) @@ -10203,8 +10203,8 @@ function TypeElementMemberedNode(Base) { getCallSignature(findFunction) { return this.getCallSignatures().find(findFunction); } - getCallSignatureOrThrow(findFunction) { - return errors.throwIfNullOrUndefined(this.getCallSignature(findFunction), "Expected to find a call signature with the provided condition."); + getCallSignatureOrThrow(findFunction, message) { + return errors.throwIfNullOrUndefined(this.getCallSignature(findFunction), message !== null && message !== void 0 ? message : "Expected to find a call signature with the provided condition.", this); } getCallSignatures() { return this.compilerNode.members.filter(m => m.kind === SyntaxKind.CallSignature) @@ -10231,8 +10231,8 @@ function TypeElementMemberedNode(Base) { getIndexSignature(findFunction) { return this.getIndexSignatures().find(findFunction); } - getIndexSignatureOrThrow(findFunction) { - return errors.throwIfNullOrUndefined(this.getIndexSignature(findFunction), "Expected to find a index signature with the provided condition."); + getIndexSignatureOrThrow(findFunction, message) { + return errors.throwIfNullOrUndefined(this.getIndexSignature(findFunction), message !== null && message !== void 0 ? message : "Expected to find a index signature with the provided condition.", this); } getIndexSignatures() { return this.compilerNode.members.filter(m => m.kind === SyntaxKind.IndexSignature) @@ -10443,8 +10443,8 @@ class ArrayBindingPattern extends Node { const createBase$E = (ctor) => DotDotDotTokenableNode(InitializerExpressionableNode(BindingNamedNode(ctor))); const BindingElementBase = createBase$E(Node); class BindingElement extends BindingElementBase { - getPropertyNameNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getPropertyNameNode(), "Expected to find a property name node."); + getPropertyNameNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getPropertyNameNode(), message !== null && message !== void 0 ? message : "Expected to find a property name node.", this); } getPropertyNameNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.propertyName); @@ -10465,8 +10465,8 @@ function AbstractableNode(Base) { getAbstractKeyword() { return this.getFirstModifierByKind(SyntaxKind.AbstractKeyword); } - getAbstractKeywordOrThrow() { - return errors.throwIfNullOrUndefined(this.getAbstractKeyword(), "Expected to find an abstract keyword."); + getAbstractKeywordOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getAbstractKeyword(), message !== null && message !== void 0 ? message : "Expected to find an abstract keyword.", this); } setIsAbstract(isAbstract) { this.toggleModifier("abstract", isAbstract); @@ -10605,15 +10605,15 @@ function ExpressionableNode(Base) { getExpression() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.expression); } - getExpressionOrThrow() { - return errors.throwIfNullOrUndefined(this.getExpression(), "Expected to find an expression."); + getExpressionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getExpression(), message !== null && message !== void 0 ? message : "Expected to find an expression.", this); } getExpressionIfKind(kind) { const expression = this.getExpression(); return (expression === null || expression === void 0 ? void 0 : expression.getKind()) === kind ? expression : undefined; } - getExpressionIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), `An expression with the kind kind ${getSyntaxKindName(kind)} was expected.`); + getExpressionIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), message !== null && message !== void 0 ? message : `An expression with the kind kind ${getSyntaxKindName(kind)} was expected.`, this); } }; } @@ -10627,8 +10627,8 @@ function BaseExpressionedNode(Base) { const { expression } = this.compilerNode; return expression.kind === kind ? this._getNodeFromCompilerNode(expression) : undefined; } - getExpressionIfKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), `An expression of the kind ${getSyntaxKindName(kind)} was expected.`); + getExpressionIfKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), message !== null && message !== void 0 ? message : `An expression of the kind ${getSyntaxKindName(kind)} was expected.`, this); } setExpression(textOrWriterFunction) { this.getExpression().replaceWithText(textOrWriterFunction, this._getWriterWithQueuedChildIndentation()); @@ -10715,8 +10715,8 @@ class ElementAccessExpression extends ElementAccessExpressionBase { getArgumentExpression() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.argumentExpression); } - getArgumentExpressionOrThrow() { - return errors.throwIfNullOrUndefined(this.getArgumentExpression(), "Expected to find an argument expression."); + getArgumentExpressionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getArgumentExpression(), message !== null && message !== void 0 ? message : "Expected to find an argument expression.", this); } } @@ -10963,14 +10963,14 @@ class ShorthandPropertyAssignment extends ShorthandPropertyAssignmentBase { hasObjectAssignmentInitializer() { return this.compilerNode.objectAssignmentInitializer != null; } - getObjectAssignmentInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getObjectAssignmentInitializer(), "Expected to find an object assignment initializer."); + getObjectAssignmentInitializerOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getObjectAssignmentInitializer(), message !== null && message !== void 0 ? message : "Expected to find an object assignment initializer.", this); } getObjectAssignmentInitializer() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.objectAssignmentInitializer); } - getEqualsTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getEqualsToken(), "Expected to find an equals token."); + getEqualsTokenOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getEqualsToken(), message !== null && message !== void 0 ? message : "Expected to find an equals token.", this); } getEqualsToken() { const equalsToken = this.compilerNode.equalsToken; @@ -11127,15 +11127,15 @@ function StatementedNode(Base) { getStatement(findFunction) { return this.getStatements().find(findFunction); } - getStatementOrThrow(findFunction) { - return errors.throwIfNullOrUndefined(this.getStatement(findFunction), "Expected to find a statement matching the provided condition."); + getStatementOrThrow(findFunction, message) { + return errors.throwIfNullOrUndefined(this.getStatement(findFunction), message !== null && message !== void 0 ? message : "Expected to find a statement matching the provided condition.", this); } getStatementByKind(kind) { const statement = this._getCompilerStatementsWithComments().find(s => s.kind === kind); return this._getNodeFromCompilerNodeIfExists(statement); } - getStatementByKindOrThrow(kind) { - return errors.throwIfNullOrUndefined(this.getStatementByKind(kind), `Expected to find a statement with syntax kind ${getSyntaxKindName(kind)}.`); + getStatementByKindOrThrow(kind, message) { + return errors.throwIfNullOrUndefined(this.getStatementByKind(kind), message !== null && message !== void 0 ? message : `Expected to find a statement with syntax kind ${getSyntaxKindName(kind)}.`, this); } addStatements(textOrWriterFunction) { return this.insertStatements(this._getCompilerStatementsWithComments().length, textOrWriterFunction); @@ -11372,8 +11372,8 @@ function StatementedNode(Base) { return nameOrFindFunction; } } - getVariableStatementOrThrow(nameOrFindFunction) { - return errors.throwIfNullOrUndefined(this.getVariableStatement(nameOrFindFunction), "Expected to find a variable statement that matched the provided condition."); + getVariableStatementOrThrow(nameOrFindFunction, message) { + return errors.throwIfNullOrUndefined(this.getVariableStatement(nameOrFindFunction), message !== null && message !== void 0 ? message : "Expected to find a variable statement that matched the provided condition.", this); } addVariableStatement(structure) { return this.addVariableStatements([structure])[0]; @@ -11504,8 +11504,8 @@ class BreakStatement extends Statement { getLabel() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.label); } - getLabelOrThrow() { - return errors.throwIfNullOrUndefined(this.getLabel(), "Expected to find a label."); + getLabelOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLabel(), message !== null && message !== void 0 ? message : "Expected to find a label.", this); } } @@ -11543,8 +11543,8 @@ class CatchClause extends CatchClauseBase { getVariableDeclaration() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.variableDeclaration); } - getVariableDeclarationOrThrow() { - return errors.throwIfNullOrUndefined(this.getVariableDeclaration(), "Expected to find a variable declaration."); + getVariableDeclarationOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getVariableDeclaration(), message !== null && message !== void 0 ? message : "Expected to find a variable declaration.", this); } } @@ -11557,8 +11557,8 @@ class ContinueStatement extends Statement { ? undefined : this._getNodeFromCompilerNode(this.compilerNode.label); } - getLabelOrThrow() { - return errors.throwIfNullOrUndefined(this.getLabel(), "Expected to find a label."); + getLabelOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLabel(), message !== null && message !== void 0 ? message : "Expected to find a label.", this); } } @@ -11611,20 +11611,20 @@ class ForStatement extends ForStatementBase { getInitializer() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.initializer); } - getInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getInitializer(), "Expected to find an initializer."); + getInitializerOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message !== null && message !== void 0 ? message : "Expected to find an initializer.", this); } getCondition() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.condition); } - getConditionOrThrow() { - return errors.throwIfNullOrUndefined(this.getCondition(), "Expected to find a condition."); + getConditionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getCondition(), message !== null && message !== void 0 ? message : "Expected to find a condition.", this); } getIncrementor() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.incrementor); } - getIncrementorOrThrow() { - return errors.throwIfNullOrUndefined(this.getIncrementor(), "Expected to find an incrementor."); + getIncrementorOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getIncrementor(), message !== null && message !== void 0 ? message : "Expected to find an incrementor.", this); } } @@ -11691,16 +11691,16 @@ class TryStatement extends TryStatementBase { getCatchClause() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.catchClause); } - getCatchClauseOrThrow() { - return errors.throwIfNullOrUndefined(this.getCatchClause(), "Expected to find a catch clause."); + getCatchClauseOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getCatchClause(), message !== null && message !== void 0 ? message : "Expected to find a catch clause.", this); } getFinallyBlock() { if (this.compilerNode.finallyBlock == null || this.compilerNode.finallyBlock.getFullWidth() === 0) return undefined; return this._getNodeFromCompilerNode(this.compilerNode.finallyBlock); } - getFinallyBlockOrThrow() { - return errors.throwIfNullOrUndefined(this.getFinallyBlock(), "Expected to find a finally block."); + getFinallyBlockOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getFinallyBlock(), message !== null && message !== void 0 ? message : "Expected to find a finally block.", this); } } @@ -11804,8 +11804,8 @@ class ExportDeclaration extends ExportDeclarationBase { const exportClause = this.getNodeProperty("exportClause"); return exportClause != null && Node.isNamespaceExport(exportClause) ? exportClause : undefined; } - getNamespaceExportOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamespaceExport(), "Expected to find a namespace export."); + getNamespaceExportOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNamespaceExport(), message !== null && message !== void 0 ? message : "Expected to find a namespace export.", this); } setNamespaceExport(name) { const exportClause = this.getNodeProperty("exportClause"); @@ -11868,8 +11868,8 @@ class ExportDeclaration extends ExportDeclarationBase { const moduleSpecifier = this.getModuleSpecifier(); return moduleSpecifier === null || moduleSpecifier === void 0 ? void 0 : moduleSpecifier.getLiteralValue(); } - getModuleSpecifierSourceFileOrThrow() { - return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), `A module specifier source file was expected.`); + getModuleSpecifierSourceFileOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), message !== null && message !== void 0 ? message : `A module specifier source file was expected.`, this); } getModuleSpecifierSourceFile() { const stringLiteral = this.getLastChildByKind(SyntaxKind.StringLiteral); @@ -12162,8 +12162,8 @@ class ExportSpecifier extends ExportSpecifierBase { getExportDeclaration() { return this.getFirstAncestorByKindOrThrow(SyntaxKind.ExportDeclaration); } - getLocalTargetSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getLocalTargetSymbol(), `The export specifier's local target symbol was expected.`); + getLocalTargetSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLocalTargetSymbol(), message !== null && message !== void 0 ? message : `The export specifier's local target symbol was expected.`, this); } getLocalTargetSymbol() { return this._context.typeChecker.getExportSpecifierLocalTargetSymbol(this); @@ -12207,8 +12207,8 @@ class ExportSpecifier extends ExportSpecifierBase { const ExternalModuleReferenceBase = ExpressionableNode(Node); class ExternalModuleReference extends ExternalModuleReferenceBase { - getReferencedSourceFileOrThrow() { - return errors.throwIfNullOrUndefined(this.getReferencedSourceFile(), "Expected to find the referenced source file."); + getReferencedSourceFileOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getReferencedSourceFile(), message !== null && message !== void 0 ? message : "Expected to find the referenced source file.", this); } isRelative() { const expression = this.getExpression(); @@ -12251,20 +12251,20 @@ class ImportClause extends ImportClauseBase { } return this; } - getDefaultImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefaultImport(), "Expected to find a default import."); + getDefaultImportOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefaultImport(), message !== null && message !== void 0 ? message : "Expected to find a default import.", this); } getDefaultImport() { return this.getNodeProperty("name"); } - getNamedBindingsOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamedBindings(), "Expected to find an import declaration's named bindings."); + getNamedBindingsOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNamedBindings(), message !== null && message !== void 0 ? message : "Expected to find an import declaration's named bindings.", this); } getNamedBindings() { return this.getNodeProperty("namedBindings"); } - getNamespaceImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamespaceImport(), "Expected to find a namespace import."); + getNamespaceImportOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNamespaceImport(), message !== null && message !== void 0 ? message : "Expected to find a namespace import.", this); } getNamespaceImport() { const namedBindings = this.getNamedBindings(); @@ -12311,8 +12311,8 @@ class ImportDeclaration extends ImportDeclarationBase { getModuleSpecifierValue() { return this.getModuleSpecifier().getLiteralValue(); } - getModuleSpecifierSourceFileOrThrow() { - return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), `A module specifier source file was expected.`); + getModuleSpecifierSourceFileOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), message !== null && message !== void 0 ? message : `A module specifier source file was expected.`, this); } getModuleSpecifierSourceFile() { const symbol = this.getModuleSpecifier().getSymbol(); @@ -12359,8 +12359,8 @@ class ImportDeclaration extends ImportDeclarationBase { this.setDefaultImport(text); return this; } - getDefaultImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefaultImport(), "Expected to find a default import."); + getDefaultImportOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefaultImport(), message !== null && message !== void 0 ? message : "Expected to find a default import.", this); } getDefaultImport() { var _a, _b; @@ -12434,8 +12434,8 @@ class ImportDeclaration extends ImportDeclarationBase { } return this; } - getNamespaceImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamespaceImport(), "Expected to find a namespace import."); + getNamespaceImportOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNamespaceImport(), message !== null && message !== void 0 ? message : "Expected to find a namespace import.", this); } getNamespaceImport() { var _a, _b; @@ -12525,8 +12525,8 @@ class ImportDeclaration extends ImportDeclarationBase { removeChildren({ children: [importClause, fromKeyword], removePrecedingSpaces: true }); return this; } - getImportClauseOrThrow() { - return errors.throwIfNullOrUndefined(this.getImportClause(), "Expected to find an import clause."); + getImportClauseOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getImportClause(), message !== null && message !== void 0 ? message : "Expected to find an import clause.", this); } getImportClause() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.importClause); @@ -12680,8 +12680,8 @@ class ImportEqualsDeclaration extends ImportEqualsDeclarationBase { moduleReference.replaceWithText(writer => writer.write("require(").quote(text).write(")")); return this; } - getExternalModuleReferenceSourceFileOrThrow() { - return errors.throwIfNullOrUndefined(this.getExternalModuleReferenceSourceFile(), "Expected to find an external module reference's referenced source file."); + getExternalModuleReferenceSourceFileOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getExternalModuleReferenceSourceFile(), message !== null && message !== void 0 ? message : "Expected to find an external module reference's referenced source file.", this); } getExternalModuleReferenceSourceFile() { const moduleReference = this.getModuleReference(); @@ -12823,8 +12823,8 @@ class ModuleBlock extends ModuleBlockBase { function ModuleChildableNode(Base) { return class extends Base { - getParentModuleOrThrow() { - return errors.throwIfNullOrUndefined(this.getParentModule(), "Expected to find the parent module declaration."); + getParentModuleOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getParentModule(), message !== null && message !== void 0 ? message : "Expected to find the parent module declaration.", this); } getParentModule() { let parent = this.getParentOrThrow(); @@ -13656,8 +13656,8 @@ function OverloadableNode(Base) { return this; return getOverloadsAndImplementation(this).find(n => n.isImplementation()); } - getImplementationOrThrow() { - return errors.throwIfNullOrUndefined(this.getImplementation(), "Expected to find a corresponding implementation for the overload."); + getImplementationOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getImplementation(), message !== null && message !== void 0 ? message : "Expected to find a corresponding implementation for the overload.", this); } isOverload() { return !this.isImplementation(); @@ -13999,8 +13999,8 @@ function ClassLikeDeclarationBaseSpecific(Base) { extendsClause.removeExpression(0); return this; } - getExtendsOrThrow() { - return errors.throwIfNullOrUndefined(this.getExtends(), `Expected to find the extends expression for the class ${this.getName()}.`); + getExtendsOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getExtends(), message !== null && message !== void 0 ? message : `Expected to find the extends expression for the class ${this.getName()}.`, this); } getExtends() { const extendsClause = this.getHeritageClauseByKind(SyntaxKind.ExtendsKeyword); @@ -14366,8 +14366,8 @@ function ClassLikeDeclarationBaseSpecific(Base) { getBaseTypes() { return this.getType().getBaseTypes(); } - getBaseClassOrThrow() { - return errors.throwIfNullOrUndefined(this.getBaseClass(), `Expected to find the base class of ${this.getName()}.`); + getBaseClassOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getBaseClass(), message !== null && message !== void 0 ? message : `Expected to find the base class of ${this.getName()}.`, this); } getBaseClass() { const baseTypes = ArrayUtils.flatten(this.getBaseTypes().map(t => t.isIntersection() ? t.getIntersectionTypes() : [t])); @@ -14708,8 +14708,8 @@ class GetAccessorDeclaration extends GetAccessorDeclarationBase { return undefined; }); } - getSetAccessorOrThrow() { - return errors.throwIfNullOrUndefined(this.getSetAccessor(), () => `Expected to find a corresponding set accessor for ${this.getName()}.`); + getSetAccessorOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getSetAccessor(), message !== null && message !== void 0 ? message : (() => `Expected to find a corresponding set accessor for ${this.getName()}.`), this); } getStructure() { return callBaseGetStructure(GetAccessorDeclarationBase.prototype, this, { @@ -14767,8 +14767,8 @@ class SetAccessorDeclaration extends SetAccessorDeclarationBase { return undefined; }); } - getGetAccessorOrThrow() { - return errors.throwIfNullOrUndefined(this.getGetAccessor(), () => `Expected to find a corresponding get accessor for ${this.getName()}.`); + getGetAccessorOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getGetAccessor(), message !== null && message !== void 0 ? message : (() => `Expected to find a corresponding get accessor for ${this.getName()}.`), this); } getStructure() { return callBaseGetStructure(SetAccessorDeclarationBase.prototype, this, { @@ -14847,8 +14847,8 @@ class Decorator extends DecoratorBase { } return this; } - getCallExpressionOrThrow() { - return errors.throwIfNullOrUndefined(this.getCallExpression(), "Expected to find a call expression."); + getCallExpressionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getCallExpression(), message !== null && message !== void 0 ? message : "Expected to find a call expression.", this); } getCallExpression() { const expression = this._getInnerExpression(); @@ -14955,8 +14955,8 @@ function JSDocPropertyLikeTag(Base) { getTypeExpression() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.typeExpression); } - getTypeExpressionOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeExpression(), `Expected to find a JS doc type expression.`); + getTypeExpressionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTypeExpression(), message !== null && message !== void 0 ? message : `Expected to find a JS doc type expression.`, this); } getName() { return this.getNameNode().getText(); @@ -14978,8 +14978,8 @@ function JSDocTypeExpressionableTag(Base) { return undefined; return result; } - getTypeExpressionOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeExpression(), `Expected to find the JS doc tag's type expression.`); + getTypeExpressionOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTypeExpression(), message !== null && message !== void 0 ? message : `Expected to find the JS doc tag's type expression.`, this); } }; } @@ -15251,8 +15251,8 @@ class ImportTypeNode extends NodeWithTypeArguments { } return this; } - getQualifierOrThrow() { - return errors.throwIfNullOrUndefined(this.getQualifier(), () => `Expected to find a qualifier for the import type: ${this.getText()}`); + getQualifierOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getQualifier(), message !== null && message !== void 0 ? message : (() => `Expected to find a qualifier for the import type: ${this.getText()}`), this); } getQualifier() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.qualifier); @@ -15260,8 +15260,8 @@ class ImportTypeNode extends NodeWithTypeArguments { getAssertions() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.assertions); } - getAssertionsOrThrow() { - return errors.throwIfNullOrUndefined(this._getNodeFromCompilerNodeIfExists(this.compilerNode.assertions), "Could not find import type assertion container."); + getAssertionsOrThrow(message) { + return errors.throwIfNullOrUndefined(this._getNodeFromCompilerNodeIfExists(this.compilerNode.assertions), message !== null && message !== void 0 ? message : "Could not find import type assertion container.", this); } } @@ -15297,20 +15297,20 @@ class MappedTypeNode extends TypeNode { getNameTypeNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.nameType); } - getNameTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getNameTypeNode(), "Type did not exist."); + getNameTypeNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getNameTypeNode(), message !== null && message !== void 0 ? message : "Type did not exist.", this); } getReadonlyToken() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.readonlyToken); } - getReadonlyTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getReadonlyToken(), "Readonly token did not exist."); + getReadonlyTokenOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getReadonlyToken(), message !== null && message !== void 0 ? message : "Readonly token did not exist.", this); } getQuestionToken() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.questionToken); } - getQuestionTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getQuestionToken(), "Question token did not exist."); + getQuestionTokenOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getQuestionToken(), message !== null && message !== void 0 ? message : "Question token did not exist.", this); } getTypeParameter() { return this._getNodeFromCompilerNode(this.compilerNode.typeParameter); @@ -15318,8 +15318,8 @@ class MappedTypeNode extends TypeNode { getTypeNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); } - getTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Type did not exist, but was expected to exist."); + getTypeNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message !== null && message !== void 0 ? message : "Type did not exist, but was expected to exist.", this); } } @@ -15414,8 +15414,8 @@ class TypeParameterDeclaration extends TypeParameterDeclarationBase { getConstraint() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.constraint); } - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected to find the type parameter's constraint."); + getConstraintOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message !== null && message !== void 0 ? message : "Expected to find the type parameter's constraint.", this); } setConstraint(text) { text = this.getParentOrThrow()._getTextWithQueuedChildIndentation(text); @@ -15443,8 +15443,8 @@ class TypeParameterDeclaration extends TypeParameterDeclarationBase { getDefault() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.default); } - getDefaultOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefault(), "Expected to find the type parameter's default."); + getDefaultOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefault(), message !== null && message !== void 0 ? message : "Expected to find the type parameter's default.", this); } setDefault(text) { text = this.getParentOrThrow()._getTextWithQueuedChildIndentation(text); @@ -15542,14 +15542,14 @@ class TypePredicateNode extends TypeNode { getAssertsModifier() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.assertsModifier); } - getAssertsModifierOrThrow() { - return errors.throwIfNullOrUndefined(this.getAssertsModifier(), "Expected to find an asserts modifier."); + getAssertsModifierOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getAssertsModifier(), message !== null && message !== void 0 ? message : "Expected to find an asserts modifier.", this); } getTypeNode() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); } - getTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Expected to find a type node."); + getTypeNodeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message !== null && message !== void 0 ? message : "Expected to find a type node.", this); } } @@ -15819,8 +15819,8 @@ class JSDocTemplateTag extends JSDocTemplateTagBase { getConstraint() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.constraint); } - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected to find the JS doc template tag's constraint."); + getConstraintOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message !== null && message !== void 0 ? message : "Expected to find the JS doc template tag's constraint.", this); } } @@ -16241,8 +16241,8 @@ function JsxTagNamedNode(Base) { const JsxAttributeBase = NamedNode(Node); class JsxAttribute extends JsxAttributeBase { - getInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getInitializer(), `Expected to find an initializer for the JSX attribute '${this.getName()}'`); + getInitializerOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message !== null && message !== void 0 ? message : `Expected to find an initializer for the JSX attribute '${this.getName()}'`, this); } getInitializer() { return this._getNodeFromCompilerNodeIfExists(this.compilerNode.initializer); @@ -16733,8 +16733,8 @@ class VariableDeclaration extends VariableDeclarationBase { }); } } - getVariableStatementOrThrow() { - return errors.throwIfNullOrUndefined(this.getVariableStatement(), "Expected the grandparent to be a variable statement."); + getVariableStatementOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getVariableStatement(), message !== null && message !== void 0 ? message : "Expected the grandparent to be a variable statement.", this); } getVariableStatement() { const grandParent = this.getParentOrThrow().getParentOrThrow(); @@ -16867,14 +16867,14 @@ class Symbol { getEscapedName() { return this.compilerSymbol.getEscapedName(); } - getAliasedSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getAliasedSymbol(), "Expected to find an aliased symbol."); + getAliasedSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getAliasedSymbol(), message !== null && message !== void 0 ? message : "Expected to find an aliased symbol."); } getImmediatelyAliasedSymbol() { return this._context.typeChecker.getImmediatelyAliasedSymbol(this); } - getImmediatelyAliasedSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getImmediatelyAliasedSymbol(), "Expected to find an immediately aliased symbol."); + getImmediatelyAliasedSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getImmediatelyAliasedSymbol(), message !== null && message !== void 0 ? message : "Expected to find an immediately aliased symbol."); } getAliasedSymbol() { return this._context.typeChecker.getAliasedSymbol(this); @@ -16894,8 +16894,8 @@ class Symbol { hasFlags(flags) { return (this.compilerSymbol.flags & flags) === flags; } - getValueDeclarationOrThrow() { - return errors.throwIfNullOrUndefined(this.getValueDeclaration(), () => `Expected to find the value declaration of symbol '${this.getName()}'.`); + getValueDeclarationOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getValueDeclaration(), message !== null && message !== void 0 ? message : (() => `Expected to find the value declaration of symbol '${this.getName()}'.`)); } getValueDeclaration() { const declaration = this.compilerSymbol.valueDeclaration; @@ -16908,8 +16908,8 @@ class Symbol { return ((_a = this.compilerSymbol.declarations) !== null && _a !== void 0 ? _a : []) .map(d => this._context.compilerFactory.getNodeFromCompilerNode(d, this._context.compilerFactory.getSourceFileForNode(d))); } - getExportOrThrow(name) { - return errors.throwIfNullOrUndefined(this.getExport(name), `Expected to find export with name: ${name}`); + getExportOrThrow(name, message) { + return errors.throwIfNullOrUndefined(this.getExport(name), message !== null && message !== void 0 ? message : (() => `Expected to find export with name: ${name}`)); } getExport(name) { if (this.compilerSymbol.exports == null) @@ -16922,8 +16922,8 @@ class Symbol { return []; return ArrayUtils.from(this.compilerSymbol.exports.values()).map(symbol => this._context.compilerFactory.getSymbol(symbol)); } - getGlobalExportOrThrow(name) { - return errors.throwIfNullOrUndefined(this.getGlobalExport(name), `Expected to find global export with name: ${name}`); + getGlobalExportOrThrow(name, message) { + return errors.throwIfNullOrUndefined(this.getGlobalExport(name), message !== null && message !== void 0 ? message : (() => `Expected to find global export with name: ${name}`)); } getGlobalExport(name) { if (this.compilerSymbol.globalExports == null) @@ -16936,8 +16936,8 @@ class Symbol { return []; return ArrayUtils.from(this.compilerSymbol.globalExports.values()).map(symbol => this._context.compilerFactory.getSymbol(symbol)); } - getMemberOrThrow(name) { - return errors.throwIfNullOrUndefined(this.getMember(name), `Expected to find member with name: ${name}`); + getMemberOrThrow(name, message) { + return errors.throwIfNullOrUndefined(this.getMember(name), message !== null && message !== void 0 ? message : `Expected to find member with name: ${name}`); } getMember(name) { if (this.compilerSymbol.members == null) @@ -17575,8 +17575,8 @@ class TypeChecker { return undefined; return this._context.compilerFactory.getSignature(resolvedSignature); } - getResolvedSignatureOrThrow(node) { - return errors.throwIfNullOrUndefined(this.getResolvedSignature(node), "Signature could not be resolved."); + getResolvedSignatureOrThrow(node, message) { + return errors.throwIfNullOrUndefined(this.getResolvedSignature(node), message !== null && message !== void 0 ? message : "Signature could not be resolved.", node); } getBaseTypeOfLiteralType(type) { return this._context.compilerFactory.getType(this.compilerObject.getBaseTypeOfLiteralType(type.compilerType)); @@ -17887,7 +17887,7 @@ class Type { getAliasSymbol() { return this.compilerType.aliasSymbol == null ? undefined : this._context.compilerFactory.getSymbol(this.compilerType.aliasSymbol); } - getAliasSymbolOrThrow() { + getAliasSymbolOrThrow(message) { return errors.throwIfNullOrUndefined(this.getAliasSymbol(), "Expected to find an alias symbol."); } getAliasTypeArguments() { @@ -17897,8 +17897,8 @@ class Type { getApparentType() { return this._context.typeChecker.getApparentType(this); } - getArrayElementTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getArrayElementType(), "Expected to find an array element type."); + getArrayElementTypeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getArrayElementType(), message !== null && message !== void 0 ? message : "Expected to find an array element type."); } getArrayElementType() { if (!this.isArray()) @@ -17918,15 +17918,15 @@ class Type { getConstructSignatures() { return this.compilerType.getConstructSignatures().map(s => this._context.compilerFactory.getSignature(s)); } - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected to find a constraint."); + getConstraintOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message !== null && message !== void 0 ? message : "Expected to find a constraint."); } getConstraint() { const constraint = this.compilerType.getConstraint(); return constraint == null ? undefined : this._context.compilerFactory.getType(constraint); } - getDefaultOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefault(), "Expected to find a default type."); + getDefaultOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefault(), message !== null && message !== void 0 ? message : "Expected to find a default type."); } getDefault() { const defaultType = this.compilerType.getDefault(); @@ -17965,8 +17965,8 @@ class Type { const targetType = this.compilerType.target || undefined; return targetType == null ? undefined : this._context.compilerFactory.getType(targetType); } - getTargetTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getTargetType(), "Expected to find the target type."); + getTargetTypeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getTargetType(), message !== null && message !== void 0 ? message : "Expected to find the target type."); } getTypeArguments() { return this._context.typeChecker.getTypeArguments(this); @@ -17988,31 +17988,31 @@ class Type { var _a; return (_a = this.compilerType) === null || _a === void 0 ? void 0 : _a.value; } - getLiteralValueOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralValue(), "Type was not a literal type."); + getLiteralValueOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLiteralValue(), message !== null && message !== void 0 ? message : "Type was not a literal type."); } getLiteralFreshType() { var _a; const type = (_a = this.compilerType) === null || _a === void 0 ? void 0 : _a.freshType; return type == null ? undefined : this._context.compilerFactory.getType(type); } - getLiteralFreshTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralFreshType(), "Type was not a literal type."); + getLiteralFreshTypeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLiteralFreshType(), message !== null && message !== void 0 ? message : "Type was not a literal type."); } getLiteralRegularType() { var _a; const type = (_a = this.compilerType) === null || _a === void 0 ? void 0 : _a.regularType; return type == null ? undefined : this._context.compilerFactory.getType(type); } - getLiteralRegularTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralRegularType(), "Type was not a literal type."); + getLiteralRegularTypeOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getLiteralRegularType(), message !== null && message !== void 0 ? message : "Type was not a literal type."); } getSymbol() { const tsSymbol = this.compilerType.getSymbol(); return tsSymbol == null ? undefined : this._context.compilerFactory.getSymbol(tsSymbol); } - getSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getSymbol(), "Expected to find a symbol."); + getSymbolOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getSymbol(), message !== null && message !== void 0 ? message : "Expected to find a symbol."); } isAnonymous() { return this._hasObjectFlag(ObjectFlags.Anonymous); @@ -18131,8 +18131,8 @@ class Type { } class TypeParameter extends Type { - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected type parameter to have a constraint."); + getConstraintOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message !== null && message !== void 0 ? message : "Expected type parameter to have a constraint."); } getConstraint() { const declaration = this._getTypeParameterDeclaration(); @@ -18143,8 +18143,8 @@ class TypeParameter extends Type { return undefined; return this._context.typeChecker.getTypeAtLocation(constraintNode); } - getDefaultOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefault(), "Expected type parameter to have a default type."); + getDefaultOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getDefault(), message !== null && message !== void 0 ? message : "Expected type parameter to have a default type."); } getDefault() { const declaration = this._getTypeParameterDeclaration(); @@ -18210,8 +18210,8 @@ class Directory { getBaseName() { return this._pathParts[this._pathParts.length - 1]; } - getParentOrThrow() { - return errors.throwIfNullOrUndefined(this.getParent(), () => `Parent directory of ${this.getPath()} does not exist or was never added.`); + getParentOrThrow(message) { + return errors.throwIfNullOrUndefined(this.getParent(), message !== null && message !== void 0 ? message : (() => `Parent directory of ${this.getPath()} does not exist or was never added.`)); } getParent() { if (FileUtils.isRootDirPath(this.getPath())) @@ -20157,8 +20157,8 @@ class Project { createDirectory(dirPath) { return this._context.directoryCoordinator.createDirectoryOrAddIfExists(this._context.fileSystemWrapper.getStandardizedAbsolutePath(dirPath), { markInProject: true }); } - getDirectoryOrThrow(dirPath) { - return errors.throwIfNullOrUndefined(this.getDirectory(dirPath), () => `Could not find a directory at the specified path: ${this._context.fileSystemWrapper.getStandardizedAbsolutePath(dirPath)}`); + getDirectoryOrThrow(dirPath, message) { + return errors.throwIfNullOrUndefined(this.getDirectory(dirPath), message !== null && message !== void 0 ? message : (() => `Could not find a directory at the specified path: ${this._context.fileSystemWrapper.getStandardizedAbsolutePath(dirPath)}`)); } getDirectory(dirPath) { const { compilerFactory } = this._context; @@ -20289,8 +20289,8 @@ class Project { moduleName = normalizeAmbientModuleName(moduleName); return this.getAmbientModules().find(s => s.getName() === moduleName); } - getAmbientModuleOrThrow(moduleName) { - return errors.throwIfNullOrUndefined(this.getAmbientModule(moduleName), () => `Could not find ambient module with name: ${normalizeAmbientModuleName(moduleName)}`); + getAmbientModuleOrThrow(moduleName, message) { + return errors.throwIfNullOrUndefined(this.getAmbientModule(moduleName), message !== null && message !== void 0 ? message : (() => `Could not find ambient module with name: ${normalizeAmbientModuleName(moduleName)}`)); } getAmbientModules() { return this.getTypeChecker().getAmbientModules(); diff --git a/packages/common/lib/ts-morph-common.d.ts b/packages/common/lib/ts-morph-common.d.ts index 16c71036c..ec4513703 100644 --- a/packages/common/lib/ts-morph-common.d.ts +++ b/packages/common/lib/ts-morph-common.d.ts @@ -346,26 +346,35 @@ export declare function Memoize(target: any, propertyName: string, descriptor: T /** Collection of helper functions that can be used to throw errors. */ export declare namespace errors { + /** + * Minimal attributes to show a error message with the node source. + */ + interface Node { + getSourceFile(): { + getFilePath(): StandardizedFilePath; + getFullText(): string; + }; + getStart(): number; + } /** Base error class. */ abstract class BaseError extends Error { - readonly message: string; protected constructor(); } /** Thrown when there is a problem with a provided argument. */ class ArgumentError extends BaseError { - constructor(argName: string, message: string); + constructor(argName: string, message: string, node?: Node); } /** Thrown when an argument is null or whitespace. */ class ArgumentNullOrWhitespaceError extends ArgumentError { - constructor(argName: string); + constructor(argName: string, node?: Node); } /** Thrown when an argument is out of range. */ class ArgumentOutOfRangeError extends ArgumentError { - constructor(argName: string, value: number, range: [number, number]); + constructor(argName: string, value: number, range: [number, number], node?: Node); } /** Thrown when an argument does not match an expected type. */ class ArgumentTypeError extends ArgumentError { - constructor(argName: string, expectedType: string, actualType: string); + constructor(argName: string, expectedType: string, actualType: string, node?: Node); } /** Thrown when a file or directory path was not found. */ class PathNotFoundError extends BaseError { @@ -383,11 +392,11 @@ export declare namespace errors { } /** Thrown when an action was taken that is not allowed. */ class InvalidOperationError extends BaseError { - constructor(message: string); + constructor(message: string, node?: Node); } /** Thrown when a certain behaviour or feature has not been implemented. */ class NotImplementedError extends BaseError { - constructor(message?: string); + constructor(message?: string, node?: Node); } /** Thrown when an operation is not supported. */ class NotSupportedError extends BaseError { @@ -432,7 +441,7 @@ export declare namespace errors { * Gets an error saying that a feature is not implemented for a certain syntax kind. * @param kind - Syntax kind that isn't implemented. */ - function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind): never; + function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind, node?: Node): never; /** * Throws an Argument * @param value @@ -444,12 +453,12 @@ export declare namespace errors { * @param value - Value to check. * @param errorMessage - Error message to throw when not defined. */ - function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string)): T; + function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string), node?: Node): T; /** * Throw if the value should have been the never type. * @param value - Value to check. */ - function throwNotImplementedForNeverValueError(value: never): never; + function throwNotImplementedForNeverValueError(value: never, sourceNode?: Node): never; /** * Throws an error if the actual value does not equal the expected value. * @param actual - Actual value. diff --git a/packages/common/src/errors.ts b/packages/common/src/errors.ts index b09bda6ed..0a65e4a27 100644 --- a/packages/common/src/errors.ts +++ b/packages/common/src/errors.ts @@ -1,44 +1,57 @@ import { StandardizedFilePath } from "./fileSystem"; import { getSyntaxKindName } from "./helpers"; import { ts } from "./typescript"; +import { StringUtils } from "./utils"; /** Collection of helper functions that can be used to throw errors. */ export namespace errors { + /** + * Minimal attributes to show a error message with the node source. + */ + export interface Node { + getSourceFile(): { + getFilePath(): StandardizedFilePath; + getFullText(): string; + }; + getStart(): number; + } + /** Base error class. */ export abstract class BaseError extends Error { /** @private */ - constructor(public readonly message: string) { - super(message); - - this.message = message; + constructor(message: string, node?: Node) { + const nodeLocation = node && getPrettyNodeLocation(node); + const messageWithLocation = nodeLocation ? `${message}\n\n${nodeLocation}` : message; + super(messageWithLocation); + this.message = messageWithLocation; } } /** Thrown when there is a problem with a provided argument. */ export class ArgumentError extends BaseError { - constructor(argName: string, message: string) { - super(`Argument Error (${argName}): ${message}`); + constructor(argName: string, message: string, node?: Node) { + super(`Argument Error (${argName}): ${message}`, node); } } /** Thrown when an argument is null or whitespace. */ export class ArgumentNullOrWhitespaceError extends ArgumentError { - constructor(argName: string) { - super(argName, "Cannot be null or whitespace."); + constructor(argName: string, node?: Node) { + super(argName, "Cannot be null or whitespace.", node); } } /** Thrown when an argument is out of range. */ export class ArgumentOutOfRangeError extends ArgumentError { - constructor(argName: string, value: number, range: [number, number]) { - super(argName, `Range is ${range[0]} to ${range[1]}, but ${value} was provided.`); + constructor(argName: string, value: number, range: [number, number], node?: Node) { + super(argName, `Range is ${range[0]} to ${range[1]}, but ${value} was provided.`, node); } } /** Thrown when an argument does not match an expected type. */ export class ArgumentTypeError extends ArgumentError { - constructor(argName: string, expectedType: string, actualType: string) { - super(argName, `Expected type '${expectedType}', but was '${actualType}'.`); + constructor(argName: string, expectedType: string, actualType: string, node?: Node) { + super(argName, `Expected type '${expectedType}', but was '${actualType}'.`, node); } } @@ -67,15 +80,15 @@ export namespace errors { /** Thrown when an action was taken that is not allowed. */ export class InvalidOperationError extends BaseError { - constructor(message: string) { - super(message); + constructor(message: string, node?: Node) { + super(message, node); } } /** Thrown when a certain behaviour or feature has not been implemented. */ export class NotImplementedError extends BaseError { - constructor(message = "Not implemented.") { - super(message); + constructor(message = "Not implemented.", node?: Node) { + super(message, node); } } @@ -148,8 +161,8 @@ export namespace errors { * Gets an error saying that a feature is not implemented for a certain syntax kind. * @param kind - Syntax kind that isn't implemented. */ - export function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind): never { - throw new NotImplementedError(`Not implemented feature for syntax kind '${getSyntaxKindName(kind)}'.`); + export function throwNotImplementedForSyntaxKindError(kind: ts.SyntaxKind, node?: Node): never { + throw new NotImplementedError(`Not implemented feature for syntax kind '${getSyntaxKindName(kind)}'.`, node); } /** @@ -167,9 +180,9 @@ export namespace errors { * @param value - Value to check. * @param errorMessage - Error message to throw when not defined. */ - export function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string)) { + export function throwIfNullOrUndefined(value: T | undefined, errorMessage: string | (() => string), node?: Node) { if (value == null) - throw new InvalidOperationError(typeof errorMessage === "string" ? errorMessage : errorMessage()); + throw new InvalidOperationError(typeof errorMessage === "string" ? errorMessage : errorMessage(), node); return value; } @@ -177,12 +190,12 @@ export namespace errors { * Throw if the value should have been the never type. * @param value - Value to check. */ - export function throwNotImplementedForNeverValueError(value: never): never { + export function throwNotImplementedForNeverValueError(value: never, sourceNode?: Node): never { const node = value as any as { kind: number }; if (node != null && typeof node.kind === "number") - return throwNotImplementedForSyntaxKindError(node.kind); + return throwNotImplementedForSyntaxKindError(node.kind, sourceNode); - throw new NotImplementedError(`Not implemented value: ${JSON.stringify(value)}`); + throw new NotImplementedError(`Not implemented value: ${JSON.stringify(value)}`, sourceNode); } /** @@ -206,3 +219,50 @@ export namespace errors { throw new InvalidOperationError(errorMessage); } } + +/** + * Returns the line of the given node inside its source file + * in a prettified format. + */ +function getPrettyNodeLocation(node: errors.Node) { + const source = getSourceLocation(node); + if (!source) + return undefined; + return `${source.filePath}:${source.loc.line}:${source.loc.character}\n` + + `> ${source.loc.line} | ${source.lineText}`; +} + +/** + * Returns the location of the given node inside its source file. + */ +function getSourceLocation(node: errors.Node) { + if (!isNode(node)) + return; + const sourceFile = node.getSourceFile(); + const sourceCode = sourceFile.getFullText(); + const start = node.getStart(); + const lineStart = sourceCode.lastIndexOf("\n", start) + 1; + const nextNewLinePos = sourceCode.indexOf("\n", start); + const lineEnd = nextNewLinePos === -1 ? sourceCode.length : nextNewLinePos; + const textStart = (start - lineStart > 40) ? start - 37 : lineStart; + const textEnd = (lineEnd - textStart > 80) ? textStart + 77 : lineEnd; + let lineText = ""; + if (textStart !== lineStart) + lineText += "..."; + lineText += sourceCode.substring(textStart, textEnd); + if (textEnd !== lineEnd) + lineText += "..."; + + return { + filePath: sourceFile.getFilePath(), + loc: { + line: StringUtils.getLineNumberAtPos(sourceCode, start), + character: start - lineStart + 1, // make 1-indexed + }, + lineText, + }; +} + +function isNode(node: unknown): node is errors.Node { + return typeof node === "object" && node !== null && ("getSourceFile" in node) && ("getStart" in node); +} diff --git a/packages/common/src/tests/errorsTests.ts b/packages/common/src/tests/errorsTests.ts index 3e95cf657..12b7b5bf0 100644 --- a/packages/common/src/tests/errorsTests.ts +++ b/packages/common/src/tests/errorsTests.ts @@ -1,144 +1,219 @@ import { expect } from "chai"; import { errors } from "../errors"; +import { StandardizedFilePath } from "../fileSystem"; import { ts } from "../typescript"; import { nameof } from "../utils"; -describe("helpers", () => { - describe(nameof(errors, "throwIfNotType"), () => { - it("should throw when not the same type", () => { - expect(() => errors.throwIfNotType(4, "string", "argName")).to.throw( - errors.ArgumentTypeError, - "Argument Error (argName): Expected type 'string', but was 'number'.", - ); - }); - - it("should not throw when the same type", () => { - expect(() => errors.throwIfNotType("", "string", "argName")).to.not.throw(); - }); - }); - - describe(nameof(errors, "throwIfWhitespaceOrNotString"), () => { - it("should throw when not a string", () => { - expect(() => errors.throwIfWhitespaceOrNotString(4 as any, "argName")).to.throw( - errors.ArgumentTypeError, - "Argument Error (argName): Expected type 'string', but was 'number'.", - ); - }); - - it("should throw when null", () => { - expect(() => errors.throwIfWhitespaceOrNotString(null as any, "argName")).to.throw( - errors.ArgumentTypeError, - "Argument Error (argName): Expected type 'string', but was 'object'.", - ); - }); +describe(nameof(errors, "throwIfNotType"), () => { + it("should throw when not the same type", () => { + expect(() => errors.throwIfNotType(4, "string", "argName")).to.throw( + errors.ArgumentTypeError, + "Argument Error (argName): Expected type 'string', but was 'number'.", + ); + }); + + it("should not throw when the same type", () => { + expect(() => errors.throwIfNotType("", "string", "argName")).to.not.throw(); + }); +}); + +describe(nameof(errors, "throwIfWhitespaceOrNotString"), () => { + it("should throw when not a string", () => { + expect(() => errors.throwIfWhitespaceOrNotString(4 as any, "argName")).to.throw( + errors.ArgumentTypeError, + "Argument Error (argName): Expected type 'string', but was 'number'.", + ); + }); + + it("should throw when null", () => { + expect(() => errors.throwIfWhitespaceOrNotString(null as any, "argName")).to.throw( + errors.ArgumentTypeError, + "Argument Error (argName): Expected type 'string', but was 'object'.", + ); + }); + + it("should throw when whitespace string", () => { + expect(() => errors.throwIfWhitespaceOrNotString(" ", "argName")).to.throw( + errors.ArgumentNullOrWhitespaceError, + "Argument Error (argName): Cannot be null or whitespace.", + ); + }); + + it("should throw when string that's not a whitespace string", () => { + expect(() => errors.throwIfWhitespaceOrNotString("str", "argName")).to.not.throw(); + }); +}); + +describe(nameof(errors, "throwIfOutOfRange"), () => { + it("should not throw when inside the bounds", () => { + expect(() => errors.throwIfOutOfRange(5, [1, 10], "arg")).to.not.throw(); + }); + + it("should throw when outside the inclusive lower bound", () => { + expect(() => errors.throwIfOutOfRange(0, [1, 10], "arg")).to.throw(); + }); + + it("should not throw when inside the inclusive lower bound", () => { + expect(() => errors.throwIfOutOfRange(1, [1, 10], "arg")).to.not.throw(); + }); + + it("should throw when outside the inclusive upper bound", () => { + expect(() => errors.throwIfOutOfRange(11, [1, 10], "arg")).to.throw(); + }); + + it("should not throw when inside the inclusive upper bound", () => { + expect(() => errors.throwIfOutOfRange(10, [1, 10], "arg")).to.not.throw(); + }); +}); + +describe(nameof(errors, "throwIfRangeOutOfRange"), () => { + it("should throw when the range is flipped", () => { + expect(() => errors.throwIfRangeOutOfRange([9, 2], [1, 10], "arg")).to.throw(); + }); + + it("should not throw when inside the bounds", () => { + expect(() => errors.throwIfRangeOutOfRange([2, 9], [1, 10], "arg")).to.not.throw(); + }); + + it("should throw when outside the inclusive lower bound", () => { + expect(() => errors.throwIfRangeOutOfRange([0, 9], [1, 10], "arg")).to.throw(); + }); + + it("should not throw when inside the inclusive lower or upper bound", () => { + expect(() => errors.throwIfRangeOutOfRange([1, 10], [1, 10], "arg")).to.not.throw(); + }); + + it("should throw when outside the inclusive upper bound", () => { + expect(() => errors.throwIfRangeOutOfRange([2, 11], [1, 10], "arg")).to.throw(); + }); +}); - it("should throw when whitespace string", () => { - expect(() => errors.throwIfWhitespaceOrNotString(" ", "argName")).to.throw( - errors.ArgumentNullOrWhitespaceError, - "Argument Error (argName): Cannot be null or whitespace.", - ); - }); - - it("should throw when string that's not a whitespace string", () => { - expect(() => errors.throwIfWhitespaceOrNotString("str", "argName")).to.not.throw(); - }); - }); - - describe(nameof(errors, "throwIfOutOfRange"), () => { - it("should not throw when inside the bounds", () => { - expect(() => errors.throwIfOutOfRange(5, [1, 10], "arg")).to.not.throw(); - }); - - it("should throw when outside the inclusive lower bound", () => { - expect(() => errors.throwIfOutOfRange(0, [1, 10], "arg")).to.throw(); - }); - - it("should not throw when inside the inclusive lower bound", () => { - expect(() => errors.throwIfOutOfRange(1, [1, 10], "arg")).to.not.throw(); - }); - - it("should throw when outside the inclusive upper bound", () => { - expect(() => errors.throwIfOutOfRange(11, [1, 10], "arg")).to.throw(); - }); - - it("should not throw when inside the inclusive upper bound", () => { - expect(() => errors.throwIfOutOfRange(10, [1, 10], "arg")).to.not.throw(); - }); - }); - - describe(nameof(errors, "throwIfRangeOutOfRange"), () => { - it("should throw when the range is flipped", () => { - expect(() => errors.throwIfRangeOutOfRange([9, 2], [1, 10], "arg")).to.throw(); - }); - - it("should not throw when inside the bounds", () => { - expect(() => errors.throwIfRangeOutOfRange([2, 9], [1, 10], "arg")).to.not.throw(); - }); - - it("should throw when outside the inclusive lower bound", () => { - expect(() => errors.throwIfRangeOutOfRange([0, 9], [1, 10], "arg")).to.throw(); - }); - - it("should not throw when inside the inclusive lower or upper bound", () => { - expect(() => errors.throwIfRangeOutOfRange([1, 10], [1, 10], "arg")).to.not.throw(); - }); - - it("should throw when outside the inclusive upper bound", () => { - expect(() => errors.throwIfRangeOutOfRange([2, 11], [1, 10], "arg")).to.throw(); - }); - }); - - describe(nameof(errors, "throwIfNegative"), () => { - it("should throw when negative", () => { - expect(() => errors.throwIfNegative(-1, "arg")).to.throw(); - }); - - it("should not throw when positive", () => { - expect(() => errors.throwIfNegative(1, "arg")).to.not.throw(); - }); - - it("should not throw when 0", () => { - expect(() => errors.throwIfNegative(0, "arg")).to.not.throw(); - }); - }); - - describe(nameof(errors, "throwNotImplementedForSyntaxKindError"), () => { - let result: Error; - try { - errors.throwNotImplementedForSyntaxKindError(ts.SyntaxKind.EnumDeclaration); - } catch (ex: any) { - result = ex; - } +describe(nameof(errors, "throwIfNegative"), () => { + it("should throw when negative", () => { + expect(() => errors.throwIfNegative(-1, "arg")).to.throw(); + }); - it("should return a NotImplementedError", () => { - expect(result).to.be.instanceOf(errors.NotImplementedError); - }); + it("should not throw when positive", () => { + expect(() => errors.throwIfNegative(1, "arg")).to.not.throw(); + }); - it("should have the correct message", () => { - expect(result.message).to.equal("Not implemented feature for syntax kind 'EnumDeclaration'."); - }); - }); - - describe(nameof(errors, "throwIfNotEqual"), () => { - it("should throw when not equal", () => { - expect(() => errors.throwIfNotEqual(1, 2, "New length should equal old length.")).to.throw( - errors.InvalidOperationError, - "Expected 1 to equal 2. New length should equal old length.", - ); - }); + it("should not throw when 0", () => { + expect(() => errors.throwIfNegative(0, "arg")).to.not.throw(); + }); +}); + +describe(nameof(errors, "throwNotImplementedForSyntaxKindError"), () => { + let result: Error; + try { + errors.throwNotImplementedForSyntaxKindError(ts.SyntaxKind.EnumDeclaration); + } catch (ex: any) { + result = ex; + } - it("should not throw when equal", () => { - expect(() => errors.throwIfNotEqual(2, 2, "New length should equal old length.")).to.not.throw(); - }); + it("should return a NotImplementedError", () => { + expect(result).to.be.instanceOf(errors.NotImplementedError); }); - describe(nameof(errors, "throwIfTrue"), () => { - it("should throw when true", () => { - expect(() => errors.throwIfTrue(true, "message")).to.throw(errors.InvalidOperationError, "message"); - }); + it("should have the correct message", () => { + expect(result.message).to.equal("Not implemented feature for syntax kind 'EnumDeclaration'."); + }); +}); + +describe(nameof(errors, "throwIfNotEqual"), () => { + it("should throw when not equal", () => { + expect(() => errors.throwIfNotEqual(1, 2, "New length should equal old length.")).to.throw( + errors.InvalidOperationError, + "Expected 1 to equal 2. New length should equal old length.", + ); + }); + + it("should not throw when equal", () => { + expect(() => errors.throwIfNotEqual(2, 2, "New length should equal old length.")).to.not.throw(); + }); +}); + +describe(nameof(errors, "throwIfTrue"), () => { + it("should throw when true", () => { + expect(() => errors.throwIfTrue(true, "message")).to.throw(errors.InvalidOperationError, "message"); + }); + + it("should not throw when false", () => { + expect(() => errors.throwIfTrue(false, "message")).to.not.throw(); + }); +}); + +describe("with error context", () => { + it("should get text", () => { + const sourceFile = { + getSourceFile() { + return { + getFilePath() { + return "/test.ts" as StandardizedFilePath; + }, + getFullText() { + return `1;\nconst test = 123456789;\nasdf;`; + }, + }; + }, + getStart() { + return 16; + }, + }; + expect(new errors.InvalidOperationError("Message.", sourceFile).message).to.equal( + [ + "Message.", + "", + "/test.ts:2:14", + "> 2 | const test = 123456789;", + ].join("\n"), + ); + }); - it("should not throw when false", () => { - expect(() => errors.throwIfTrue(false, "message")).to.not.throw(); - }); + it("should get text when truncating start and end", () => { + let pos = 80; + const sourceFile = { + getSourceFile() { + return { + getFilePath() { + return "/test.ts" as StandardizedFilePath; + }, + getFullText() { + let text = ""; + for (let i = 0; i < 20; i++) + text += `${i}123456789`; + return text; + }, + }; + }, + getStart() { + return pos; + }, + }; + expect(new errors.InvalidOperationError("Message.", sourceFile).message).to.equal( + [ + "Message.", + "", + "/test.ts:1:81", + "> 1 | ...34567895123456789612345678971234567898123456789912345678910123456789111234567...", + ].join("\n"), + ); + pos = 0; + expect(new errors.InvalidOperationError("Message.", sourceFile).message).to.equal( + [ + "Message.", + "", + "/test.ts:1:1", + "> 1 | 01234567891123456789212345678931234567894123456789512345678961234567897123456...", + ].join("\n"), + ); + pos = 20 * 10; + expect(new errors.InvalidOperationError("Message.", sourceFile).message).to.equal( + [ + "Message.", + "", + "/test.ts:1:201", + "> 1 | ...78916123456789171234567891812345678919123456789", + ].join("\n"), + ); }); }); diff --git a/packages/ts-morph/lib/ts-morph.d.ts b/packages/ts-morph/lib/ts-morph.d.ts index 730c3da43..cb205b26f 100644 --- a/packages/ts-morph/lib/ts-morph.d.ts +++ b/packages/ts-morph/lib/ts-morph.d.ts @@ -201,7 +201,7 @@ export declare class Directory { /** Gets the directory path's base name. */ getBaseName(): string; /** Gets the parent directory or throws if it doesn't exist or was never added to the project. */ - getParentOrThrow(): Directory; + getParentOrThrow(message?: string | (() => string)): Directory; /** Gets the parent directory if it exists and was added to the project. */ getParent(): Directory | undefined; /** @@ -541,7 +541,7 @@ export declare class Project { * Gets a directory by the specified path or throws if it doesn't exist. * @param dirPath - Path to create the directory at. */ - getDirectoryOrThrow(dirPath: string): Directory; + getDirectoryOrThrow(dirPath: string, message?: string | (() => string)): Directory; /** * Gets a directory by the specified path or returns undefined if it doesn't exist. * @param dirPath - Directory path. @@ -637,7 +637,7 @@ export declare class Project { * Gets the specified ambient module symbol or throws if not found. * @param moduleName - The ambient module name with or without quotes. */ - getAmbientModuleOrThrow(moduleName: string): Symbol; + getAmbientModuleOrThrow(moduleName: string, message?: string | (() => string)): Symbol; /** Gets the ambient module symbols (ex. modules in the @types folder or node_modules). */ getAmbientModules(): Symbol[]; /** Saves all the unsaved source files to the file system and deletes all deleted files. */ @@ -912,7 +912,7 @@ export interface AmbientableNode { /** Gets the declare keyword or undefined if none exists. */ getDeclareKeyword(): Node | undefined; /** Gets the declare keyword or throws if it doesn't exist. */ - getDeclareKeywordOrThrow(): Node; + getDeclareKeywordOrThrow(message?: string | (() => string)): Node; /** Gets if the node is ambient. */ isAmbient(): boolean; /** @@ -973,7 +973,7 @@ export interface AsyncableNode { /** Gets the async keyword or undefined if none exists. */ getAsyncKeyword(): Node | undefined; /** Gets the async keyword or throws if none exists. */ - getAsyncKeywordOrThrow(): Node; + getAsyncKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is async. * @param value - If it should be async or not. @@ -990,7 +990,7 @@ export interface AwaitableNode { /** Gets the await token or undefined if none exists. */ getAwaitKeyword(): Node | undefined; /** Gets the await token or throws if none exists. */ - getAwaitKeywordOrThrow(): Node; + getAwaitKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is awaited. * @param value - If it should be awaited or not. @@ -1022,7 +1022,7 @@ export declare function BodyableNode string)): Node; /** Gets the body if it exists. */ getBody(): Node | undefined; /** Gets the body text without leading whitespace, leading indentation, or trailing whitespace. Returns undefined if there is no body. */ @@ -1107,7 +1107,7 @@ export interface DotDotDotTokenableNode { /** Gets the dot dot dot token (...) if it exists or returns undefined */ getDotDotDotToken(): Node | undefined; /** Gets the dot dot dot token (...) if it exists or throws if not. */ - getDotDotDotTokenOrThrow(): Node; + getDotDotDotTokenOrThrow(message?: string | (() => string)): Node; } declare type DotDotDotTokenableNodeExtensionType = Node | undefined; /** Gets the exclamation token node or throws. */ - getExclamationTokenNodeOrThrow(): Node; + getExclamationTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a exclamation token. * @param value - If it should have a exclamation token or not. @@ -1158,13 +1158,13 @@ export interface ExportGetableNode { /** Gets the export keyword or undefined if none exists. */ getExportKeyword(): Node | undefined; /** Gets the export keyword or throws if none exists. */ - getExportKeywordOrThrow(): Node; + getExportKeywordOrThrow(message?: string | (() => string)): Node; /** If the node has the default keyword. */ hasDefaultKeyword(): boolean; /** Gets the default keyword or undefined if none exists. */ getDefaultKeyword(): Node | undefined; /** Gets the default keyword or throws if none exists. */ - getDefaultKeywordOrThrow(): Node; + getDefaultKeywordOrThrow(message?: string | (() => string)): Node; /** Gets if the node is exported from a namespace, is a default export, or is a named export. */ isExported(): boolean; /** Gets if this node is a default export of a file. */ @@ -1220,7 +1220,7 @@ export interface GeneratorableNode { /** Gets the asterisk token or undefined if none exists. */ getAsteriskToken(): Node | undefined; /** Gets the asterisk token or throws if none exists. */ - getAsteriskTokenOrThrow(): Node; + getAsteriskTokenOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is a generator. * @param value - If it should be a generator or not. @@ -1316,7 +1316,7 @@ export interface InitializerExpressionGetableNode { /** Gets the initializer if it's a certain kind. */ getInitializerIfKind(kind: TKind): KindToExpressionMappings[TKind] | undefined; /** Gets the initializer or throw. */ - getInitializerOrThrow(): Expression; + getInitializerOrThrow(message?: string | (() => string)): Expression; } declare type InitializerExpressionGetableNodeExtensionType = Node>): ExportDeclaration[]; - getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration | undefined; + getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration | undefined; /** * Gets the first export declaration that matches a module specifier, or undefined if it doesn't exist. * @param module - Module specifier to get the export declaration by. @@ -1480,12 +1480,12 @@ export interface ModuledNode { * Gets the first export declaration that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export declaration by. */ - getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration; + getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration; /** * Gets the first export declaration that matches a module specifier, or throws if it doesn't exist. * @param module - Module specifier to get the export declaration by. */ - getExportDeclarationOrThrow(moduleSpecifier: string): ExportDeclaration; + getExportDeclarationOrThrow(moduleSpecifier: string, message?: string | (() => string)): ExportDeclaration; /** Get the export declarations. */ getExportDeclarations(): ExportDeclaration[]; /** @@ -1519,13 +1519,13 @@ export interface ModuledNode { * Gets the first export assignment that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export assignment by. */ - getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean): ExportAssignment; + getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean, message?: string | (() => string)): ExportAssignment; /** Get the file's export assignments. */ getExportAssignments(): ExportAssignment[]; /** Gets the default export symbol. */ getDefaultExportSymbol(): Symbol | undefined; /** Gets the default export symbol or throws if it doesn't exist. */ - getDefaultExportSymbolOrThrow(): Symbol; + getDefaultExportSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the export symbols. */ getExportSymbols(): Symbol[]; /** @@ -1576,11 +1576,11 @@ export interface NameableNodeSpecific { /** Gets the name node if it exists. */ getNameNode(): Identifier | undefined; /** Gets the name node if it exists, or throws. */ - getNameNodeOrThrow(): Identifier; + getNameNodeOrThrow(message?: string | (() => string)): Identifier; /** Gets the name if it exists. */ getName(): string | undefined; /** Gets the name if it exists, or throws. */ - getNameOrThrow(): string; + getNameOrThrow(message?: string | (() => string)): string; /** Removes the name from the node. */ removeName(): this; } @@ -1643,7 +1643,7 @@ export interface OverrideableNode { /** Gets the override keyword or undefined if none exists. */ getOverrideKeyword(): Node | undefined; /** Gets the override keyword or throws if none exists. */ - getOverrideKeywordOrThrow(): Node; + getOverrideKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node has an override keyword. * @param value - If it should have an override keyword or not. @@ -1712,7 +1712,7 @@ export interface QuestionDotTokenableNode { /** Gets the question dot token node or returns undefined if it doesn't exist. */ getQuestionDotTokenNode(): Node | undefined; /** Gets the question dot token node or throws. */ - getQuestionDotTokenNodeOrThrow(): Node; + getQuestionDotTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question dot token. * @param value - If it should have a question dot token or not. @@ -1731,7 +1731,7 @@ export interface QuestionTokenableNode { /** Gets the question token node or returns undefined if it doesn't exist. */ getQuestionTokenNode(): Node | undefined; /** Gets the question token node or throws. */ - getQuestionTokenNodeOrThrow(): Node; + getQuestionTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question token. * @param value - If it should have a question token or not. @@ -1750,7 +1750,7 @@ export interface ReadonlyableNode { /** Gets the readonly keyword, or undefined if none exists. */ getReadonlyKeyword(): Node | undefined; /** Gets the readonly keyword, or throws if none exists. */ - getReadonlyKeywordOrThrow(): Node; + getReadonlyKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if this node is readonly. * @param value - If readonly or not. @@ -1767,7 +1767,7 @@ export interface ReturnTypedNode { /** Gets the return type node or undefined if none exists. */ getReturnTypeNode(): TypeNode | undefined; /** Gets the return type node or throws if none exists. */ - getReturnTypeNodeOrThrow(): TypeNode; + getReturnTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the return type of the node. * @param textOrWriterFunction - Text or writer function to set the return type with. @@ -1826,7 +1826,7 @@ export interface StaticableNode { /** Gets the static keyword, or undefined if none exists. */ getStaticKeyword(): Node | undefined; /** Gets the static keyword, or throws if none exists. */ - getStaticKeywordOrThrow(): Node; + getStaticKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is static. * @param value - If it should be static or not. @@ -1915,7 +1915,7 @@ export interface TypedNode { /** Gets the type node or undefined if none exists. */ getTypeNode(): TypeNode | undefined; /** Gets the type node or throws if none exists. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type. * @param textOrWriterFunction - Text or writer function to set the type with. @@ -2219,7 +2219,7 @@ export declare class ArrayBindingPattern extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BindingElementBase: Constructor & Constructor & Constructor & typeof Node; @@ -2230,7 +2230,7 @@ export declare class BindingElement extends BindingElementBase string)): PropertyName; /** * Gets binding element's property name node or returns undefined if not found. * @@ -2240,7 +2240,7 @@ export declare class BindingElement extends BindingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ObjectBindingPattern extends Node { @@ -2249,7 +2249,7 @@ export declare class ObjectBindingPattern extends Node /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function AbstractableNode>(Base: T): Constructor & T; @@ -2260,7 +2260,7 @@ export interface AbstractableNode { /** Gets the abstract keyword or undefined if it doesn't exist. */ getAbstractKeyword(): Node | undefined; /** Gets the abstract keyword or throws if it doesn't exist. */ - getAbstractKeywordOrThrow(): Node; + getAbstractKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is abstract. * @param isAbstract - If it should be abstract or not. @@ -2285,7 +2285,7 @@ interface ClassLikeDeclarationBaseSpecific { /** Removes the extends expression, if it exists. */ removeExtends(): this; /** Gets the extends expression or throws if it doesn't exist. */ - getExtendsOrThrow(): ExpressionWithTypeArguments; + getExtendsOrThrow(message?: string | (() => string)): ExpressionWithTypeArguments; /** Gets the extends expression or returns undefined if it doesn't exist. */ getExtends(): ExpressionWithTypeArguments | undefined; /** @@ -2701,7 +2701,7 @@ interface ClassLikeDeclarationBaseSpecific { * * Note: Use getBaseTypes if you need to get the mixins. */ - getBaseClassOrThrow(): ClassDeclaration; + getBaseClassOrThrow(message?: string | (() => string)): ClassDeclaration; /** * Gets the base class. * @@ -2743,7 +2743,7 @@ export declare class ClassDeclaration extends ClassDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ClassElement extends Node { @@ -2757,7 +2757,7 @@ export declare class ClassExpression extends ClassExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ClassStaticBlockDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2783,7 +2783,7 @@ export declare class ClassStaticBlockDeclaration extends ClassStaticBlockDeclara /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentClassElement extends ClassElement { @@ -2825,7 +2825,7 @@ export declare class ConstructorDeclaration extends ConstructorDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const GetAccessorDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2839,13 +2839,13 @@ export declare class GetAccessorDeclaration extends GetAccessorDeclarationBase string)): SetAccessorDeclaration; /** Gets the structure equivalent to this node. */ getStructure(): GetAccessorDeclarationStructure; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const MethodDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2884,7 +2884,7 @@ export declare class MethodDeclaration extends MethodDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertyDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2906,7 +2906,7 @@ export declare class PropertyDeclaration extends PropertyDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SetAccessorDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof ClassElement; @@ -2920,13 +2920,13 @@ export declare class SetAccessorDeclaration extends SetAccessorDeclarationBase string)): GetAccessorDeclaration; /** Gets the structure equivalent to this node. */ getStructure(): SetAccessorDeclarationStructure; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentRange extends TextRange { @@ -3351,7 +3351,7 @@ export declare class Node { */ print(options?: PrintNodeOptions): string; /** Gets the symbol or throws an error if it doesn't exist. */ - getSymbolOrThrow(): Symbol; + getSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the compiler symbol or undefined if it doesn't exist. */ getSymbol(): Symbol | undefined; /** @@ -3368,7 +3368,7 @@ export declare class Node { * WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break. * @param name - Name of the local symbol. */ - getLocalOrThrow(name: string): Symbol; + getLocalOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the specified local symbol by name or returns undefined if it doesn't exist. * @@ -3399,7 +3399,7 @@ export declare class Node { * Gets the node as the specified kind if it is equal to that kind, otherwise throws. * @param kind - Syntax kind. */ - asKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + asKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Returns if the node is the specified kind. * @@ -3416,12 +3416,12 @@ export declare class Node { * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => node is T): T; + getFirstChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => boolean): Node; + getFirstChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the first child by a condition. * @param condition - Condition. @@ -3436,12 +3436,12 @@ export declare class Node { * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => node is T): T; + getLastChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => boolean): Node; + getLastChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the last child by a condition. * @param condition - Condition. @@ -3456,12 +3456,12 @@ export declare class Node { * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => node is T): T; + getFirstDescendantOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => boolean): Node; + getFirstDescendantOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the first descendant by a condition. * @param condition - Condition. @@ -3476,12 +3476,12 @@ export declare class Node { * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => node is T): T; + getPreviousSiblingOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => boolean): Node; + getPreviousSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the previous sibling. * @param condition - Optional condition for getting the previous sibling. @@ -3496,12 +3496,12 @@ export declare class Node { * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => node is T): T; + getNextSiblingOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => boolean): Node; + getNextSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; /** * Gets the next sibling. * @param condition - Optional condition for getting the next sibling. @@ -3532,7 +3532,7 @@ export declare class Node { */ getChildAtIndex(index: number): Node; /** Gets the child syntax list or throws if it doesn't exist. */ - getChildSyntaxListOrThrow(): SyntaxList; + getChildSyntaxListOrThrow(message?: string | (() => string)): SyntaxList; /** Gets the child syntax list if it exists. */ getChildSyntaxList(): SyntaxList | undefined; /** @@ -3640,19 +3640,19 @@ export declare class Node { /** Get the node's parent. */ getParent(): Node | undefined; /** Gets the parent or throws an error if it doesn't exist. */ - getParentOrThrow(): Node; + getParentOrThrow(message?: string | (() => string)): Node; /** * Goes up the parents (ancestors) of the node while a condition is true. * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T): T; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T, message?: string | (() => string)): T; /** * Goes up the parents (ancestors) of the node while a condition is true. * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean): Node; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean, message?: string | (() => string)): Node; /** * Goes up the parents (ancestors) of the node while a condition is true. * Returns undefined if the initial parent doesn't match the condition. @@ -3670,7 +3670,7 @@ export declare class Node { * Throws if the initial parent is not the specified syntax kind. * @param kind - Syntax kind to check for. */ - getParentWhileKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getParentWhileKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Goes up the parents (ancestors) of the node while the parent is the specified syntax kind. * Returns undefined if the initial parent is not the specified syntax kind. @@ -3682,7 +3682,7 @@ export declare class Node { /** Gets if this node is in a syntax list. */ isInSyntaxList(): boolean; /** Gets the parent if it's a syntax list or throws an error otherwise. */ - getParentSyntaxListOrThrow(): SyntaxList; + getParentSyntaxListOrThrow(message?: string | (() => string)): SyntaxList; /** Gets the parent if it's a syntax list. */ getParentSyntaxList(): SyntaxList | undefined; /** Gets the child index of this node relative to the parent. */ @@ -3777,7 +3777,7 @@ export declare class Node { * Gets the first child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstChildByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first child by syntax kind. * @param kind - Syntax kind. @@ -3787,7 +3787,7 @@ export declare class Node { * Gets the first child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstChildIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first child if it matches the specified syntax kind. * @param kind - Syntax kind. @@ -3797,7 +3797,7 @@ export declare class Node { * Gets the last child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getLastChildByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the last child by syntax kind. * @param kind - Syntax kind. @@ -3807,7 +3807,7 @@ export declare class Node { * Gets the last child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getLastChildIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the last child if it matches the specified syntax kind. * @param kind - Syntax kind. @@ -3818,7 +3818,7 @@ export declare class Node { * @param index - Child index to get. * @param kind - Expected kind. */ - getChildAtIndexIfKindOrThrow(index: number, kind: TKind): KindToNodeMappings[TKind]; + getChildAtIndexIfKindOrThrow(index: number, kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the child at the specified index if it's the specified kind or returns undefined. * @param index - Child index to get. @@ -3829,12 +3829,12 @@ export declare class Node { * Gets the previous sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getPreviousSiblingIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getPreviousSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the next sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getNextSiblingIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getNextSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the previous sibling if it matches the specified kind. * @param kind - Kind to check. @@ -3846,22 +3846,22 @@ export declare class Node { */ getNextSiblingIfKind(kind: TKind): KindToNodeMappings[TKind] | undefined; /** Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T): T; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T, message?: string | (() => string)): T; /** Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean): Node; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean, message?: string | (() => string)): Node; /** Gets the parent if it matches a certain condition. */ getParentIf(condition: (parent: Node | undefined, node: Node) => parent is T): T | undefined; /** Gets the parent if it matches a certain condition. */ getParentIf(condition: (parent: Node | undefined, node: Node) => boolean): Node | undefined; /** Gets the parent if it's a certain syntax kind or throws. */ - getParentIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getParentIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** Gets the parent if it's a certain syntax kind. */ getParentIfKind(kind: TKind): KindToNodeMappings[TKind] | undefined; /** * Gets the first ancestor by syntax kind or throws if not found. * @param kind - Syntax kind. */ - getFirstAncestorByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstAncestorByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Get the first ancestor by syntax kind. * @param kind - Syntax kind. @@ -3896,7 +3896,7 @@ export declare class Node { * Gets the first descendant by syntax kind or throws. * @param kind - Syntax kind. */ - getFirstDescendantByKindOrThrow(kind: TKind): KindToNodeMappings[TKind]; + getFirstDescendantByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind]; /** * Gets the first descendant by syntax kind. * @param kind - Syntax kind. @@ -4532,7 +4532,7 @@ export declare class SyntaxList extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TextRange { @@ -4597,7 +4597,7 @@ export declare class Decorator extends DecoratorBase { */ setIsDecoratorFactory(isDecoratorFactory: boolean): this; /** Gets the call expression if a decorator factory, or throws. */ - getCallExpressionOrThrow(): CallExpression; + getCallExpressionOrThrow(message?: string | (() => string)): CallExpression; /** Gets the call expression if a decorator factory. */ getCallExpression(): CallExpression | undefined; /** Gets the decorator's arguments from its call expression. */ @@ -4680,7 +4680,7 @@ export declare class Decorator extends DecoratorBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function JSDocPropertyLikeTag>(Base: T): Constructor & T; @@ -4689,7 +4689,7 @@ export interface JSDocPropertyLikeTag { /** Gets the type expression node of the JS doc tag if it exists. */ getTypeExpression(): JSDocTypeExpression | undefined; /** Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; /** Gets the name of the JS doc property like tag. */ getName(): string; /** Gets the name node of the JS doc property like tag. */ @@ -4705,7 +4705,7 @@ export interface JSDocTypeExpressionableTag { /** Gets the type expression node of the JS doc tag if it exists. */ getTypeExpression(): JSDocTypeExpression | undefined; /** Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; } declare type JSDocTypeExpressionableTagExtensionType = Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc all type. */ @@ -4787,7 +4787,7 @@ export declare class JSDocAllType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc augments tag node. */ @@ -4795,7 +4795,7 @@ export declare class JSDocAugmentsTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc author tag node. */ @@ -4803,7 +4803,7 @@ export declare class JSDocAuthorTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc callback tag node. */ @@ -4811,7 +4811,7 @@ export declare class JSDocCallbackTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc class tag node. */ @@ -4819,7 +4819,7 @@ export declare class JSDocClassTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc deprecated tag node. */ @@ -4827,7 +4827,7 @@ export declare class JSDocDeprecatedTag extends JSDocTag /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc enum tag node. */ @@ -4835,7 +4835,7 @@ export declare class JSDocEnumTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocFunctionTypeBase: Constructor & typeof JSDocType; @@ -4845,7 +4845,7 @@ export declare class JSDocFunctionType extends JSDocFunctionTypeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc implements tag node. */ @@ -4853,7 +4853,7 @@ export declare class JSDocImplementsTag extends JSDocTag /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link node. */ @@ -4861,7 +4861,7 @@ export declare class JSDocLink extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link code node. */ @@ -4869,7 +4869,7 @@ export declare class JSDocLinkCode extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc link plain node. */ @@ -4877,7 +4877,7 @@ export declare class JSDocLinkPlain extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc member name node. */ @@ -4885,7 +4885,7 @@ export declare class JSDocMemberName extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc namepath type. */ @@ -4895,7 +4895,7 @@ export declare class JSDocNamepathType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc name reference. */ @@ -4905,7 +4905,7 @@ export declare class JSDocNameReference extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc non-nullable type. */ @@ -4916,7 +4916,7 @@ export declare class JSDocNonNullableType extends JSDocType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc nullable type. */ @@ -4927,7 +4927,7 @@ export declare class JSDocNullableType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc optional type. */ @@ -4937,7 +4937,7 @@ export declare class JSDocOptionalType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc override tag node. */ @@ -4945,7 +4945,7 @@ export declare class JSDocOverrideTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocParameterTagBase: Constructor & typeof JSDocTag; @@ -4955,7 +4955,7 @@ export declare class JSDocParameterTag extends JSDocParameterTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc private tag node. */ @@ -4963,7 +4963,7 @@ export declare class JSDocPrivateTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocPropertyTagBase: Constructor & typeof JSDocTag; @@ -4973,7 +4973,7 @@ export declare class JSDocPropertyTag extends JSDocPropertyTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc protected tag node. */ @@ -4981,7 +4981,7 @@ export declare class JSDocProtectedTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc public tag node. */ @@ -4989,7 +4989,7 @@ export declare class JSDocPublicTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc readonly tag node. */ @@ -4997,7 +4997,7 @@ export declare class JSDocReadonlyTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocReturnTagBase: Constructor & typeof JSDocTag; @@ -5007,7 +5007,7 @@ export declare class JSDocReturnTag extends JSDocReturnTagBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocSeeTagBase: Constructor & typeof JSDocTag; @@ -5017,7 +5017,7 @@ export declare class JSDocSeeTag extends JSDocSeeTagBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc signature node. */ @@ -5027,7 +5027,7 @@ export declare class JSDocSignature extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocTagBase: typeof Node; @@ -5081,11 +5081,11 @@ export declare class JSDocTemplateTag extends JSDocTemplateTagBase string)): JSDocTypeExpression; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc text node. */ @@ -5093,7 +5093,7 @@ export declare class JSDocText extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JSDocThisTagBase: Constructor & typeof JSDocTag; @@ -5103,7 +5103,7 @@ export declare class JSDocThisTag extends JSDocThisTagBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type node. */ @@ -5115,7 +5115,7 @@ export declare class JSDocTypedefTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type expression node. */ @@ -5125,7 +5125,7 @@ export declare class JSDocTypeExpression extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type literal. */ @@ -5137,7 +5137,7 @@ export declare class JSDocTypeLiteral extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc type tag node. */ @@ -5147,7 +5147,7 @@ export declare class JSDocTypeTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc unknown tag node. */ @@ -5155,7 +5155,7 @@ export declare class JSDocUnknownTag extends JSDocTag { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc unknown type. */ @@ -5163,7 +5163,7 @@ export declare class JSDocUnknownType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** JS doc variadic type. */ @@ -5173,7 +5173,7 @@ export declare class JSDocVariadicType extends JSDocType { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentEnumMember extends Node { @@ -5268,7 +5268,7 @@ export declare class EnumDeclaration extends EnumDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const EnumMemberBase: Constructor & Constructor & Constructor & typeof Node; @@ -5296,7 +5296,7 @@ export declare class EnumMember extends EnumMemberBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ArrayDestructuringAssignmentBase: typeof AssignmentExpression; @@ -5307,7 +5307,7 @@ export declare class ArrayDestructuringAssignment extends ArrayDestructuringAssi /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ArrayLiteralExpression extends PrimaryExpression { @@ -5360,7 +5360,7 @@ export declare class ArrayLiteralExpression extends PrimaryExpression; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AsExpressionBase: Constructor & Constructor & typeof Expression; @@ -5369,7 +5369,7 @@ export declare class AsExpression extends AsExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssignmentExpressionBase: typeof BinaryExpression; @@ -5385,7 +5385,7 @@ export declare class AwaitExpression extends AwaitExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BinaryExpressionBase: typeof Expression; @@ -5414,7 +5414,7 @@ export declare class CommaListExpression extends CommaListExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ConditionalExpressionBase: typeof Expression; @@ -5433,7 +5433,7 @@ export declare class ConditionalExpression extends ConditionalExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DeleteExpressionBase: Constructor & typeof UnaryExpression; @@ -5442,7 +5442,7 @@ export declare class DeleteExpression extends DeleteExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ElementAccessExpressionBase: Constructor & Constructor & typeof MemberExpression; @@ -5451,7 +5451,7 @@ export declare class ElementAccessExpression; + getArgumentExpressionOrThrow(message?: string | (() => string)): Expression; } export declare class Expression extends Node { @@ -5465,7 +5465,7 @@ export interface ExpressionableNode { /** Gets the expression if it exists or returns undefined. */ getExpression(): Expression | undefined; /** Gets the expression if it exists or throws. */ - getExpressionOrThrow(): Expression; + getExpressionOrThrow(message?: string | (() => string)): Expression; /** Gets the expression if it is of the specified syntax kind or returns undefined. */ getExpressionIfKind(kind: TKind): KindToExpressionMappings[TKind] | undefined; /** Gets the expression if it is of the specified syntax kind or throws. */ @@ -5543,7 +5543,7 @@ export declare class ImportExpression extends ImportExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class LeftHandSideExpression extends UpdateExpression { @@ -5565,7 +5565,7 @@ export declare class MetaProperty extends MetaPropertyBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NewExpressionBase: Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -5574,7 +5574,7 @@ export declare class NewExpression extends NewExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NonNullExpressionBase: Constructor & typeof LeftHandSideExpression; @@ -5583,7 +5583,7 @@ export declare class NonNullExpression extends NonNullExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentObjectLiteralElement extends ObjectLiteralElement { @@ -5597,7 +5597,7 @@ export declare class ObjectDestructuringAssignment extends ObjectDestructuringAs /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ObjectLiteralElement extends Node { @@ -5797,7 +5797,7 @@ export declare class ObjectLiteralExpression extends ObjectLiteralExpressionBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertyAssignmentBase: Constructor & Constructor & Constructor & typeof ObjectLiteralElement; @@ -5824,7 +5824,7 @@ export declare class PropertyAssignment extends PropertyAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ShorthandPropertyAssignmentBase: Constructor & Constructor & Constructor & typeof ObjectLiteralElement; @@ -5833,11 +5833,11 @@ export declare class ShorthandPropertyAssignment extends ShorthandPropertyAssign /** Gets if the shorthand property assignment has an object assignment initializer. */ hasObjectAssignmentInitializer(): boolean; /** Gets the object assignment initializer or throws if it doesn't exist. */ - getObjectAssignmentInitializerOrThrow(): Expression; + getObjectAssignmentInitializerOrThrow(message?: string | (() => string)): Expression; /** Gets the object assignment initializer if it exists. */ getObjectAssignmentInitializer(): Expression | undefined; /** Gets the equals token or throws if it doesn't exist. */ - getEqualsTokenOrThrow(): Node; + getEqualsTokenOrThrow(message?: string | (() => string)): Node; /** Gets the equals token if it exists. */ getEqualsToken(): Node | undefined; /** @@ -5863,7 +5863,7 @@ export declare class ShorthandPropertyAssignment extends ShorthandPropertyAssign /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SpreadAssignmentBase: Constructor & typeof ObjectLiteralElement; @@ -5879,7 +5879,7 @@ export declare class SpreadAssignment extends SpreadAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const OmittedExpressionBase: typeof Expression; @@ -5888,7 +5888,7 @@ export declare class OmittedExpression extends OmittedExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ParenthesizedExpressionBase: Constructor & typeof Expression; @@ -5897,7 +5897,7 @@ export declare class ParenthesizedExpression extends ParenthesizedExpressionBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PartiallyEmittedExpressionBase: Constructor & typeof Expression; @@ -5906,7 +5906,7 @@ export declare class PartiallyEmittedExpression extends PartiallyEmittedExpressi /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PostfixUnaryExpressionBase: typeof UnaryExpression; @@ -5919,7 +5919,7 @@ export declare class PostfixUnaryExpression extends PostfixUnaryExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PrefixUnaryExpressionBase: typeof UnaryExpression; @@ -5932,7 +5932,7 @@ export declare class PrefixUnaryExpression extends PrefixUnaryExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class PrimaryExpression extends MemberExpression { @@ -5949,7 +5949,7 @@ export declare class SatisfiesExpression extends SatisfiesExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SpreadElementBase: Constructor & typeof Expression; @@ -5958,7 +5958,7 @@ export declare class SpreadElement extends SpreadElementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperElementAccessExpressionBase: Constructor & typeof ElementAccessExpression; @@ -5967,7 +5967,7 @@ export declare class SuperElementAccessExpression extends SuperElementAccessExpr /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperExpressionBase: typeof PrimaryExpression; @@ -5976,7 +5976,7 @@ export declare class SuperExpression extends SuperExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const SuperPropertyAccessExpressionBase: Constructor & typeof PropertyAccessExpression; @@ -5985,7 +5985,7 @@ export declare class SuperPropertyAccessExpression extends SuperPropertyAccessEx /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ThisExpressionBase: typeof PrimaryExpression; @@ -5994,7 +5994,7 @@ export declare class ThisExpression extends ThisExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeAssertionBase: Constructor & Constructor & typeof UnaryExpression; @@ -6003,7 +6003,7 @@ export declare class TypeAssertion extends TypeAssertionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeOfExpressionBase: Constructor & typeof UnaryExpression; @@ -6012,7 +6012,7 @@ export declare class TypeOfExpression extends TypeOfExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class UnaryExpression extends Expression { @@ -6027,7 +6027,7 @@ export declare class VoidExpression extends VoidExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const YieldExpressionBase: Constructor & Constructor & typeof Expression; @@ -6036,7 +6036,7 @@ export declare class YieldExpression extends YieldExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ArrowFunctionBase: Constructor & Constructor & Constructor & Constructor & typeof Expression; @@ -6047,7 +6047,7 @@ export declare class ArrowFunction extends ArrowFunctionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -6088,7 +6088,7 @@ export declare class FunctionDeclaration extends FunctionDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionExpressionBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -6097,7 +6097,7 @@ export declare class FunctionExpression extends FunctionExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function FunctionLikeDeclaration>(Base: T): Constructor & T; @@ -6115,7 +6115,7 @@ export interface OverloadableNode { /** Gets the implementation or undefined if it doesn't exist. */ getImplementation(): this | undefined; /** Gets the implementation or throws if it doesn't exist. */ - getImplementationOrThrow(): this; + getImplementationOrThrow(message?: string | (() => string)): this; /** Gets if this is not the implementation. */ isOverload(): boolean; /** Gets if this is the implementation. */ @@ -6164,7 +6164,7 @@ export declare class ParameterDeclaration extends ParameterDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class HeritageClause extends Node { @@ -6185,7 +6185,7 @@ export declare class HeritageClause extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CallSignatureDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6201,7 +6201,7 @@ export declare class CallSignatureDeclaration extends CallSignatureDeclarationBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentTypeElement extends TypeElement { @@ -6220,7 +6220,7 @@ export declare class ConstructSignatureDeclaration extends ConstructSignatureDec /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IndexSignatureDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6254,7 +6254,7 @@ export declare class IndexSignatureDeclaration extends IndexSignatureDeclaration /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const InterfaceDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -6280,7 +6280,7 @@ export declare class InterfaceDeclaration extends InterfaceDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const MethodSignatureBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6296,7 +6296,7 @@ export declare class MethodSignature extends MethodSignatureBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PropertySignatureBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeElement; @@ -6312,7 +6312,7 @@ export declare class PropertySignature extends PropertySignatureBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeElement extends Node { @@ -6372,7 +6372,7 @@ declare const JsxAttributeBase: Constructor & typeof Node; export declare class JsxAttribute extends JsxAttributeBase { /** Gets the JSX attribute's initializer or throws if it doesn't exist. */ - getInitializerOrThrow(): StringLiteral | JsxElement | JsxSelfClosingElement | JsxFragment | JsxExpression; + getInitializerOrThrow(message?: string | (() => string)): StringLiteral | JsxElement | JsxSelfClosingElement | JsxFragment | JsxExpression; /** Gets the JSX attribute's initializer or returns undefined if it doesn't exist. */ getInitializer(): JsxElement | JsxExpression | JsxFragment | JsxSelfClosingElement | StringLiteral | undefined; /** @@ -6395,7 +6395,7 @@ export declare class JsxAttribute extends JsxAttributeBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxClosingElementBase: Constructor & typeof Node; @@ -6404,14 +6404,14 @@ export declare class JsxClosingElement extends JsxClosingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxClosingFragment extends Expression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxElementBase: typeof PrimaryExpression; @@ -6443,7 +6443,7 @@ export declare class JsxElement extends JsxElementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxExpressionBase: Constructor & Constructor & typeof Expression; @@ -6452,7 +6452,7 @@ export declare class JsxExpression extends JsxExpressionBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxFragment extends PrimaryExpression { @@ -6465,7 +6465,7 @@ export declare class JsxFragment extends PrimaryExpression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxOpeningElementBase: Constructor & Constructor & typeof Expression; @@ -6474,14 +6474,14 @@ export declare class JsxOpeningElement extends JsxOpeningElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class JsxOpeningFragment extends Expression { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxSelfClosingElementBase: Constructor & Constructor & typeof PrimaryExpression; @@ -6497,7 +6497,7 @@ export declare class JsxSelfClosingElement extends JsxSelfClosingElementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxSpreadAttributeBase: Constructor & typeof Node; @@ -6515,7 +6515,7 @@ export declare class JsxSpreadAttribute extends JsxSpreadAttributeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const JsxTextBase: Constructor & typeof Node; @@ -6526,7 +6526,7 @@ export declare class JsxText extends JsxTextBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export interface ImplementedKindToNodeMappings { @@ -6816,7 +6816,7 @@ export declare class BigIntLiteral extends BigIntLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TrueLiteralBase: typeof PrimaryExpression; @@ -6834,7 +6834,7 @@ export declare class TrueLiteral extends TrueLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FalseLiteralBase: typeof PrimaryExpression; @@ -6852,7 +6852,7 @@ export declare class FalseLiteral extends FalseLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NullLiteralBase: typeof PrimaryExpression; @@ -6861,7 +6861,7 @@ export declare class NullLiteral extends NullLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NumericLiteralBase: typeof LiteralExpression; @@ -6877,7 +6877,7 @@ export declare class NumericLiteral extends NumericLiteralBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** Quote type for a string literal. */ @@ -6907,7 +6907,7 @@ export declare class RegularExpressionLiteral extends RegularExpressionLiteralBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const StringLiteralBase: typeof LiteralExpression; @@ -6929,7 +6929,7 @@ export declare class StringLiteral extends StringLiteralBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NoSubstitutionTemplateLiteralBase: typeof LiteralExpression; @@ -6948,7 +6948,7 @@ export declare class NoSubstitutionTemplateLiteral extends NoSubstitutionTemplat /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TaggedTemplateExpression extends MemberExpression { @@ -6964,7 +6964,7 @@ export declare class TaggedTemplateExpression extends MemberExpression; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateExpressionBase: typeof PrimaryExpression; @@ -6985,7 +6985,7 @@ export declare class TemplateExpression extends TemplateExpressionBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateHeadBase: Constructor & typeof Node; @@ -6994,7 +6994,7 @@ export declare class TemplateHead extends TemplateHeadBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateMiddleBase: Constructor & typeof Node; @@ -7003,7 +7003,7 @@ export declare class TemplateMiddle extends TemplateMiddleBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateSpanBase: Constructor & typeof Node; @@ -7014,7 +7014,7 @@ export declare class TemplateSpan extends TemplateSpanBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TemplateTailBase: Constructor & typeof Node; @@ -7023,7 +7023,7 @@ export declare class TemplateTail extends TemplateTailBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssertClauseBase: typeof Node; @@ -7038,7 +7038,7 @@ export declare class AssertClause extends AssertClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const AssertEntryBase: Constructor & typeof Node; @@ -7053,7 +7053,7 @@ export declare class AssertEntry extends AssertEntryBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportAssignmentBase: Constructor & typeof Statement; @@ -7080,7 +7080,7 @@ export declare class ExportAssignment extends ExportAssignmentBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportDeclarationBase: typeof Statement; @@ -7093,7 +7093,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase string)): NamespaceExport; /** Sets the namespace export name. */ setNamespaceExport(name: string): this; /** @@ -7111,7 +7111,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase string)): SourceFile; /** Gets the source file referenced in the module specifier. */ getModuleSpecifierSourceFile(): SourceFile | undefined; /** Gets if the module specifier starts with `./` or `../`. */ @@ -7164,7 +7164,7 @@ export declare class ExportDeclaration extends ExportDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExportSpecifierBase: typeof Node; @@ -7202,7 +7202,7 @@ export declare class ExportSpecifier extends ExportSpecifierBase string)): Symbol; /** Gets the local target symbol of the export specifier or undefined if it doesn't exist. */ getLocalTargetSymbol(): Symbol | undefined; /** Gets all the declarations referenced by the export specifier. */ @@ -7219,14 +7219,14 @@ export declare class ExportSpecifier extends ExportSpecifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExternalModuleReferenceBase: Constructor & typeof Node; export declare class ExternalModuleReference extends ExternalModuleReferenceBase { /** Gets the source file referenced or throws if it can't find it. */ - getReferencedSourceFileOrThrow(): SourceFile; + getReferencedSourceFileOrThrow(message?: string | (() => string)): SourceFile; /** Gets if the external module reference is relative. */ isRelative(): boolean; /** Gets the source file referenced or returns undefined if it can't find it. */ @@ -7234,7 +7234,7 @@ export declare class ExternalModuleReference extends ExternalModuleReferenceBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportClauseBase: typeof Node; @@ -7245,15 +7245,15 @@ export declare class ImportClause extends ImportClauseBase { /** Sets if this import declaration is type only. */ setIsTypeOnly(value: boolean): this; /** Gets the default import or throws if it doesn't exit. */ - getDefaultImportOrThrow(): Identifier; + getDefaultImportOrThrow(message?: string | (() => string)): Identifier; /** Gets the default import or returns undefined if it doesn't exist. */ getDefaultImport(): Identifier | undefined; /** Gets the named bindings of the import clause or throws if it doesn't exist. */ - getNamedBindingsOrThrow(): NamespaceImport | NamedImports; + getNamedBindingsOrThrow(message?: string | (() => string)): NamespaceImport | NamedImports; /** Gets the named bindings of the import clause or returns undefined if it doesn't exist. */ getNamedBindings(): NamespaceImport | NamedImports | undefined; /** Gets the namespace import if it exists or throws. */ - getNamespaceImportOrThrow(): Identifier; + getNamespaceImportOrThrow(message?: string | (() => string)): Identifier; /** Gets the namespace import identifier, if it exists. */ getNamespaceImport(): Identifier | undefined; /** Gets the namespace import identifier, if it exists. */ @@ -7261,7 +7261,7 @@ export declare class ImportClause extends ImportClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportDeclarationBase: typeof Statement; @@ -7286,7 +7286,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): SourceFile; /** Gets the source file referenced in the module specifier or returns undefined if it can't find it. */ getModuleSpecifierSourceFile(): SourceFile | undefined; /** Gets if the module specifier starts with `./` or `../`. */ @@ -7303,7 +7303,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): Identifier; /** Gets the default import or returns undefined if it doesn't exist. */ getDefaultImport(): Identifier | undefined; /** @@ -7317,7 +7317,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): Identifier; /** Gets the namespace import identifier, if it exists. */ getNamespaceImport(): Identifier | undefined; /** @@ -7350,7 +7350,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase string)): ImportClause; /** Gets the import clause or returns undefined if it doesn't exist. */ getImportClause(): ImportClause | undefined; /** Sets the elements in an assert clause. */ @@ -7367,7 +7367,7 @@ export declare class ImportDeclaration extends ImportDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportEqualsDeclarationBase: Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -7392,13 +7392,13 @@ export declare class ImportEqualsDeclaration extends ImportEqualsDeclarationBase */ setExternalModuleReference(sourceFile: SourceFile): this; /** Gets the source file referenced in the external module reference or throws if it doesn't exist. */ - getExternalModuleReferenceSourceFileOrThrow(): SourceFile; + getExternalModuleReferenceSourceFileOrThrow(message?: string | (() => string)): SourceFile; /** Gets the source file referenced in the external module reference or returns undefined if it doesn't exist. */ getExternalModuleReferenceSourceFile(): SourceFile | undefined; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ImportSpecifierBase: typeof Node; @@ -7450,7 +7450,7 @@ export declare class ImportSpecifier extends ImportSpecifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ModuleBlockBase: Constructor & typeof Statement; @@ -7459,7 +7459,7 @@ export declare class ModuleBlock extends ModuleBlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare function ModuleChildableNode>(Base: T): Constructor & T; @@ -7468,7 +7468,7 @@ export interface ModuleChildableNode { /** Gets the parent module declaration or undefined if it doesn't exist. */ getParentModule(): ModuleDeclaration | undefined; /** Gets the parent module declaration or throws if it doesn't exist. */ - getParentModuleOrThrow(): ModuleDeclaration; + getParentModuleOrThrow(message?: string | (() => string)): ModuleDeclaration; } declare type ModuleChildableNodeExtensionType = Node; @@ -7515,7 +7515,7 @@ export declare class ModuleDeclaration extends ModuleDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare enum ModuleDeclarationKind { @@ -7532,7 +7532,7 @@ export declare class NamedExports extends NamedExportsBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamedImportsBase: typeof Node; @@ -7543,7 +7543,7 @@ export declare class NamedImports extends NamedImportsBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamespaceExportBase: Constructor & typeof Node; @@ -7558,7 +7558,7 @@ export declare class NamespaceExport extends NamespaceExportBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamespaceImportBase: Constructor & typeof Node; @@ -7573,7 +7573,7 @@ export declare class NamespaceImport extends NamespaceImportBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class FileReference extends TextRange { @@ -7890,7 +7890,7 @@ export declare class SourceFile extends SourceFileBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare function CommonIdentifierBase>(Base: T): Constructor & T; @@ -7919,7 +7919,7 @@ export declare class ComputedPropertyName extends ComputedPropertyNameBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IdentifierBase: Constructor & Constructor & Constructor & typeof PrimaryExpression; @@ -7934,7 +7934,7 @@ export declare class Identifier extends IdentifierBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const PrivateIdentifierBase: Constructor & Constructor & Constructor & typeof Node; @@ -7943,7 +7943,7 @@ export declare class PrivateIdentifier extends PrivateIdentifierBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class QualifiedName extends Node { @@ -7954,7 +7954,7 @@ export declare class QualifiedName extends Node { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const BlockBase: Constructor & Constructor & typeof Statement; @@ -7963,18 +7963,18 @@ export declare class Block extends BlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class BreakStatement extends Statement { /** Gets this break statement's label or undefined if it does not exist. */ getLabel(): Identifier | undefined; /** Gets this break statement's label or throw if it does not exist. */ - getLabelOrThrow(): Identifier; + getLabelOrThrow(message?: string | (() => string)): Identifier; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CaseBlockBase: Constructor & typeof Node; @@ -7995,7 +7995,7 @@ export declare class CaseBlock extends CaseBlockBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CaseClauseBase: Constructor & Constructor & Constructor & Constructor & typeof Node; @@ -8006,7 +8006,7 @@ export declare class CaseClause extends CaseClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const CatchClauseBase: typeof Node; @@ -8017,11 +8017,11 @@ export declare class CatchClause extends CatchClauseBase { /** Gets this catch clause's variable declaration or undefined if none exists. */ getVariableDeclaration(): VariableDeclaration | undefined; /** Gets this catch clause's variable declaration or throws if none exists. */ - getVariableDeclarationOrThrow(): VariableDeclaration; + getVariableDeclarationOrThrow(message?: string | (() => string)): VariableDeclaration; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class CommentStatement extends Statement { @@ -8031,11 +8031,11 @@ export declare class ContinueStatement extends Statement { /** Gets this continue statement's label or undefined if it does not exist. */ getLabel(): Identifier | undefined; /** Gets this continue statement's label or throw if it does not exist. */ - getLabelOrThrow(): Identifier; + getLabelOrThrow(message?: string | (() => string)): Identifier; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DebuggerStatementBase: typeof Statement; @@ -8044,7 +8044,7 @@ export declare class DebuggerStatement extends DebuggerStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DefaultClauseBase: Constructor & Constructor & typeof Node; @@ -8055,7 +8055,7 @@ export declare class DefaultClause extends DefaultClauseBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const DoStatementBase: Constructor & typeof IterationStatement; @@ -8064,7 +8064,7 @@ export declare class DoStatement extends DoStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const EmptyStatementBase: typeof Statement; @@ -8073,7 +8073,7 @@ export declare class EmptyStatement extends EmptyStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExpressionStatementBase: Constructor & Constructor & typeof Statement; @@ -8082,7 +8082,7 @@ export declare class ExpressionStatement extends ExpressionStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForInStatementBase: Constructor & typeof IterationStatement; @@ -8093,7 +8093,7 @@ export declare class ForInStatement extends ForInStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForOfStatementBase: Constructor & Constructor & typeof IterationStatement; @@ -8104,7 +8104,7 @@ export declare class ForOfStatement extends ForOfStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ForStatementBase: typeof IterationStatement; @@ -8113,19 +8113,19 @@ export declare class ForStatement extends ForStatementBase { /** Gets this for statement's initializer or undefined if none exists. */ getInitializer(): VariableDeclarationList | Expression | undefined; /** Gets this for statement's initializer or throws if none exists. */ - getInitializerOrThrow(): Expression | VariableDeclarationList; + getInitializerOrThrow(message?: string | (() => string)): Expression | VariableDeclarationList; /** Gets this for statement's condition or undefined if none exists. */ getCondition(): Expression | undefined; /** Gets this for statement's condition or throws if none exists. */ - getConditionOrThrow(): Expression; + getConditionOrThrow(message?: string | (() => string)): Expression; /** Gets this for statement's incrementor. */ getIncrementor(): Expression | undefined; /** Gets this for statement's incrementor or throws if none exists. */ - getIncrementorOrThrow(): Expression; + getIncrementorOrThrow(message?: string | (() => string)): Expression; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const IfStatementBase: Constructor & typeof Statement; @@ -8140,7 +8140,7 @@ export declare class IfStatement extends IfStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IterationStatement extends Statement { @@ -8158,7 +8158,7 @@ export declare class LabeledStatement extends LabeledStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NotEmittedStatementBase: typeof Statement; @@ -8167,7 +8167,7 @@ export declare class NotEmittedStatement extends NotEmittedStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ReturnStatementBase: Constructor & typeof Statement; @@ -8176,7 +8176,7 @@ export declare class ReturnStatement extends ReturnStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const StatementBase: Constructor & typeof Node; @@ -8607,7 +8607,7 @@ export declare class SwitchStatement extends SwitchStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ThrowStatementBase: Constructor & typeof Statement; @@ -8616,7 +8616,7 @@ export declare class ThrowStatement extends ThrowStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TryStatementBase: typeof Statement; @@ -8627,15 +8627,15 @@ export declare class TryStatement extends TryStatementBase { /** Gets this try statement's catch clause or undefined if none exists. */ getCatchClause(): CatchClause | undefined; /** Gets this try statement's catch clause or throws if none exists. */ - getCatchClauseOrThrow(): CatchClause; + getCatchClauseOrThrow(message?: string | (() => string)): CatchClause; /** Gets this try statement's finally block or undefined if none exists. */ getFinallyBlock(): Block | undefined; /** Gets this try statement's finally block or throws if none exists. */ - getFinallyBlockOrThrow(): Block; + getFinallyBlockOrThrow(message?: string | (() => string)): Block; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const VariableStatementBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -8686,7 +8686,7 @@ export declare class VariableStatement extends VariableStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const WhileStatementBase: Constructor & typeof IterationStatement; @@ -8695,7 +8695,7 @@ export declare class WhileStatement extends WhileStatementBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const WithStatementBase: Constructor & typeof Statement; @@ -8706,7 +8706,7 @@ export declare class WithStatement extends WithStatementBase { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ArrayTypeNode extends TypeNode { @@ -8715,7 +8715,7 @@ export declare class ArrayTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ConditionalTypeNode extends TypeNode { @@ -8746,7 +8746,7 @@ export declare class ConditionalTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ConstructorTypeNodeBase: Constructor & Constructor & typeof FunctionOrConstructorTypeNodeBase; @@ -8755,7 +8755,7 @@ export declare class ConstructorTypeNode extends ConstructorTypeNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const ExpressionWithTypeArgumentsBase: Constructor & typeof NodeWithTypeArguments; @@ -8764,7 +8764,7 @@ export declare class ExpressionWithTypeArguments extends ExpressionWithTypeArgum /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const FunctionOrConstructorTypeNodeBaseBase: Constructor & typeof TypeNode; @@ -8778,7 +8778,7 @@ export declare class FunctionTypeNode extends FunctionTypeNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ImportTypeAssertionContainer extends Node { @@ -8788,7 +8788,7 @@ export declare class ImportTypeAssertionContainer extends Node; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ImportTypeNode extends NodeWithTypeArguments { @@ -8805,17 +8805,17 @@ export declare class ImportTypeNode extends NodeWithTypeArguments string)): EntityName; /** Gets the qualifier of the import type if it exists or returns undefined. */ getQualifier(): EntityName | undefined; /** Gets the import type assertion container if it exists. */ getAssertions(): ImportTypeAssertionContainer | undefined; /** Gets the import type assertion container if it exists or throws. */ - getAssertionsOrThrow(): ImportTypeAssertionContainer; + getAssertionsOrThrow(message?: string | (() => string)): ImportTypeAssertionContainer; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IndexedAccessTypeNode extends TypeNode { @@ -8834,7 +8834,7 @@ export declare class IndexedAccessTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class InferTypeNode extends TypeNode { @@ -8847,7 +8847,7 @@ export declare class InferTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class IntersectionTypeNode extends TypeNode { @@ -8856,7 +8856,7 @@ export declare class IntersectionTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class LiteralTypeNode extends TypeNode { @@ -8865,32 +8865,32 @@ export declare class LiteralTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class MappedTypeNode extends TypeNode { /** Gets the mapped type node's name type node if any. */ getNameTypeNode(): TypeNode | undefined; /** Gets the mapped type node's name type node or throws if it doesn't exist. */ - getNameTypeNodeOrThrow(): TypeNode; + getNameTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** Gets the mapped type's readonly token. */ getReadonlyToken(): Node | Node | Node | undefined; /** Gets the mapped type's readonly token or throws if not exist. */ - getReadonlyTokenOrThrow(): Node | Node | Node; + getReadonlyTokenOrThrow(message?: string | (() => string)): Node | Node | Node; /** Gets the mapped type's question token. */ getQuestionToken(): Node | Node | Node | undefined; /** Gets the mapped type's question token or throws if not exist. */ - getQuestionTokenOrThrow(): Node | Node | Node; + getQuestionTokenOrThrow(message?: string | (() => string)): Node | Node | Node; /** Gets the mapped type node's type parameter. */ getTypeParameter(): TypeParameterDeclaration; /** Gets the mapped type node's type node if it exists or returns undefined when not. */ getTypeNode(): TypeNode | undefined; /** Gets the mapped type node's type node if it exists or throws when undefined. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const NamedTupleMemberBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof TypeNode; @@ -8908,7 +8908,7 @@ export declare class NamedTupleMember extends NamedTupleMemberBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ParenthesizedTypeNode extends TypeNode { @@ -8922,7 +8922,7 @@ export declare class ParenthesizedTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TemplateLiteralTypeNode extends TypeNode { @@ -8941,14 +8941,14 @@ export declare class TemplateLiteralTypeNode extends TypeNode; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class ThisTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TupleTypeNode extends TypeNode { @@ -8957,7 +8957,7 @@ export declare class TupleTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeAliasDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & Constructor & typeof Statement; @@ -8973,7 +8973,7 @@ export declare class TypeAliasDeclaration extends TypeAliasDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const TypeLiteralNodeBase: Constructor & typeof TypeNode; @@ -8982,7 +8982,7 @@ export declare class TypeLiteralNode extends TypeLiteralNodeBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeNode extends Node { @@ -9001,7 +9001,7 @@ export declare class TypeOperatorTypeNode extends TypeNode /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** Variance of the type parameter. */ @@ -9022,7 +9022,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** Gets the constraint of the type parameter. */ getConstraint(): TypeNode | undefined; /** Gets the constraint of the type parameter or throws if it doesn't exist. */ - getConstraintOrThrow(): TypeNode; + getConstraintOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type parameter constraint. * @param text - Text to set as the constraint. @@ -9033,7 +9033,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** Gets the default node of the type parameter. */ getDefault(): TypeNode | undefined; /** Gets the default node of the type parameter or throws if it doesn't exist. */ - getDefaultOrThrow(): TypeNode; + getDefaultOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type parameter default type node. * @param text - Text to set as the default type node. @@ -9057,7 +9057,7 @@ export declare class TypeParameterDeclaration extends TypeParameterDeclarationBa /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } /** @@ -9075,15 +9075,15 @@ export declare class TypePredicateNode extends TypeNode { /** Gets the asserts modifier if it exists. */ getAssertsModifier(): Node | undefined; /** Gets the asserts modifier if it exists or throws otherwise. */ - getAssertsModifierOrThrow(): Node; + getAssertsModifierOrThrow(message?: string | (() => string)): Node; /** Gets the type name if it exists or returns undefined when it asserts a condition. */ getTypeNode(): TypeNode | undefined; /** Gets the type name if it exists or throws when it asserts a condition. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeQueryNode extends NodeWithTypeArguments { @@ -9092,7 +9092,7 @@ export declare class TypeQueryNode extends NodeWithTypeArguments; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class TypeReferenceNode extends NodeWithTypeArguments { @@ -9101,7 +9101,7 @@ export declare class TypeReferenceNode extends NodeWithTypeArguments; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class UnionTypeNode extends TypeNode { @@ -9110,7 +9110,7 @@ export declare class UnionTypeNode extends TypeNode { /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } declare const VariableDeclarationBase: Constructor & Constructor & Constructor & Constructor & Constructor & typeof Node; @@ -9119,7 +9119,7 @@ export declare class VariableDeclaration extends VariableDeclarationBase string)): VariableStatement; /** Gets the corresponding variable statement if it exists. Returns undefined for variable declarations in for statements. */ getVariableStatement(): VariableStatement | undefined; /** @@ -9132,7 +9132,7 @@ export declare class VariableDeclaration extends VariableDeclarationBase; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare enum VariableDeclarationKind { @@ -9180,7 +9180,7 @@ export declare class VariableDeclarationList extends VariableDeclarationListBase /** @inheritdoc **/ getParent(): NodeParentType; /** @inheritdoc **/ - getParentOrThrow(): NonNullable>; + getParentOrThrow(message?: string | (() => string)): NonNullable>; } export declare class Signature { @@ -9210,11 +9210,11 @@ export declare class Symbol { /** Gets the escaped name. */ getEscapedName(): string; /** Gets the aliased symbol or throws if it doesn't exist. */ - getAliasedSymbolOrThrow(): Symbol; + getAliasedSymbolOrThrow(message?: string | (() => string)): Symbol; /** Follows a single alias to get the immediately aliased symbol or returns undefined if it doesn't exist. */ getImmediatelyAliasedSymbol(): Symbol | undefined; /** Follows a single alias to get the immediately aliased symbol or throws if it doesn't exist. */ - getImmediatelyAliasedSymbolOrThrow(): Symbol; + getImmediatelyAliasedSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the aliased symbol or returns undefined if it doesn't exist. */ getAliasedSymbol(): Symbol | undefined; /** @@ -9240,7 +9240,7 @@ export declare class Symbol { */ hasFlags(flags: SymbolFlags): boolean; /** Gets the value declaration of a symbol or throws if it doesn't exist. */ - getValueDeclarationOrThrow(): Node; + getValueDeclarationOrThrow(message?: string | (() => string)): Node; /** Gets the value declaration of the symbol or returns undefined if it doesn't exist. */ getValueDeclaration(): Node | undefined; /** Gets the symbol declarations. */ @@ -9249,7 +9249,7 @@ export declare class Symbol { * Gets the export of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getExportOrThrow(name: string): Symbol; + getExportOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the export of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the export. @@ -9261,7 +9261,7 @@ export declare class Symbol { * Gets the global export of the symbol by the specified name or throws if not exists. * @param name - Name of the global export. */ - getGlobalExportOrThrow(name: string): Symbol; + getGlobalExportOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the global export of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the global export. @@ -9273,7 +9273,7 @@ export declare class Symbol { * Gets the member of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getMemberOrThrow(name: string): Symbol; + getMemberOrThrow(name: string, message?: string | (() => string)): Symbol; /** * Gets the member of the symbol by the specified name or returns undefined if not exists. * @param name - Name of the member. @@ -9969,7 +9969,7 @@ export declare class TypeChecker { * Gets the resolved signature from a node or throws if the signature cannot be resolved. * @param node - Node to get the signature from. */ - getResolvedSignatureOrThrow(node: CallLikeExpression): Signature; + getResolvedSignatureOrThrow(node: CallLikeExpression, message?: string | (() => string)): Signature; /** * Gets the base type of a literal type. * @@ -10006,13 +10006,13 @@ export declare class Type { /** Gets the alias symbol if it exists. */ getAliasSymbol(): Symbol | undefined; /** Gets the alias symbol if it exists, or throws. */ - getAliasSymbolOrThrow(): Symbol; + getAliasSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets the alias type arguments. */ getAliasTypeArguments(): Type[]; /** Gets the apparent type. */ getApparentType(): Type; /** Gets the array element type or throws if it doesn't exist (ex. for `T[]` it would be `T`). */ - getArrayElementTypeOrThrow(): Type; + getArrayElementTypeOrThrow(message?: string | (() => string)): Type; /** Gets the array element type or returns undefined if it doesn't exist (ex. for `T[]` it would be `T`). */ getArrayElementType(): Type | undefined; /** Gets the base types. */ @@ -10028,11 +10028,11 @@ export declare class Type { /** Gets the construct signatures. */ getConstructSignatures(): Signature[]; /** Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow(): Type; + getConstraintOrThrow(message?: string | (() => string)): Type; /** Gets the constraint or returns undefined if it doesn't exist. */ getConstraint(): Type | undefined; /** Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow(): Type; + getDefaultOrThrow(message?: string | (() => string)): Type; /** Gets the default type or returns undefined if it doesn't exist. */ getDefault(): Type | undefined; /** Gets the properties of the type. */ @@ -10095,7 +10095,7 @@ export declare class Type { * - Given generic type `Promise` returns the same `Promise`. * - Given `string` throws an error. */ - getTargetTypeOrThrow(): Type; + getTargetTypeOrThrow(message?: string | (() => string)): Type; /** Gets type arguments. */ getTypeArguments(): Type[]; /** Gets the individual element types of the tuple. */ @@ -10107,7 +10107,7 @@ export declare class Type { /** Gets the value of a literal or returns undefined if this is not a literal type. */ getLiteralValue(): string | number | ts.PseudoBigInt | undefined; /** Gets the value of the literal or throws if this is not a literal type. */ - getLiteralValueOrThrow(): string | number | ts.PseudoBigInt; + getLiteralValueOrThrow(message?: string | (() => string)): string | number | ts.PseudoBigInt; /** * Gets the fresh type of the literal or returns undefined if this is not a literal type. * @@ -10119,7 +10119,7 @@ export declare class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralFreshTypeOrThrow(): Type; + getLiteralFreshTypeOrThrow(message?: string | (() => string)): Type; /** * Gets the regular type of the literal or returns undefined if this is not a literal type. * @@ -10131,11 +10131,11 @@ export declare class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralRegularTypeOrThrow(): Type; + getLiteralRegularTypeOrThrow(message?: string | (() => string)): Type; /** Gets the symbol of the type. */ getSymbol(): Symbol | undefined; /** Gets the symbol of the type or throws. */ - getSymbolOrThrow(): Symbol; + getSymbolOrThrow(message?: string | (() => string)): Symbol; /** Gets if this is an anonymous type. */ isAnonymous(): boolean; /** Gets if this is an any type. */ @@ -10201,11 +10201,11 @@ export declare class Type { export declare class TypeParameter extends Type { /** Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow(): Type; + getConstraintOrThrow(message?: string | (() => string)): Type; /** Gets the constraint type. */ getConstraint(): Type | undefined; /** Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow(): Type; + getDefaultOrThrow(message?: string | (() => string)): Type; /** Gets the default type or undefined if it doesn't exist. */ getDefault(): Type | undefined; } diff --git a/packages/ts-morph/scripts/generation/createDeclarationFile.ts b/packages/ts-morph/scripts/generation/createDeclarationFile.ts index 4197a1c85..b845f26c1 100644 --- a/packages/ts-morph/scripts/generation/createDeclarationFile.ts +++ b/packages/ts-morph/scripts/generation/createDeclarationFile.ts @@ -162,7 +162,7 @@ export async function createDeclarationFile() { writer.writeLine("/** @inheritdoc **/"); writer.writeLine(`getParent(): NodeParentType<${typeArgName}>;`); writer.writeLine("/** @inheritdoc **/"); - writer.writeLine(`getParentOrThrow(): NonNullable>;`); + writer.writeLine(`getParentOrThrow(message?: string | (() => string)): NonNullable>;`); }); } diff --git a/packages/ts-morph/src/Project.ts b/packages/ts-morph/src/Project.ts index 8a105c5ff..3497048f7 100644 --- a/packages/ts-morph/src/Project.ts +++ b/packages/ts-morph/src/Project.ts @@ -242,10 +242,10 @@ export class Project { * Gets a directory by the specified path or throws if it doesn't exist. * @param dirPath - Path to create the directory at. */ - getDirectoryOrThrow(dirPath: string): Directory { + getDirectoryOrThrow(dirPath: string, message?: string | (() => string)): Directory { return errors.throwIfNullOrUndefined( this.getDirectory(dirPath), - () => `Could not find a directory at the specified path: ${this._context.fileSystemWrapper.getStandardizedAbsolutePath(dirPath)}`, + message ?? (() => `Could not find a directory at the specified path: ${this._context.fileSystemWrapper.getStandardizedAbsolutePath(dirPath)}`), ); } @@ -522,10 +522,10 @@ export class Project { * Gets the specified ambient module symbol or throws if not found. * @param moduleName - The ambient module name with or without quotes. */ - getAmbientModuleOrThrow(moduleName: string) { + getAmbientModuleOrThrow(moduleName: string, message?: string | (() => string)) { return errors.throwIfNullOrUndefined( this.getAmbientModule(moduleName), - () => `Could not find ambient module with name: ${normalizeAmbientModuleName(moduleName)}`, + message ?? (() => `Could not find ambient module with name: ${normalizeAmbientModuleName(moduleName)}`), ); } diff --git a/packages/ts-morph/src/compiler/ast/base/AmbientableNode.ts b/packages/ts-morph/src/compiler/ast/base/AmbientableNode.ts index 5c744bb9b..9fca76ca3 100644 --- a/packages/ts-morph/src/compiler/ast/base/AmbientableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/AmbientableNode.ts @@ -21,7 +21,7 @@ export interface AmbientableNode { /** * Gets the declare keyword or throws if it doesn't exist. */ - getDeclareKeywordOrThrow(): Node; + getDeclareKeywordOrThrow(message?: string | (() => string)): Node; /** * Gets if the node is ambient. */ @@ -39,8 +39,8 @@ export function AmbientableNode string)) { + return errors.throwIfNullOrUndefined(this.getDeclareKeyword(), message ?? "Expected to find a declare keyword.", this); } getDeclareKeyword() { diff --git a/packages/ts-morph/src/compiler/ast/base/AsyncableNode.ts b/packages/ts-morph/src/compiler/ast/base/AsyncableNode.ts index 13bd7c448..4db71ed7f 100644 --- a/packages/ts-morph/src/compiler/ast/base/AsyncableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/AsyncableNode.ts @@ -20,7 +20,7 @@ export interface AsyncableNode { /** * Gets the async keyword or throws if none exists. */ - getAsyncKeywordOrThrow(): Node; + getAsyncKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is async. * @param value - If it should be async or not. @@ -38,8 +38,8 @@ export function AsyncableNode> return this.getFirstModifierByKind(SyntaxKind.AsyncKeyword) as Node | undefined; } - getAsyncKeywordOrThrow(): Node { - return errors.throwIfNullOrUndefined(this.getAsyncKeyword(), "Expected to find an async keyword."); + getAsyncKeywordOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getAsyncKeyword(), message ?? "Expected to find an async keyword.", this); } setIsAsync(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/AwaitableNode.ts b/packages/ts-morph/src/compiler/ast/base/AwaitableNode.ts index 6bce2b1e3..9ddf52a0b 100644 --- a/packages/ts-morph/src/compiler/ast/base/AwaitableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/AwaitableNode.ts @@ -19,7 +19,7 @@ export interface AwaitableNode { /** * Gets the await token or throws if none exists. */ - getAwaitKeywordOrThrow(): Node; + getAwaitKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is awaited. * @param value - If it should be awaited or not. @@ -38,7 +38,7 @@ export function AwaitableNode> return this._getNodeFromCompilerNodeIfExists(awaitModifier); } - getAwaitKeywordOrThrow(): Node { + getAwaitKeywordOrThrow(message?: string | (() => string)): Node { return errors.throwIfNullOrUndefined(this.getAwaitKeyword(), "Expected to find an await token."); } diff --git a/packages/ts-morph/src/compiler/ast/base/BodyableNode.ts b/packages/ts-morph/src/compiler/ast/base/BodyableNode.ts index 983c5780a..733f9593c 100644 --- a/packages/ts-morph/src/compiler/ast/base/BodyableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/BodyableNode.ts @@ -10,7 +10,7 @@ export interface BodyableNode { /** * Gets the body or throws an error if it doesn't exist. */ - getBodyOrThrow(): Node; + getBodyOrThrow(message?: string | (() => string)): Node; /** * Gets the body if it exists. */ @@ -40,8 +40,8 @@ export interface BodyableNode { export function BodyableNode>(Base: T): Constructor & T { return class extends Base implements BodyableNode { - getBodyOrThrow() { - return errors.throwIfNullOrUndefined(this.getBody(), "Expected to find the node's body."); + getBodyOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getBody(), message ?? "Expected to find the node's body.", this); } getBody() { diff --git a/packages/ts-morph/src/compiler/ast/base/DecoratableNode.ts b/packages/ts-morph/src/compiler/ast/base/DecoratableNode.ts index ae6084420..6fd8874d3 100644 --- a/packages/ts-morph/src/compiler/ast/base/DecoratableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/DecoratableNode.ts @@ -66,10 +66,11 @@ export function DecoratableNode boolean)): Decorator { + getDecoratorOrThrow(nameOrFindFunction: string | ((declaration: Decorator) => boolean), message?: string | (() => string)): Decorator { return errors.throwIfNullOrUndefined( this.getDecorator(nameOrFindFunction), - () => getNotFoundErrorMessageForNameOrFindFunction("decorator", nameOrFindFunction), + message ?? (() => getNotFoundErrorMessageForNameOrFindFunction("decorator", nameOrFindFunction)), + this, ); } diff --git a/packages/ts-morph/src/compiler/ast/base/DotDotDotTokenableNode.ts b/packages/ts-morph/src/compiler/ast/base/DotDotDotTokenableNode.ts index ad0ee8d48..697b69fff 100644 --- a/packages/ts-morph/src/compiler/ast/base/DotDotDotTokenableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/DotDotDotTokenableNode.ts @@ -12,13 +12,13 @@ export interface DotDotDotTokenableNode { /** * Gets the dot dot dot token (...) if it exists or throws if not. */ - getDotDotDotTokenOrThrow(): Node; + getDotDotDotTokenOrThrow(message?: string | (() => string)): Node; } export function DotDotDotTokenableNode>(Base: T): Constructor & T { return class extends Base implements DotDotDotTokenableNode { - getDotDotDotTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getDotDotDotToken(), "Expected to find a dot dot dot token (...)."); + getDotDotDotTokenOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getDotDotDotToken(), message ?? "Expected to find a dot dot dot token (...).", this); } getDotDotDotToken() { diff --git a/packages/ts-morph/src/compiler/ast/base/ExclamationTokenableNode.ts b/packages/ts-morph/src/compiler/ast/base/ExclamationTokenableNode.ts index 50e0de24e..6a6dfc688 100644 --- a/packages/ts-morph/src/compiler/ast/base/ExclamationTokenableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/ExclamationTokenableNode.ts @@ -20,7 +20,7 @@ export interface ExclamationTokenableNode { /** * Gets the exclamation token node or throws. */ - getExclamationTokenNodeOrThrow(): Node; + getExclamationTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a exclamation token. * @param value - If it should have a exclamation token or not. @@ -38,8 +38,8 @@ export function ExclamationTokenableNode { - return errors.throwIfNullOrUndefined(this.getExclamationTokenNode(), "Expected to find an exclamation token."); + getExclamationTokenNodeOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getExclamationTokenNode(), message ?? "Expected to find an exclamation token.", this); } setHasExclamationToken(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/GeneratorableNode.ts b/packages/ts-morph/src/compiler/ast/base/GeneratorableNode.ts index 1a7fb306d..8fdd201fd 100644 --- a/packages/ts-morph/src/compiler/ast/base/GeneratorableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/GeneratorableNode.ts @@ -21,7 +21,7 @@ export interface GeneratorableNode { /** * Gets the asterisk token or throws if none exists. */ - getAsteriskTokenOrThrow(): Node; + getAsteriskTokenOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is a generator. * @param value - If it should be a generator or not. @@ -39,8 +39,8 @@ export function GeneratorableNode { - return errors.throwIfNullOrUndefined(this.getAsteriskToken(), "Expected to find an asterisk token."); + getAsteriskTokenOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getAsteriskToken(), message ?? "Expected to find an asterisk token.", this); } setIsGenerator(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/HeritageClauseableNode.ts b/packages/ts-morph/src/compiler/ast/base/HeritageClauseableNode.ts index 1f9c110ee..ca90fc1dd 100644 --- a/packages/ts-morph/src/compiler/ast/base/HeritageClauseableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/HeritageClauseableNode.ts @@ -29,8 +29,12 @@ export function HeritageClauseableNode this._getNodeFromCompilerNode(c)) ?? []; } - getHeritageClauseByKindOrThrow(kind: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword) { - return errors.throwIfNullOrUndefined(this.getHeritageClauseByKind(kind), `Expected to have heritage clause of kind ${getSyntaxKindName(kind)}.`); + getHeritageClauseByKindOrThrow(kind: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getHeritageClauseByKind(kind), + message ?? (() => `Expected to have heritage clause of kind ${getSyntaxKindName(kind)}.`), + this, + ); } getHeritageClauseByKind(kind: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword) { diff --git a/packages/ts-morph/src/compiler/ast/base/ModifierableNode.ts b/packages/ts-morph/src/compiler/ast/base/ModifierableNode.ts index 024432e8b..8997e64e3 100644 --- a/packages/ts-morph/src/compiler/ast/base/ModifierableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/ModifierableNode.ts @@ -75,8 +75,12 @@ export function ModifierableNode this._getNodeFromCompilerNode(m)) as Node[]; } - getFirstModifierByKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getFirstModifierByKind(kind), `Expected a modifier of syntax kind: ${getSyntaxKindName(kind)}`); + getFirstModifierByKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getFirstModifierByKind(kind), + message ?? (() => `Expected a modifier of syntax kind: ${getSyntaxKindName(kind)}`), + this, + ); } getFirstModifierByKind(kind: TKind): KindToNodeMappings[TKind] | undefined { diff --git a/packages/ts-morph/src/compiler/ast/base/ModuledNode.ts b/packages/ts-morph/src/compiler/ast/base/ModuledNode.ts index 2020ad68d..70fc3f88b 100644 --- a/packages/ts-morph/src/compiler/ast/base/ModuledNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/ModuledNode.ts @@ -85,10 +85,10 @@ export interface ModuledNode { */ insertExportDeclarations(index: number, structures: ReadonlyArray>): ExportDeclaration[]; /* - * Gets the first export declaration that matches a condition, or undefined if it doesn't exist. - * @param condition - Condition to get the export declaration by. - */ - getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration | undefined; + * Gets the first export declaration that matches a condition, or undefined if it doesn't exist. + * @param condition - Condition to get the export declaration by. + */ + getExportDeclaration(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration | undefined; /** * Gets the first export declaration that matches a module specifier, or undefined if it doesn't exist. * @param module - Module specifier to get the export declaration by. @@ -100,14 +100,17 @@ export interface ModuledNode { * Gets the first export declaration that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export declaration by. */ - getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean): ExportDeclaration; + getExportDeclarationOrThrow(condition: (exportDeclaration: ExportDeclaration) => boolean, message?: string | (() => string)): ExportDeclaration; /** * Gets the first export declaration that matches a module specifier, or throws if it doesn't exist. * @param module - Module specifier to get the export declaration by. */ - getExportDeclarationOrThrow(moduleSpecifier: string): ExportDeclaration; + getExportDeclarationOrThrow(moduleSpecifier: string, message?: string | (() => string)): ExportDeclaration; /** @internal */ - getExportDeclarationOrThrow(conditionOrModuleSpecifier: string | ((exportDeclaration: ExportDeclaration) => boolean)): ExportDeclaration; + getExportDeclarationOrThrow( + conditionOrModuleSpecifier: string | ((exportDeclaration: ExportDeclaration) => boolean), + message?: string | (() => string), + ): ExportDeclaration; /** * Get the export declarations. */ @@ -143,7 +146,7 @@ export interface ModuledNode { * Gets the first export assignment that matches a condition, or throws if it doesn't exist. * @param condition - Condition to get the export assignment by. */ - getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean): ExportAssignment; + getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean, message?: string | (() => string)): ExportAssignment; /** * Get the file's export assignments. */ @@ -155,7 +158,7 @@ export interface ModuledNode { /** * Gets the default export symbol or throws if it doesn't exist. */ - getDefaultExportSymbolOrThrow(): Symbol; + getDefaultExportSymbolOrThrow(message?: string | (() => string)): Symbol; /** * Gets the export symbols. */ @@ -238,10 +241,11 @@ export function ModuledNode>(Bas } } - getImportDeclarationOrThrow(conditionOrModuleSpecifier: string | ((importDeclaration: ImportDeclaration) => boolean)) { + getImportDeclarationOrThrow(conditionOrModuleSpecifier: string | ((importDeclaration: ImportDeclaration) => boolean), message?: string | (() => string)) { return errors.throwIfNullOrUndefined( this.getImportDeclaration(conditionOrModuleSpecifier), - "Expected to find an import with the provided condition.", + message ?? "Expected to find an import with the provided condition.", + this, ); } @@ -289,10 +293,11 @@ export function ModuledNode>(Bas } } - getExportDeclarationOrThrow(conditionOrModuleSpecifier: string | ((exportDeclaration: ExportDeclaration) => boolean)) { + getExportDeclarationOrThrow(conditionOrModuleSpecifier: string | ((exportDeclaration: ExportDeclaration) => boolean), message?: string | (() => string)) { return errors.throwIfNullOrUndefined( this.getExportDeclaration(conditionOrModuleSpecifier), - "Expected to find an export declaration with the provided condition.", + message ?? "Expected to find an export declaration with the provided condition.", + this, ); } @@ -333,8 +338,12 @@ export function ModuledNode>(Bas return this.getExportAssignments().find(condition); } - getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean): ExportAssignment { - return errors.throwIfNullOrUndefined(this.getExportAssignment(condition), "Expected to find an export assignment with the provided condition."); + getExportAssignmentOrThrow(condition: (exportAssignment: ExportAssignment) => boolean, message?: string | (() => string)): ExportAssignment { + return errors.throwIfNullOrUndefined( + this.getExportAssignment(condition), + message ?? "Expected to find an export assignment with the provided condition.", + this, + ); } getExportAssignments(): ExportAssignment[] { @@ -351,8 +360,8 @@ export function ModuledNode>(Bas return sourceFileSymbol.getExport("default"); } - getDefaultExportSymbolOrThrow(): Symbol { - return errors.throwIfNullOrUndefined(this.getDefaultExportSymbol(), "Expected to find a default export symbol"); + getDefaultExportSymbolOrThrow(message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getDefaultExportSymbol(), message ?? "Expected to find a default export symbol"); } getExportSymbols(): Symbol[] { diff --git a/packages/ts-morph/src/compiler/ast/base/OverrideableNode.ts b/packages/ts-morph/src/compiler/ast/base/OverrideableNode.ts index b27135da8..987813961 100644 --- a/packages/ts-morph/src/compiler/ast/base/OverrideableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/OverrideableNode.ts @@ -20,7 +20,7 @@ export interface OverrideableNode { /** * Gets the override keyword or throws if none exists. */ - getOverrideKeywordOrThrow(): Node; + getOverrideKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node has an override keyword. * @param value - If it should have an override keyword or not. @@ -38,8 +38,8 @@ export function OverrideableNode | undefined; } - getOverrideKeywordOrThrow(): Node { - return errors.throwIfNullOrUndefined(this.getOverrideKeyword(), "Expected to find an override keyword."); + getOverrideKeywordOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getOverrideKeyword(), message ?? "Expected to find an override keyword.", this); } setHasOverrideKeyword(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/QuestionDotTokenableNode.ts b/packages/ts-morph/src/compiler/ast/base/QuestionDotTokenableNode.ts index befe97461..5606731f4 100644 --- a/packages/ts-morph/src/compiler/ast/base/QuestionDotTokenableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/QuestionDotTokenableNode.ts @@ -20,7 +20,7 @@ export interface QuestionDotTokenableNode { /** * Gets the question dot token node or throws. */ - getQuestionDotTokenNodeOrThrow(): Node; + getQuestionDotTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question dot token. * @param value - If it should have a question dot token or not. @@ -38,8 +38,8 @@ export function QuestionDotTokenableNode { - return errors.throwIfNullOrUndefined(this.getQuestionDotTokenNode(), "Expected to find a question dot token."); + getQuestionDotTokenNodeOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getQuestionDotTokenNode(), message ?? "Expected to find a question dot token.", this); } setHasQuestionDotToken(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/QuestionTokenableNode.ts b/packages/ts-morph/src/compiler/ast/base/QuestionTokenableNode.ts index 3c210667b..fecad3f4c 100644 --- a/packages/ts-morph/src/compiler/ast/base/QuestionTokenableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/QuestionTokenableNode.ts @@ -20,7 +20,7 @@ export interface QuestionTokenableNode { /** * Gets the question token node or throws. */ - getQuestionTokenNodeOrThrow(): Node; + getQuestionTokenNodeOrThrow(message?: string | (() => string)): Node; /** * Sets if this node has a question token. * @param value - If it should have a question token or not. @@ -38,8 +38,8 @@ export function QuestionTokenableNode { - return errors.throwIfNullOrUndefined(this.getQuestionTokenNode(), "Expected to find a question token."); + getQuestionTokenNodeOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined(this.getQuestionTokenNode(), message ?? "Expected to find a question token.", this); } setHasQuestionToken(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/ReadonlyableNode.ts b/packages/ts-morph/src/compiler/ast/base/ReadonlyableNode.ts index dd4bd2d35..43766729b 100644 --- a/packages/ts-morph/src/compiler/ast/base/ReadonlyableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/ReadonlyableNode.ts @@ -20,7 +20,7 @@ export interface ReadonlyableNode { /** * Gets the readonly keyword, or throws if none exists. */ - getReadonlyKeywordOrThrow(): Node; + getReadonlyKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if this node is readonly. * @param value - If readonly or not. @@ -38,8 +38,8 @@ export function ReadonlyableNode string)) { + return errors.throwIfNullOrUndefined(this.getReadonlyKeyword(), message ?? "Expected to find a readonly keyword.", this); } setIsReadonly(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/ReturnTypedNode.ts b/packages/ts-morph/src/compiler/ast/base/ReturnTypedNode.ts index 0b0d668ee..ed0501ff3 100644 --- a/packages/ts-morph/src/compiler/ast/base/ReturnTypedNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/ReturnTypedNode.ts @@ -24,7 +24,7 @@ export interface ReturnTypedNode { /** * Gets the return type node or throws if none exists. */ - getReturnTypeNodeOrThrow(): TypeNode; + getReturnTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the return type of the node. * @param textOrWriterFunction - Text or writer function to set the return type with. @@ -50,8 +50,8 @@ export function ReturnTypedNode string)) { + return errors.throwIfNullOrUndefined(this.getReturnTypeNode(), message ?? "Expected to find a return type node.", this); } setReturnType(textOrWriterFunction: string | WriterFunction) { diff --git a/packages/ts-morph/src/compiler/ast/base/StaticableNode.ts b/packages/ts-morph/src/compiler/ast/base/StaticableNode.ts index e34aba38d..94e0354fb 100644 --- a/packages/ts-morph/src/compiler/ast/base/StaticableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/StaticableNode.ts @@ -20,7 +20,7 @@ export interface StaticableNode { /** * Gets the static keyword, or throws if none exists. */ - getStaticKeywordOrThrow(): Node; + getStaticKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is static. * @param value - If it should be static or not. @@ -38,8 +38,8 @@ export function StaticableNode string)) { + return errors.throwIfNullOrUndefined(this.getStaticKeyword(), message ?? "Expected to find a static keyword.", this); } setIsStatic(value: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/base/TypeElementMemberedNode.ts b/packages/ts-morph/src/compiler/ast/base/TypeElementMemberedNode.ts index d867e8362..24f0a6a5a 100644 --- a/packages/ts-morph/src/compiler/ast/base/TypeElementMemberedNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/TypeElementMemberedNode.ts @@ -349,10 +349,11 @@ export function TypeElementMemberedNode boolean) { + getConstructSignatureOrThrow(findFunction: (member: ConstructSignatureDeclaration) => boolean, message?: string | (() => string)) { return errors.throwIfNullOrUndefined( this.getConstructSignature(findFunction), - "Expected to find a construct signature with the provided condition.", + message ?? "Expected to find a construct signature with the provided condition.", + this, ); } @@ -387,8 +388,12 @@ export function TypeElementMemberedNode boolean) { - return errors.throwIfNullOrUndefined(this.getCallSignature(findFunction), "Expected to find a call signature with the provided condition."); + getCallSignatureOrThrow(findFunction: (member: CallSignatureDeclaration) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getCallSignature(findFunction), + message ?? "Expected to find a call signature with the provided condition.", + this, + ); } getCallSignatures() { @@ -422,8 +427,12 @@ export function TypeElementMemberedNode boolean) { - return errors.throwIfNullOrUndefined(this.getIndexSignature(findFunction), "Expected to find a index signature with the provided condition."); + getIndexSignatureOrThrow(findFunction: (member: IndexSignatureDeclaration) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getIndexSignature(findFunction), + message ?? "Expected to find a index signature with the provided condition.", + this, + ); } getIndexSignatures() { diff --git a/packages/ts-morph/src/compiler/ast/base/TypedNode.ts b/packages/ts-morph/src/compiler/ast/base/TypedNode.ts index 5c788a50c..9426600c0 100644 --- a/packages/ts-morph/src/compiler/ast/base/TypedNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/TypedNode.ts @@ -18,7 +18,7 @@ export interface TypedNode { /** * Gets the type node or throws if none exists. */ - getTypeNodeOrThrow(): TypeNode; + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode; /** * Sets the type. * @param textOrWriterFunction - Text or writer function to set the type with. @@ -36,8 +36,8 @@ export function TypedNode>(Base: T return this._getNodeFromCompilerNodeIfExists(this.compilerNode.type); } - getTypeNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Expected to find a type node."); + getTypeNodeOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message ?? "Expected to find a type node.", this); } setType(textOrWriterFunction: string | WriterFunction) { diff --git a/packages/ts-morph/src/compiler/ast/base/export/ExportGetableNode.ts b/packages/ts-morph/src/compiler/ast/base/export/ExportGetableNode.ts index 6f87d17d6..35b0f6757 100644 --- a/packages/ts-morph/src/compiler/ast/base/export/ExportGetableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/export/ExportGetableNode.ts @@ -17,7 +17,7 @@ export interface ExportGetableNode { /** * Gets the export keyword or throws if none exists. */ - getExportKeywordOrThrow(): Node; + getExportKeywordOrThrow(message?: string | (() => string)): Node; /** * If the node has the default keyword. */ @@ -29,7 +29,7 @@ export interface ExportGetableNode { /** * Gets the default keyword or throws if none exists. */ - getDefaultKeywordOrThrow(): Node; + getDefaultKeywordOrThrow(message?: string | (() => string)): Node; /** * Gets if the node is exported from a namespace, is a default export, or is a named export. */ @@ -60,8 +60,8 @@ export function ExportGetableNode string)) { + return errors.throwIfNullOrUndefined(this.getExportKeyword(), message ?? "Expected to find an export keyword.", this); } hasDefaultKeyword() { @@ -78,8 +78,8 @@ export function ExportGetableNode string)) { + return errors.throwIfNullOrUndefined(this.getDefaultKeyword(), message ?? "Expected to find a default keyword.", this); } isExported() { diff --git a/packages/ts-morph/src/compiler/ast/base/initializer/InitializerExpressionGetableNode.ts b/packages/ts-morph/src/compiler/ast/base/initializer/InitializerExpressionGetableNode.ts index 12f401cf1..a37c7af81 100644 --- a/packages/ts-morph/src/compiler/ast/base/initializer/InitializerExpressionGetableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/initializer/InitializerExpressionGetableNode.ts @@ -26,7 +26,7 @@ export interface InitializerExpressionGetableNode { /** * Gets the initializer or throw. */ - getInitializerOrThrow(): Expression; + getInitializerOrThrow(message?: string | (() => string)): Expression; } export function InitializerExpressionGetableNode>( @@ -37,8 +37,12 @@ export function InitializerExpressionGetableNode(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getInitializerIfKind(kind), `Expected to find an initializer of kind '${getSyntaxKindName(kind)}'.`); + getInitializerIfKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getInitializerIfKind(kind), + message ?? `Expected to find an initializer of kind '${getSyntaxKindName(kind)}'.`, + this, + ); } getInitializerIfKind(kind: TKind): KindToExpressionMappings[TKind] | undefined { @@ -48,8 +52,8 @@ export function InitializerExpressionGetableNode string)) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message ?? "Expected to find an initializer.", this); } getInitializer() { diff --git a/packages/ts-morph/src/compiler/ast/base/name/NameableNode.ts b/packages/ts-morph/src/compiler/ast/base/name/NameableNode.ts index cac419a83..6d4a09aa1 100644 --- a/packages/ts-morph/src/compiler/ast/base/name/NameableNode.ts +++ b/packages/ts-morph/src/compiler/ast/base/name/NameableNode.ts @@ -22,7 +22,7 @@ export interface NameableNodeSpecific { /** * Gets the name node if it exists, or throws. */ - getNameNodeOrThrow(): Identifier; + getNameNodeOrThrow(message?: string | (() => string)): Identifier; /** * Gets the name if it exists. */ @@ -30,7 +30,7 @@ export interface NameableNodeSpecific { /** * Gets the name if it exists, or throws. */ - getNameOrThrow(): string; + getNameOrThrow(message?: string | (() => string)): string; /** * Removes the name from the node. */ @@ -47,16 +47,16 @@ function NameableNodeInternal>( return this._getNodeFromCompilerNodeIfExists(this.compilerNode.name); } - getNameNodeOrThrow() { - return errors.throwIfNullOrUndefined(this.getNameNode(), "Expected to have a name node."); + getNameNodeOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getNameNode(), message ?? "Expected to have a name node.", this); } getName() { return this.getNameNode()?.getText() ?? undefined; // huh? why was this necessary? bug in optional chaining? } - getNameOrThrow() { - return errors.throwIfNullOrUndefined(this.getName(), "Expected to have a name."); + getNameOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getName(), message ?? "Expected to have a name.", this); } rename(newName: string) { diff --git a/packages/ts-morph/src/compiler/ast/binding/BindingElement.ts b/packages/ts-morph/src/compiler/ast/binding/BindingElement.ts index 7650306be..0ddadbf57 100644 --- a/packages/ts-morph/src/compiler/ast/binding/BindingElement.ts +++ b/packages/ts-morph/src/compiler/ast/binding/BindingElement.ts @@ -11,8 +11,8 @@ export class BindingElement extends BindingElementBase { * * For example in `const { a: b } = { a: 5 }`, `a` would be the property name. */ - getPropertyNameNodeOrThrow(): PropertyName { - return errors.throwIfNullOrUndefined(this.getPropertyNameNode(), "Expected to find a property name node."); + getPropertyNameNodeOrThrow(message?: string | (() => string)): PropertyName { + return errors.throwIfNullOrUndefined(this.getPropertyNameNode(), message ?? "Expected to find a property name node.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/class/GetAccessorDeclaration.ts b/packages/ts-morph/src/compiler/ast/class/GetAccessorDeclaration.ts index 9daf8a9ed..e1b660adf 100644 --- a/packages/ts-morph/src/compiler/ast/class/GetAccessorDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/class/GetAccessorDeclaration.ts @@ -41,8 +41,12 @@ export class GetAccessorDeclaration extends GetAccessorDeclarationBase `Expected to find a corresponding set accessor for ${this.getName()}.`); + getSetAccessorOrThrow(message?: string | (() => string)): SetAccessorDeclaration { + return errors.throwIfNullOrUndefined( + this.getSetAccessor(), + message ?? (() => `Expected to find a corresponding set accessor for ${this.getName()}.`), + this, + ); } /** diff --git a/packages/ts-morph/src/compiler/ast/class/SetAccessorDeclaration.ts b/packages/ts-morph/src/compiler/ast/class/SetAccessorDeclaration.ts index 712ef88b9..fa3cd7910 100644 --- a/packages/ts-morph/src/compiler/ast/class/SetAccessorDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/class/SetAccessorDeclaration.ts @@ -41,8 +41,12 @@ export class SetAccessorDeclaration extends SetAccessorDeclarationBase `Expected to find a corresponding get accessor for ${this.getName()}.`); + getGetAccessorOrThrow(message?: string | (() => string)): GetAccessorDeclaration { + return errors.throwIfNullOrUndefined( + this.getGetAccessor(), + message ?? (() => `Expected to find a corresponding get accessor for ${this.getName()}.`), + this, + ); } /** diff --git a/packages/ts-morph/src/compiler/ast/class/base/AbstractableNode.ts b/packages/ts-morph/src/compiler/ast/class/base/AbstractableNode.ts index 856721914..1845e214b 100644 --- a/packages/ts-morph/src/compiler/ast/class/base/AbstractableNode.ts +++ b/packages/ts-morph/src/compiler/ast/class/base/AbstractableNode.ts @@ -20,7 +20,7 @@ export interface AbstractableNode { /** * Gets the abstract keyword or throws if it doesn't exist. */ - getAbstractKeywordOrThrow(): Node; + getAbstractKeywordOrThrow(message?: string | (() => string)): Node; /** * Sets if the node is abstract. * @param isAbstract - If it should be abstract or not. @@ -38,8 +38,8 @@ export function AbstractableNode string)) { + return errors.throwIfNullOrUndefined(this.getAbstractKeyword(), message ?? "Expected to find an abstract keyword.", this); } setIsAbstract(isAbstract: boolean) { diff --git a/packages/ts-morph/src/compiler/ast/class/base/ClassLikeDeclarationBase.ts b/packages/ts-morph/src/compiler/ast/class/base/ClassLikeDeclarationBase.ts index 1ae61fa1d..d6a9b62d2 100644 --- a/packages/ts-morph/src/compiler/ast/class/base/ClassLikeDeclarationBase.ts +++ b/packages/ts-morph/src/compiler/ast/class/base/ClassLikeDeclarationBase.ts @@ -98,7 +98,7 @@ export interface ClassLikeDeclarationBaseSpecific { /** * Gets the extends expression or throws if it doesn't exist. */ - getExtendsOrThrow(): ExpressionWithTypeArguments; + getExtendsOrThrow(message?: string | (() => string)): ExpressionWithTypeArguments; /** * Gets the extends expression or returns undefined if it doesn't exist. */ @@ -574,7 +574,7 @@ export interface ClassLikeDeclarationBaseSpecific { * * Note: Use getBaseTypes if you need to get the mixins. */ - getBaseClassOrThrow(): ClassDeclaration; + getBaseClassOrThrow(message?: string | (() => string)): ClassDeclaration; /** * Gets the base class. * @@ -641,8 +641,8 @@ export function ClassLikeDeclarationBaseSpecific string)) { + return errors.throwIfNullOrUndefined(this.getExtends(), message ?? `Expected to find the extends expression for the class ${this.getName()}.`, this); } getExtends(): ExpressionWithTypeArguments | undefined { @@ -1186,8 +1186,8 @@ export function ClassLikeDeclarationBaseSpecific string)) { + return errors.throwIfNullOrUndefined(this.getBaseClass(), message ?? `Expected to find the base class of ${this.getName()}.`, this); } getBaseClass() { diff --git a/packages/ts-morph/src/compiler/ast/common/Node.ts b/packages/ts-morph/src/compiler/ast/common/Node.ts index b754526b5..dd5e35075 100644 --- a/packages/ts-morph/src/compiler/ast/common/Node.ts +++ b/packages/ts-morph/src/compiler/ast/common/Node.ts @@ -238,8 +238,8 @@ export class Node { /** * Gets the symbol or throws an error if it doesn't exist. */ - getSymbolOrThrow(): Symbol { - return errors.throwIfNullOrUndefined(this.getSymbol(), "Could not find the node's symbol."); + getSymbolOrThrow(message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getSymbol(), message ?? "Could not find the node's symbol.", this); } /** @@ -279,8 +279,8 @@ export class Node { * WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break. * @param name - Name of the local symbol. */ - getLocalOrThrow(name: string): Symbol { - return errors.throwIfNullOrUndefined(this.getLocal(name), `Expected to find local symbol with name: ${name}`); + getLocalOrThrow(name: string, message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getLocal(name), message ?? `Expected to find local symbol with name: ${name}`, this); } /** @@ -364,10 +364,11 @@ export class Node { * Gets the node as the specified kind if it is equal to that kind, otherwise throws. * @param kind - Syntax kind. */ - asKindOrThrow(kind: TKind): KindToNodeMappings[TKind] { + asKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind] { return errors.throwIfNullOrUndefined( this.asKind(kind), - () => `Expected the node to be of kind ${getSyntaxKindName(kind)}, but it was ${getSyntaxKindName(this.getKind())}.`, + message ?? (() => `Expected the node to be of kind ${getSyntaxKindName(kind)}, but it was ${getSyntaxKindName(this.getKind())}.`), + this ); } @@ -397,14 +398,14 @@ export class Node { * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => node is T): T; + getFirstChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first child by a condition or throws. * @param condition - Condition. */ - getFirstChildOrThrow(condition?: (node: Node) => boolean): Node; - getFirstChildOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getFirstChild(condition), "Could not find a child that matched the specified condition."); + getFirstChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; + getFirstChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getFirstChild(condition), message ?? "Could not find a child that matched the specified condition.", this); } /** @@ -426,14 +427,14 @@ export class Node { * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => node is T): T; + getLastChildOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the last child by a condition or throws. * @param condition - Condition. */ - getLastChildOrThrow(condition?: (node: Node) => boolean): Node; - getLastChildOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getLastChild(condition), "Could not find a child that matched the specified condition."); + getLastChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; + getLastChildOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLastChild(condition), message ?? "Could not find a child that matched the specified condition.", this); } /** @@ -455,14 +456,14 @@ export class Node { * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => node is T): T; + getFirstDescendantOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the first descendant by a condition or throws. * @param condition - Condition. */ - getFirstDescendantOrThrow(condition?: (node: Node) => boolean): Node; - getFirstDescendantOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getFirstDescendant(condition), "Could not find a descendant that matched the specified condition."); + getFirstDescendantOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; + getFirstDescendantOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getFirstDescendant(condition), message ?? "Could not find a descendant that matched the specified condition.", this); } /** @@ -487,14 +488,14 @@ export class Node { * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => node is T): T; + getPreviousSiblingOrThrow(condition?: (node: Node) => node is T , message?: string | (() => string)): T; /** * Gets the previous sibling or throws. * @param condition - Optional condition for getting the previous sibling. */ - getPreviousSiblingOrThrow(condition?: (node: Node) => boolean): Node; - getPreviousSiblingOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getPreviousSibling(condition), "Could not find the previous sibling."); + getPreviousSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; + getPreviousSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getPreviousSibling(condition), message ?? "Could not find the previous sibling.", this); } /** @@ -516,14 +517,14 @@ export class Node { * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => node is T): T; + getNextSiblingOrThrow(condition?: (node: Node) => node is T, message?: string | (() => string)): T; /** * Gets the next sibling or throws. * @param condition - Optional condition for getting the next sibling. */ - getNextSiblingOrThrow(condition?: (node: Node) => boolean): Node; - getNextSiblingOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getNextSibling(condition), "Could not find the next sibling."); + getNextSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)): Node; + getNextSiblingOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getNextSibling(condition), message ?? "Could not find the next sibling.", this); } /** @@ -600,8 +601,8 @@ export class Node { /** * Gets the child syntax list or throws if it doesn't exist. */ - getChildSyntaxListOrThrow() { - return errors.throwIfNullOrUndefined(this.getChildSyntaxList(), "A child syntax list was expected."); + getChildSyntaxListOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getChildSyntaxList(), message ?? "A child syntax list was expected.", this); } /** @@ -1168,8 +1169,8 @@ export class Node { /** * Gets the parent or throws an error if it doesn't exist. */ - getParentOrThrow() { - return errors.throwIfNullOrUndefined(this.getParent(), "Expected to find a parent."); + getParentOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParent(), message ?? "Expected to find a parent.", this); } /** @@ -1177,15 +1178,15 @@ export class Node { * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T): T; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => parent is T, message?: string | (() => string)): T; /** * Goes up the parents (ancestors) of the node while a condition is true. * Throws if the initial parent doesn't match the condition. * @param condition - Condition that tests the parent to see if the expression is true. */ - getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean): Node; - getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getParentWhile(condition), "The initial parent did not match the provided condition."); + getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean, message?: string | (() => string)): Node; + getParentWhileOrThrow(condition: (parent: Node, node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParentWhile(condition), message ?? "The initial parent did not match the provided condition.", this); } /** @@ -1217,8 +1218,8 @@ export class Node { * Throws if the initial parent is not the specified syntax kind. * @param kind - Syntax kind to check for. */ - getParentWhileKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getParentWhileKind(kind), `The initial parent was not a syntax kind of ${getSyntaxKindName(kind)}.`); + getParentWhileKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParentWhileKind(kind), message ?? `The initial parent was not a syntax kind of ${getSyntaxKindName(kind)}.`, this); } /** @@ -1251,8 +1252,8 @@ export class Node { /** * Gets the parent if it's a syntax list or throws an error otherwise. */ - getParentSyntaxListOrThrow() { - return errors.throwIfNullOrUndefined(this.getParentSyntaxList(), "Expected the parent to be a syntax list."); + getParentSyntaxListOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParentSyntaxList(), message ?? "Expected the parent to be a syntax list.", this); } /** @@ -1617,8 +1618,8 @@ export class Node { * Gets the first child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildByKindOrThrow(kind: TKind): KindToNodeMappings[TKind] { - return errors.throwIfNullOrUndefined(this.getFirstChildByKind(kind), `A child of the kind ${getSyntaxKindName(kind)} was expected.`); + getFirstChildByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind] { + return errors.throwIfNullOrUndefined(this.getFirstChildByKind(kind), message ?? `A child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } /** @@ -1634,8 +1635,8 @@ export class Node { * Gets the first child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getFirstChildIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind] { - return errors.throwIfNullOrUndefined(this.getFirstChildIfKind(kind), `A first child of the kind ${getSyntaxKindName(kind)} was expected.`); + getFirstChildIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind] { + return errors.throwIfNullOrUndefined(this.getFirstChildIfKind(kind), message ?? `A first child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } /** @@ -1651,8 +1652,8 @@ export class Node { * Gets the last child by syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildByKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getLastChildByKind(kind), `A child of the kind ${getSyntaxKindName(kind)} was expected.`); + getLastChildByKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLastChildByKind(kind), message ?? `A child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } /** @@ -1669,8 +1670,8 @@ export class Node { * Gets the last child if it matches the specified syntax kind or throws an error if not found. * @param kind - Syntax kind. */ - getLastChildIfKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getLastChildIfKind(kind), `A last child of the kind ${getSyntaxKindName(kind)} was expected.`); + getLastChildIfKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLastChildIfKind(kind), message ?? `A last child of the kind ${getSyntaxKindName(kind)} was expected.`, this); } /** @@ -1687,8 +1688,8 @@ export class Node { * @param index - Child index to get. * @param kind - Expected kind. */ - getChildAtIndexIfKindOrThrow(index: number, kind: TKind) { - return errors.throwIfNullOrUndefined(this.getChildAtIndexIfKind(index, kind), `Child at index ${index} was expected to be ${getSyntaxKindName(kind)}`); + getChildAtIndexIfKindOrThrow(index: number, kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getChildAtIndexIfKind(index, kind), message ?? `Child at index ${index} was expected to be ${getSyntaxKindName(kind)}`, this); } /** @@ -1705,16 +1706,16 @@ export class Node { * Gets the previous sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getPreviousSiblingIfKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getPreviousSiblingIfKind(kind), `A previous sibling of kind ${getSyntaxKindName(kind)} was expected.`); + getPreviousSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getPreviousSiblingIfKind(kind), message ?? `A previous sibling of kind ${getSyntaxKindName(kind)} was expected.`, this); } /** * Gets the next sibiling if it matches the specified kind, or throws. * @param kind - Kind to check. */ - getNextSiblingIfKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getNextSiblingIfKind(kind), `A next sibling of kind ${getSyntaxKindName(kind)} was expected.`); + getNextSiblingIfKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getNextSiblingIfKind(kind), message ?? `A next sibling of kind ${getSyntaxKindName(kind)} was expected.`, this); } /** @@ -1740,13 +1741,13 @@ export class Node { /** * Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T): T; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => parent is T, message?: string | (() => string)): T; /** * Gets the parent if it matches a certain condition or throws. */ - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean): Node; - getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getParentIf(condition), "The parent did not match the provided condition."); + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean, message?: string | (() => string)): Node; + getParentIfOrThrow(condition: (parent: Node | undefined, node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParentIf(condition), message ?? "The parent did not match the provided condition.", this); } /** @@ -1764,8 +1765,8 @@ export class Node { /** * Gets the parent if it's a certain syntax kind or throws. */ - getParentIfKindOrThrow(kind: TKind): KindToNodeMappings[TKind] { - return errors.throwIfNullOrUndefined(this.getParentIfKind(kind), `The parent was not a syntax kind of ${getSyntaxKindName(kind)}.`); + getParentIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind] { + return errors.throwIfNullOrUndefined(this.getParentIfKind(kind), message ?? `The parent was not a syntax kind of ${getSyntaxKindName(kind)}.`, this); } /** @@ -1779,8 +1780,8 @@ export class Node { * Gets the first ancestor by syntax kind or throws if not found. * @param kind - Syntax kind. */ - getFirstAncestorByKindOrThrow(kind: TKind): KindToNodeMappings[TKind] { - return errors.throwIfNullOrUndefined(this.getFirstAncestorByKind(kind), `Expected an ancestor with a syntax kind of ${getSyntaxKindName(kind)}.`); + getFirstAncestorByKindOrThrow(kind: TKind, message?: string | (() => string)): KindToNodeMappings[TKind] { + return errors.throwIfNullOrUndefined(this.getFirstAncestorByKind(kind), message ?? `Expected an ancestor with a syntax kind of ${getSyntaxKindName(kind)}.`, this); } /** @@ -1805,8 +1806,8 @@ export class Node { * @param condition - Condition to match. */ getFirstAncestorOrThrow(condition?: (node: Node) => boolean): Node; - getFirstAncestorOrThrow(condition?: (node: Node) => boolean) { - return errors.throwIfNullOrUndefined(this.getFirstAncestor(condition), `Expected to find an ancestor that matched the provided condition.`); + getFirstAncestorOrThrow(condition?: (node: Node) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getFirstAncestor(condition), message ?? `Expected to find an ancestor that matched the provided condition.`, this); } /** @@ -1842,8 +1843,8 @@ export class Node { * Gets the first descendant by syntax kind or throws. * @param kind - Syntax kind. */ - getFirstDescendantByKindOrThrow(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getFirstDescendantByKind(kind), `A descendant of kind ${getSyntaxKindName(kind)} was expected to be found.`); + getFirstDescendantByKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getFirstDescendantByKind(kind), message ?? `A descendant of kind ${getSyntaxKindName(kind)} was expected to be found.`, this); } /** diff --git a/packages/ts-morph/src/compiler/ast/decorator/Decorator.ts b/packages/ts-morph/src/compiler/ast/decorator/Decorator.ts index 630bf905a..60a89f6bc 100644 --- a/packages/ts-morph/src/compiler/ast/decorator/Decorator.ts +++ b/packages/ts-morph/src/compiler/ast/decorator/Decorator.ts @@ -111,8 +111,8 @@ export class Decorator extends DecoratorBase { /** * Gets the call expression if a decorator factory, or throws. */ - getCallExpressionOrThrow(): CallExpression { - return errors.throwIfNullOrUndefined(this.getCallExpression(), "Expected to find a call expression."); + getCallExpressionOrThrow(message?: string | (() => string)): CallExpression { + return errors.throwIfNullOrUndefined(this.getCallExpression(), message ?? "Expected to find a call expression.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/doc/JSDocTemplateTag.ts b/packages/ts-morph/src/compiler/ast/doc/JSDocTemplateTag.ts index 69c0bd278..a79d6c726 100644 --- a/packages/ts-morph/src/compiler/ast/doc/JSDocTemplateTag.ts +++ b/packages/ts-morph/src/compiler/ast/doc/JSDocTemplateTag.ts @@ -13,7 +13,7 @@ export class JSDocTemplateTag extends JSDocTemplateTagBase } /** Gets the template tag's constraint if it exists or throws otherwise. */ - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected to find the JS doc template tag's constraint."); + getConstraintOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message ?? "Expected to find the JS doc template tag's constraint.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/doc/base/JSDocPropertyLikeTag.ts b/packages/ts-morph/src/compiler/ast/doc/base/JSDocPropertyLikeTag.ts index 9dfdad0bd..36b1701cb 100644 --- a/packages/ts-morph/src/compiler/ast/doc/base/JSDocPropertyLikeTag.ts +++ b/packages/ts-morph/src/compiler/ast/doc/base/JSDocPropertyLikeTag.ts @@ -11,7 +11,7 @@ export interface JSDocPropertyLikeTag { /** Gets the type expression node of the JS doc tag if it exists. */ getTypeExpression(): JSDocTypeExpression | undefined; /** Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; /** Gets the name of the JS doc property like tag. */ getName(): string; /** Gets the name node of the JS doc property like tag. */ @@ -27,8 +27,8 @@ export function JSDocPropertyLikeTag string)) { + return errors.throwIfNullOrUndefined(this.getTypeExpression(), message ?? `Expected to find a JS doc type expression.`, this); } getName() { diff --git a/packages/ts-morph/src/compiler/ast/doc/base/JSDocTypeExpressionableTag.ts b/packages/ts-morph/src/compiler/ast/doc/base/JSDocTypeExpressionableTag.ts index 6a06b4a0a..532be46a2 100644 --- a/packages/ts-morph/src/compiler/ast/doc/base/JSDocTypeExpressionableTag.ts +++ b/packages/ts-morph/src/compiler/ast/doc/base/JSDocTypeExpressionableTag.ts @@ -15,7 +15,7 @@ export interface JSDocTypeExpressionableTag { /** * Gets the type expression node of the JS doc tag or throws if it doesn't exist. */ - getTypeExpressionOrThrow(): JSDocTypeExpression; + getTypeExpressionOrThrow(message?: string | (() => string)): JSDocTypeExpression; } export function JSDocTypeExpressionableTag>(Base: T): @@ -31,8 +31,8 @@ export function JSDocTypeExpressionableTag string)) { + return errors.throwIfNullOrUndefined(this.getTypeExpression(), message ?? `Expected to find the JS doc tag's type expression.`, this); } }; } diff --git a/packages/ts-morph/src/compiler/ast/expression/ElementAccessExpression.ts b/packages/ts-morph/src/compiler/ast/expression/ElementAccessExpression.ts index 188e2b185..6124e382e 100644 --- a/packages/ts-morph/src/compiler/ast/expression/ElementAccessExpression.ts +++ b/packages/ts-morph/src/compiler/ast/expression/ElementAccessExpression.ts @@ -17,7 +17,7 @@ export class ElementAccessExpression string)) { + return errors.throwIfNullOrUndefined(this.getArgumentExpression(), message ?? "Expected to find an argument expression.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionableNode.ts b/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionableNode.ts index 533eb8552..182afd698 100644 --- a/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionableNode.ts +++ b/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionableNode.ts @@ -14,7 +14,7 @@ export interface ExpressionableNode { /** * Gets the expression if it exists or throws. */ - getExpressionOrThrow(): Expression; + getExpressionOrThrow(message?: string | (() => string)): Expression; /** * Gets the expression if it is of the specified syntax kind or returns undefined. */ @@ -31,8 +31,8 @@ export function ExpressionableNode string)) { + return errors.throwIfNullOrUndefined(this.getExpression(), message ?? "Expected to find an expression.", this); } getExpressionIfKind(kind: TKind) { @@ -40,8 +40,12 @@ export function ExpressionableNode(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), `An expression with the kind kind ${getSyntaxKindName(kind)} was expected.`); + getExpressionIfKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getExpressionIfKind(kind), + message ?? `An expression with the kind kind ${getSyntaxKindName(kind)} was expected.`, + this, + ); } }; } diff --git a/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionedNode.ts b/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionedNode.ts index 76d86d1be..d63825aa6 100644 --- a/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionedNode.ts +++ b/packages/ts-morph/src/compiler/ast/expression/expressioned/ExpressionedNode.ts @@ -45,8 +45,12 @@ export function BaseExpressionedNode< return expression.kind === kind ? (this._getNodeFromCompilerNode(expression) as KindToExpressionMappings[TKind]) : undefined; } - getExpressionIfKindOrThrow(kind: TKind): KindToExpressionMappings[TKind] { - return errors.throwIfNullOrUndefined(this.getExpressionIfKind(kind), `An expression of the kind ${getSyntaxKindName(kind)} was expected.`); + getExpressionIfKindOrThrow(kind: TKind, message?: string | (() => string)): KindToExpressionMappings[TKind] { + return errors.throwIfNullOrUndefined( + this.getExpressionIfKind(kind), + message ?? `An expression of the kind ${getSyntaxKindName(kind)} was expected.`, + this, + ); } setExpression(textOrWriterFunction: string | WriterFunction) { diff --git a/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts b/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts index c4212e8f5..6f691692b 100644 --- a/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts +++ b/packages/ts-morph/src/compiler/ast/expression/object/ShorthandPropertyAssignment.ts @@ -32,8 +32,8 @@ export class ShorthandPropertyAssignment extends ShorthandPropertyAssignmentBase /** * Gets the object assignment initializer or throws if it doesn't exist. */ - getObjectAssignmentInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getObjectAssignmentInitializer(), "Expected to find an object assignment initializer."); + getObjectAssignmentInitializerOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getObjectAssignmentInitializer(), message ?? "Expected to find an object assignment initializer.", this); } /** @@ -46,8 +46,8 @@ export class ShorthandPropertyAssignment extends ShorthandPropertyAssignmentBase /** * Gets the equals token or throws if it doesn't exist. */ - getEqualsTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getEqualsToken(), "Expected to find an equals token."); + getEqualsTokenOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getEqualsToken(), message ?? "Expected to find an equals token.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/function/OverloadableNode.ts b/packages/ts-morph/src/compiler/ast/function/OverloadableNode.ts index 1cebd0d77..259c07415 100644 --- a/packages/ts-morph/src/compiler/ast/function/OverloadableNode.ts +++ b/packages/ts-morph/src/compiler/ast/function/OverloadableNode.ts @@ -23,7 +23,7 @@ export interface OverloadableNode { /** * Gets the implementation or throws if it doesn't exist. */ - getImplementationOrThrow(): this; + getImplementationOrThrow(message?: string | (() => string)): this; /** * Gets if this is not the implementation. */ @@ -46,8 +46,8 @@ export function OverloadableNode n.isImplementation()) as this | undefined; } - getImplementationOrThrow(): this { - return errors.throwIfNullOrUndefined(this.getImplementation(), "Expected to find a corresponding implementation for the overload."); + getImplementationOrThrow(message?: string | (() => string)): this { + return errors.throwIfNullOrUndefined(this.getImplementation(), message ?? "Expected to find a corresponding implementation for the overload.", this); } isOverload() { diff --git a/packages/ts-morph/src/compiler/ast/jsx/JsxAttribute.ts b/packages/ts-morph/src/compiler/ast/jsx/JsxAttribute.ts index 3be4313ad..da037fe5e 100644 --- a/packages/ts-morph/src/compiler/ast/jsx/JsxAttribute.ts +++ b/packages/ts-morph/src/compiler/ast/jsx/JsxAttribute.ts @@ -18,8 +18,8 @@ export class JsxAttribute extends JsxAttributeBase { /** * Gets the JSX attribute's initializer or throws if it doesn't exist. */ - getInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getInitializer(), `Expected to find an initializer for the JSX attribute '${this.getName()}'`); + getInitializerOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message ?? `Expected to find an initializer for the JSX attribute '${this.getName()}'`, this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts b/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts index 752e1aa86..78e83ae42 100644 --- a/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/module/ExportDeclaration.ts @@ -54,8 +54,8 @@ export class ExportDeclaration extends ExportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getNamespaceExport(), message ?? "Expected to find a namespace export.", this); } /** Sets the namespace export name. */ @@ -146,8 +146,8 @@ export class ExportDeclaration extends ExportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), message ?? `A module specifier source file was expected.`, this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ExportSpecifier.ts b/packages/ts-morph/src/compiler/ast/module/ExportSpecifier.ts index 19498ab89..d89cbc529 100644 --- a/packages/ts-morph/src/compiler/ast/module/ExportSpecifier.ts +++ b/packages/ts-morph/src/compiler/ast/module/ExportSpecifier.ts @@ -157,8 +157,8 @@ export class ExportSpecifier extends ExportSpecifierBase { /** * Gets the local target symbol of the export specifier or throws if it doesn't exist. */ - getLocalTargetSymbolOrThrow() { - return errors.throwIfNullOrUndefined(this.getLocalTargetSymbol(), `The export specifier's local target symbol was expected.`); + getLocalTargetSymbolOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLocalTargetSymbol(), message ?? `The export specifier's local target symbol was expected.`, this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ExternalModuleReference.ts b/packages/ts-morph/src/compiler/ast/module/ExternalModuleReference.ts index 38aa5b738..f242fe150 100644 --- a/packages/ts-morph/src/compiler/ast/module/ExternalModuleReference.ts +++ b/packages/ts-morph/src/compiler/ast/module/ExternalModuleReference.ts @@ -8,8 +8,8 @@ export class ExternalModuleReference extends ExternalModuleReferenceBase string)) { + return errors.throwIfNullOrUndefined(this.getReferencedSourceFile(), message ?? "Expected to find the referenced source file.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ImportClause.ts b/packages/ts-morph/src/compiler/ast/module/ImportClause.ts index c653a4b9e..93c2e23bd 100644 --- a/packages/ts-morph/src/compiler/ast/module/ImportClause.ts +++ b/packages/ts-morph/src/compiler/ast/module/ImportClause.ts @@ -34,8 +34,8 @@ export class ImportClause extends ImportClauseBase { /** * Gets the default import or throws if it doesn't exit. */ - getDefaultImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefaultImport(), "Expected to find a default import."); + getDefaultImportOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getDefaultImport(), message ?? "Expected to find a default import.", this); } /** @@ -48,8 +48,8 @@ export class ImportClause extends ImportClauseBase { /** * Gets the named bindings of the import clause or throws if it doesn't exist. */ - getNamedBindingsOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamedBindings(), "Expected to find an import declaration's named bindings."); + getNamedBindingsOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getNamedBindings(), message ?? "Expected to find an import declaration's named bindings.", this); } /** @@ -62,8 +62,8 @@ export class ImportClause extends ImportClauseBase { /** * Gets the namespace import if it exists or throws. */ - getNamespaceImportOrThrow() { - return errors.throwIfNullOrUndefined(this.getNamespaceImport(), "Expected to find a namespace import."); + getNamespaceImportOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getNamespaceImport(), message ?? "Expected to find a namespace import.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ImportDeclaration.ts b/packages/ts-morph/src/compiler/ast/module/ImportDeclaration.ts index d869aba41..ff9317791 100644 --- a/packages/ts-morph/src/compiler/ast/module/ImportDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/module/ImportDeclaration.ts @@ -75,8 +75,8 @@ export class ImportDeclaration extends ImportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getModuleSpecifierSourceFile(), message ?? `A module specifier source file was expected.`, this); } /** @@ -152,8 +152,8 @@ export class ImportDeclaration extends ImportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getDefaultImport(), message ?? "Expected to find a default import.", this); } /** @@ -258,8 +258,8 @@ export class ImportDeclaration extends ImportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getNamespaceImport(), message ?? "Expected to find a namespace import.", this); } /** @@ -392,8 +392,8 @@ export class ImportDeclaration extends ImportDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getImportClause(), message ?? "Expected to find an import clause.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts b/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts index 14a5d31f3..2007f17b0 100644 --- a/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/module/ImportEqualsDeclaration.ts @@ -77,10 +77,11 @@ export class ImportEqualsDeclaration extends ImportEqualsDeclarationBase string)) { return errors.throwIfNullOrUndefined( this.getExternalModuleReferenceSourceFile(), - "Expected to find an external module reference's referenced source file.", + message ?? "Expected to find an external module reference's referenced source file.", + this, ); } diff --git a/packages/ts-morph/src/compiler/ast/module/ModuleChildableNode.ts b/packages/ts-morph/src/compiler/ast/module/ModuleChildableNode.ts index b1c0e7280..811e930df 100644 --- a/packages/ts-morph/src/compiler/ast/module/ModuleChildableNode.ts +++ b/packages/ts-morph/src/compiler/ast/module/ModuleChildableNode.ts @@ -14,13 +14,13 @@ export interface ModuleChildableNode { /** * Gets the parent module declaration or throws if it doesn't exist. */ - getParentModuleOrThrow(): ModuleDeclaration; + getParentModuleOrThrow(message?: string | (() => string)): ModuleDeclaration; } export function ModuleChildableNode>(Base: T): Constructor & T { return class extends Base implements ModuleChildableNode { - getParentModuleOrThrow() { - return errors.throwIfNullOrUndefined(this.getParentModule(), "Expected to find the parent module declaration."); + getParentModuleOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParentModule(), message ?? "Expected to find the parent module declaration.", this); } getParentModule() { diff --git a/packages/ts-morph/src/compiler/ast/statement/BreakStatement.ts b/packages/ts-morph/src/compiler/ast/statement/BreakStatement.ts index c45b99ba5..241aa26af 100644 --- a/packages/ts-morph/src/compiler/ast/statement/BreakStatement.ts +++ b/packages/ts-morph/src/compiler/ast/statement/BreakStatement.ts @@ -13,7 +13,7 @@ export class BreakStatement extends Statement { /** * Gets this break statement's label or throw if it does not exist. */ - getLabelOrThrow() { - return errors.throwIfNullOrUndefined(this.getLabel(), "Expected to find a label."); + getLabelOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLabel(), message ?? "Expected to find a label.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/statement/CatchClause.ts b/packages/ts-morph/src/compiler/ast/statement/CatchClause.ts index 0a0805952..b759bca10 100644 --- a/packages/ts-morph/src/compiler/ast/statement/CatchClause.ts +++ b/packages/ts-morph/src/compiler/ast/statement/CatchClause.ts @@ -22,7 +22,7 @@ export class CatchClause extends CatchClauseBase { /** * Gets this catch clause's variable declaration or throws if none exists. */ - getVariableDeclarationOrThrow() { - return errors.throwIfNullOrUndefined(this.getVariableDeclaration(), "Expected to find a variable declaration."); + getVariableDeclarationOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getVariableDeclaration(), message ?? "Expected to find a variable declaration.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/statement/ContinueStatement.ts b/packages/ts-morph/src/compiler/ast/statement/ContinueStatement.ts index 771f92556..444fe266b 100644 --- a/packages/ts-morph/src/compiler/ast/statement/ContinueStatement.ts +++ b/packages/ts-morph/src/compiler/ast/statement/ContinueStatement.ts @@ -15,7 +15,7 @@ export class ContinueStatement extends Statement { /** * Gets this continue statement's label or throw if it does not exist. */ - getLabelOrThrow() { - return errors.throwIfNullOrUndefined(this.getLabel(), "Expected to find a label."); + getLabelOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLabel(), message ?? "Expected to find a label.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/statement/ForStatement.ts b/packages/ts-morph/src/compiler/ast/statement/ForStatement.ts index cec4174d1..034747c57 100644 --- a/packages/ts-morph/src/compiler/ast/statement/ForStatement.ts +++ b/packages/ts-morph/src/compiler/ast/statement/ForStatement.ts @@ -15,8 +15,8 @@ export class ForStatement extends ForStatementBase { /** * Gets this for statement's initializer or throws if none exists. */ - getInitializerOrThrow() { - return errors.throwIfNullOrUndefined(this.getInitializer(), "Expected to find an initializer."); + getInitializerOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getInitializer(), message ?? "Expected to find an initializer.", this); } /** @@ -29,8 +29,8 @@ export class ForStatement extends ForStatementBase { /** * Gets this for statement's condition or throws if none exists. */ - getConditionOrThrow() { - return errors.throwIfNullOrUndefined(this.getCondition(), "Expected to find a condition."); + getConditionOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getCondition(), message ?? "Expected to find a condition.", this); } /** @@ -43,7 +43,7 @@ export class ForStatement extends ForStatementBase { /** * Gets this for statement's incrementor or throws if none exists. */ - getIncrementorOrThrow() { - return errors.throwIfNullOrUndefined(this.getIncrementor(), "Expected to find an incrementor."); + getIncrementorOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getIncrementor(), message ?? "Expected to find an incrementor.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/statement/StatementedNode.ts b/packages/ts-morph/src/compiler/ast/statement/StatementedNode.ts index 612ee7539..4e37e25f9 100644 --- a/packages/ts-morph/src/compiler/ast/statement/StatementedNode.ts +++ b/packages/ts-morph/src/compiler/ast/statement/StatementedNode.ts @@ -500,8 +500,8 @@ export function StatementedNode boolean) { - return errors.throwIfNullOrUndefined(this.getStatement(findFunction), "Expected to find a statement matching the provided condition."); + getStatementOrThrow(findFunction: (statement: Statement) => boolean, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getStatement(findFunction), message ?? "Expected to find a statement matching the provided condition.", this); } getStatementByKind(kind: TKind): KindToNodeMappingsWithCommentStatements[TKind] | undefined { @@ -509,8 +509,12 @@ export function StatementedNode(kind: TKind) { - return errors.throwIfNullOrUndefined(this.getStatementByKind(kind), `Expected to find a statement with syntax kind ${getSyntaxKindName(kind)}.`); + getStatementByKindOrThrow(kind: TKind, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined( + this.getStatementByKind(kind), + message ?? `Expected to find a statement with syntax kind ${getSyntaxKindName(kind)}.`, + this, + ); } addStatements(textOrWriterFunction: string | WriterFunction | ReadonlyArray) { @@ -868,10 +872,14 @@ export function StatementedNode boolean)): VariableStatement { + getVariableStatementOrThrow( + nameOrFindFunction: string | ((statement: VariableStatement) => boolean), + message?: string | (() => string), + ): VariableStatement { return errors.throwIfNullOrUndefined( this.getVariableStatement(nameOrFindFunction), - "Expected to find a variable statement that matched the provided condition.", + message ?? "Expected to find a variable statement that matched the provided condition.", + this, ); } diff --git a/packages/ts-morph/src/compiler/ast/statement/TryStatement.ts b/packages/ts-morph/src/compiler/ast/statement/TryStatement.ts index 839d39952..eca51eb39 100644 --- a/packages/ts-morph/src/compiler/ast/statement/TryStatement.ts +++ b/packages/ts-morph/src/compiler/ast/statement/TryStatement.ts @@ -22,8 +22,8 @@ export class TryStatement extends TryStatementBase { /** * Gets this try statement's catch clause or throws if none exists. */ - getCatchClauseOrThrow() { - return errors.throwIfNullOrUndefined(this.getCatchClause(), "Expected to find a catch clause."); + getCatchClauseOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getCatchClause(), message ?? "Expected to find a catch clause.", this); } /** @@ -39,7 +39,7 @@ export class TryStatement extends TryStatementBase { /** * Gets this try statement's finally block or throws if none exists. */ - getFinallyBlockOrThrow() { - return errors.throwIfNullOrUndefined(this.getFinallyBlock(), "Expected to find a finally block."); + getFinallyBlockOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getFinallyBlock(), message ?? "Expected to find a finally block.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/type/ImportTypeNode.ts b/packages/ts-morph/src/compiler/ast/type/ImportTypeNode.ts index f18b1f744..b0869e592 100644 --- a/packages/ts-morph/src/compiler/ast/type/ImportTypeNode.ts +++ b/packages/ts-morph/src/compiler/ast/type/ImportTypeNode.ts @@ -54,8 +54,8 @@ export class ImportTypeNode extends NodeWithTypeArguments { /** * Gets the qualifier of the import type if it exists or throws */ - getQualifierOrThrow(): EntityName { - return errors.throwIfNullOrUndefined(this.getQualifier(), () => `Expected to find a qualifier for the import type: ${this.getText()}`); + getQualifierOrThrow(message?: string | (() => string)): EntityName { + return errors.throwIfNullOrUndefined(this.getQualifier(), message ?? (() => `Expected to find a qualifier for the import type: ${this.getText()}`), this); } /** @@ -71,10 +71,11 @@ export class ImportTypeNode extends NodeWithTypeArguments { } /** Gets the import type assertion container if it exists or throws. */ - getAssertionsOrThrow() { + getAssertionsOrThrow(message?: string | (() => string)) { return errors.throwIfNullOrUndefined( this._getNodeFromCompilerNodeIfExists(this.compilerNode.assertions), - "Could not find import type assertion container.", + message ?? "Could not find import type assertion container.", + this, ); } } diff --git a/packages/ts-morph/src/compiler/ast/type/MappedTypeNode.ts b/packages/ts-morph/src/compiler/ast/type/MappedTypeNode.ts index c870d80c8..7185ff42e 100644 --- a/packages/ts-morph/src/compiler/ast/type/MappedTypeNode.ts +++ b/packages/ts-morph/src/compiler/ast/type/MappedTypeNode.ts @@ -11,8 +11,8 @@ export class MappedTypeNode extends TypeNode { } /** Gets the mapped type node's name type node or throws if it doesn't exist. */ - getNameTypeNodeOrThrow(): TypeNode { - return errors.throwIfNullOrUndefined(this.getNameTypeNode(), "Type did not exist."); + getNameTypeNodeOrThrow(message?: string | (() => string)): TypeNode { + return errors.throwIfNullOrUndefined(this.getNameTypeNode(), message ?? "Type did not exist.", this); } /** Gets the mapped type's readonly token. */ @@ -21,8 +21,8 @@ export class MappedTypeNode extends TypeNode { } /** Gets the mapped type's readonly token or throws if not exist. */ - getReadonlyTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getReadonlyToken(), "Readonly token did not exist."); + getReadonlyTokenOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getReadonlyToken(), message ?? "Readonly token did not exist.", this); } /** Gets the mapped type's question token. */ @@ -31,8 +31,8 @@ export class MappedTypeNode extends TypeNode { } /** Gets the mapped type's question token or throws if not exist. */ - getQuestionTokenOrThrow() { - return errors.throwIfNullOrUndefined(this.getQuestionToken(), "Question token did not exist."); + getQuestionTokenOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getQuestionToken(), message ?? "Question token did not exist.", this); } /** @@ -48,7 +48,7 @@ export class MappedTypeNode extends TypeNode { } /** Gets the mapped type node's type node if it exists or throws when undefined. */ - getTypeNodeOrThrow(): TypeNode { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Type did not exist, but was expected to exist."); + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message ?? "Type did not exist, but was expected to exist.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/type/TypeParameterDeclaration.ts b/packages/ts-morph/src/compiler/ast/type/TypeParameterDeclaration.ts index 445d349be..e6d61c142 100644 --- a/packages/ts-morph/src/compiler/ast/type/TypeParameterDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/type/TypeParameterDeclaration.ts @@ -32,8 +32,8 @@ export class TypeParameterDeclaration extends TypeParameterDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message ?? "Expected to find the type parameter's constraint.", this); } /** @@ -81,8 +81,8 @@ export class TypeParameterDeclaration extends TypeParameterDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getDefault(), message ?? "Expected to find the type parameter's default.", this); } /** diff --git a/packages/ts-morph/src/compiler/ast/type/TypePredicateNode.ts b/packages/ts-morph/src/compiler/ast/type/TypePredicateNode.ts index fa922a005..fd6aad10a 100644 --- a/packages/ts-morph/src/compiler/ast/type/TypePredicateNode.ts +++ b/packages/ts-morph/src/compiler/ast/type/TypePredicateNode.ts @@ -33,8 +33,8 @@ export class TypePredicateNode extends TypeNode { /** * Gets the asserts modifier if it exists or throws otherwise. */ - getAssertsModifierOrThrow() { - return errors.throwIfNullOrUndefined(this.getAssertsModifier(), "Expected to find an asserts modifier."); + getAssertsModifierOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getAssertsModifier(), message ?? "Expected to find an asserts modifier.", this); } /** @@ -47,7 +47,7 @@ export class TypePredicateNode extends TypeNode { /** * Gets the type name if it exists or throws when it asserts a condition. */ - getTypeNodeOrThrow(): TypeNode { - return errors.throwIfNullOrUndefined(this.getTypeNode(), "Expected to find a type node."); + getTypeNodeOrThrow(message?: string | (() => string)): TypeNode { + return errors.throwIfNullOrUndefined(this.getTypeNode(), message ?? "Expected to find a type node.", this); } } diff --git a/packages/ts-morph/src/compiler/ast/variable/VariableDeclaration.ts b/packages/ts-morph/src/compiler/ast/variable/VariableDeclaration.ts index c4a1e6eca..1e4635991 100644 --- a/packages/ts-morph/src/compiler/ast/variable/VariableDeclaration.ts +++ b/packages/ts-morph/src/compiler/ast/variable/VariableDeclaration.ts @@ -53,8 +53,8 @@ export class VariableDeclaration extends VariableDeclarationBase string)) { + return errors.throwIfNullOrUndefined(this.getVariableStatement(), message ?? "Expected the grandparent to be a variable statement.", this); } /** diff --git a/packages/ts-morph/src/compiler/symbols/Symbol.ts b/packages/ts-morph/src/compiler/symbols/Symbol.ts index b8cc9da13..018c154cb 100644 --- a/packages/ts-morph/src/compiler/symbols/Symbol.ts +++ b/packages/ts-morph/src/compiler/symbols/Symbol.ts @@ -48,8 +48,8 @@ export class Symbol { /** * Gets the aliased symbol or throws if it doesn't exist. */ - getAliasedSymbolOrThrow(): Symbol { - return errors.throwIfNullOrUndefined(this.getAliasedSymbol(), "Expected to find an aliased symbol."); + getAliasedSymbolOrThrow(message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getAliasedSymbol(), message ?? "Expected to find an aliased symbol."); } /** @@ -62,8 +62,8 @@ export class Symbol { /** * Follows a single alias to get the immediately aliased symbol or throws if it doesn't exist. */ - getImmediatelyAliasedSymbolOrThrow(): Symbol { - return errors.throwIfNullOrUndefined(this.getImmediatelyAliasedSymbol(), "Expected to find an immediately aliased symbol."); + getImmediatelyAliasedSymbolOrThrow(message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getImmediatelyAliasedSymbol(), message ?? "Expected to find an immediately aliased symbol."); } /** @@ -119,8 +119,11 @@ export class Symbol { /** * Gets the value declaration of a symbol or throws if it doesn't exist. */ - getValueDeclarationOrThrow(): Node { - return errors.throwIfNullOrUndefined(this.getValueDeclaration(), () => `Expected to find the value declaration of symbol '${this.getName()}'.`); + getValueDeclarationOrThrow(message?: string | (() => string)): Node { + return errors.throwIfNullOrUndefined( + this.getValueDeclaration(), + message ?? (() => `Expected to find the value declaration of symbol '${this.getName()}'.`), + ); } /** @@ -145,8 +148,8 @@ export class Symbol { * Gets the export of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getExportOrThrow(name: string): Symbol { - return errors.throwIfNullOrUndefined(this.getExport(name), `Expected to find export with name: ${name}`); + getExportOrThrow(name: string, message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getExport(name), message ?? (() => `Expected to find export with name: ${name}`)); } /** @@ -174,8 +177,8 @@ export class Symbol { * Gets the global export of the symbol by the specified name or throws if not exists. * @param name - Name of the global export. */ - getGlobalExportOrThrow(name: string): Symbol { - return errors.throwIfNullOrUndefined(this.getGlobalExport(name), `Expected to find global export with name: ${name}`); + getGlobalExportOrThrow(name: string, message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getGlobalExport(name), message ?? (() => `Expected to find global export with name: ${name}`)); } /** @@ -203,8 +206,8 @@ export class Symbol { * Gets the member of the symbol by the specified name or throws if not exists. * @param name - Name of the export. */ - getMemberOrThrow(name: string): Symbol { - return errors.throwIfNullOrUndefined(this.getMember(name), `Expected to find member with name: ${name}`); + getMemberOrThrow(name: string, message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getMember(name), message ?? `Expected to find member with name: ${name}`); } /** diff --git a/packages/ts-morph/src/compiler/tools/TypeChecker.ts b/packages/ts-morph/src/compiler/tools/TypeChecker.ts index 9d8949600..92b84519a 100644 --- a/packages/ts-morph/src/compiler/tools/TypeChecker.ts +++ b/packages/ts-morph/src/compiler/tools/TypeChecker.ts @@ -217,8 +217,8 @@ export class TypeChecker { * Gets the resolved signature from a node or throws if the signature cannot be resolved. * @param node - Node to get the signature from. */ - getResolvedSignatureOrThrow(node: CallLikeExpression) { - return errors.throwIfNullOrUndefined(this.getResolvedSignature(node), "Signature could not be resolved."); + getResolvedSignatureOrThrow(node: CallLikeExpression, message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getResolvedSignature(node), message ?? "Signature could not be resolved.", node); } /** diff --git a/packages/ts-morph/src/compiler/types/Type.ts b/packages/ts-morph/src/compiler/types/Type.ts index 2c42b27d8..d41b527ef 100644 --- a/packages/ts-morph/src/compiler/types/Type.ts +++ b/packages/ts-morph/src/compiler/types/Type.ts @@ -48,7 +48,7 @@ export class Type { /** * Gets the alias symbol if it exists, or throws. */ - getAliasSymbolOrThrow(): Symbol { + getAliasSymbolOrThrow(message?: string | (() => string)): Symbol { return errors.throwIfNullOrUndefined(this.getAliasSymbol(), "Expected to find an alias symbol."); } @@ -70,8 +70,8 @@ export class Type { /** * Gets the array element type or throws if it doesn't exist (ex. for `T[]` it would be `T`). */ - getArrayElementTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getArrayElementType(), "Expected to find an array element type."); + getArrayElementTypeOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getArrayElementType(), message ?? "Expected to find an array element type."); } /** @@ -117,8 +117,8 @@ export class Type { /** * Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow() { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected to find a constraint."); + getConstraintOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getConstraint(), message ?? "Expected to find a constraint."); } /** @@ -132,8 +132,8 @@ export class Type { /** * Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow() { - return errors.throwIfNullOrUndefined(this.getDefault(), "Expected to find a default type."); + getDefaultOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getDefault(), message ?? "Expected to find a default type."); } /** @@ -260,8 +260,8 @@ export class Type { * - Given `string` throws an error. */ - getTargetTypeOrThrow(): Type { - return errors.throwIfNullOrUndefined(this.getTargetType(), "Expected to find the target type."); + getTargetTypeOrThrow(message?: string | (() => string)): Type { + return errors.throwIfNullOrUndefined(this.getTargetType(), message ?? "Expected to find the target type."); } /** @@ -308,8 +308,8 @@ export class Type { /** * Gets the value of the literal or throws if this is not a literal type. */ - getLiteralValueOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralValue(), "Type was not a literal type."); + getLiteralValueOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLiteralValue(), message ?? "Type was not a literal type."); } /** @@ -327,8 +327,8 @@ export class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralFreshTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralFreshType(), "Type was not a literal type."); + getLiteralFreshTypeOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLiteralFreshType(), message ?? "Type was not a literal type."); } /** @@ -346,8 +346,8 @@ export class Type { * * Note: I have no idea what this means. Please help contribute to these js docs if you know. */ - getLiteralRegularTypeOrThrow() { - return errors.throwIfNullOrUndefined(this.getLiteralRegularType(), "Type was not a literal type."); + getLiteralRegularTypeOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getLiteralRegularType(), message ?? "Type was not a literal type."); } /** @@ -361,8 +361,8 @@ export class Type { /** * Gets the symbol of the type or throws. */ - getSymbolOrThrow(): Symbol { - return errors.throwIfNullOrUndefined(this.getSymbol(), "Expected to find a symbol."); + getSymbolOrThrow(message?: string | (() => string)): Symbol { + return errors.throwIfNullOrUndefined(this.getSymbol(), message ?? "Expected to find a symbol."); } /** diff --git a/packages/ts-morph/src/compiler/types/TypeParameter.ts b/packages/ts-morph/src/compiler/types/TypeParameter.ts index c76a96fff..b4ce0a8a1 100644 --- a/packages/ts-morph/src/compiler/types/TypeParameter.ts +++ b/packages/ts-morph/src/compiler/types/TypeParameter.ts @@ -6,8 +6,8 @@ export class TypeParameter extends Type { /** * Gets the constraint or throws if it doesn't exist. */ - getConstraintOrThrow(): Type { - return errors.throwIfNullOrUndefined(this.getConstraint(), "Expected type parameter to have a constraint."); + getConstraintOrThrow(message?: string | (() => string)): Type { + return errors.throwIfNullOrUndefined(this.getConstraint(), message ?? "Expected type parameter to have a constraint."); } /** @@ -26,8 +26,8 @@ export class TypeParameter extends Type { /** * Gets the default type or throws if it doesn't exist. */ - getDefaultOrThrow(): Type { - return errors.throwIfNullOrUndefined(this.getDefault(), "Expected type parameter to have a default type."); + getDefaultOrThrow(message?: string | (() => string)): Type { + return errors.throwIfNullOrUndefined(this.getDefault(), message ?? "Expected type parameter to have a default type."); } /** diff --git a/packages/ts-morph/src/fileSystem/Directory.ts b/packages/ts-morph/src/fileSystem/Directory.ts index 2718cfd59..242fea54c 100644 --- a/packages/ts-morph/src/fileSystem/Directory.ts +++ b/packages/ts-morph/src/fileSystem/Directory.ts @@ -91,8 +91,8 @@ export class Directory { /** * Gets the parent directory or throws if it doesn't exist or was never added to the project. */ - getParentOrThrow() { - return errors.throwIfNullOrUndefined(this.getParent(), () => `Parent directory of ${this.getPath()} does not exist or was never added.`); + getParentOrThrow(message?: string | (() => string)) { + return errors.throwIfNullOrUndefined(this.getParent(), message ?? (() => `Parent directory of ${this.getPath()} does not exist or was never added.`)); } /** diff --git a/packages/ts-morph/src/manipulation/textManipulators/UnwrapTextManipulator.ts b/packages/ts-morph/src/manipulation/textManipulators/UnwrapTextManipulator.ts index e6505d3f0..27920bc0c 100644 --- a/packages/ts-morph/src/manipulation/textManipulators/UnwrapTextManipulator.ts +++ b/packages/ts-morph/src/manipulation/textManipulators/UnwrapTextManipulator.ts @@ -39,7 +39,7 @@ function getReplacementText(node: Node) { else if (Node.isBodyable(node)) return node.getBodyOrThrow(); else - throw new errors.NotImplementedError(`Not implemented unwrap scenario for ${node.getKindName()}.`); + errors.throwNotImplementedForSyntaxKindError(node.getKind(), node); } } } diff --git a/packages/ts-morph/src/tests/compiler/tools/errors.ts b/packages/ts-morph/src/tests/compiler/tools/errors.ts new file mode 100644 index 000000000..f99fd558f --- /dev/null +++ b/packages/ts-morph/src/tests/compiler/tools/errors.ts @@ -0,0 +1,62 @@ +import { SyntaxKind } from "@ts-morph/common"; +import { assert, expect } from "chai"; +import { Project } from "../../../Project"; + +describe("orThrow", () => { + it("should show the source of the throw", () => { + const project = new Project({ useInMemoryFileSystem: true, skipLoadingLibFiles: true }); + const sourceFile = project.createSourceFile( + "test.ts", + ` + // Test + export const foo = 42; + export const bar = 99; + `, + ); + const exportDeclaration = sourceFile.getExportedDeclarations().get("bar")?.[0]; + assert(exportDeclaration); + expect(() => exportDeclaration.getLastChildByKindOrThrow(SyntaxKind.IfStatement)) + .to.throw(`A child of the kind IfStatement was expected. + +/test.ts:4:22 +> 4 | export const bar = 99;`); + }); + + it("should show allow to set a custom error message", () => { + const project = new Project({ useInMemoryFileSystem: true, skipLoadingLibFiles: true }); + const sourceFile = project.createSourceFile( + "test.ts", + ` + // Test + export const foo = 42; + export const bar = 99; + `, + ); + const exportDeclaration = sourceFile.getExportedDeclarations().get("bar")?.[0]; + assert(exportDeclaration); + expect(() => exportDeclaration.getLastChildByKindOrThrow(SyntaxKind.IfStatement, "This is a demo error message.")) + .to.throw(`This is a demo error message. + +/test.ts:4:22 +> 4 | export const bar = 99;`); + }); + + it("should show allow to set a function returning a custom error message", () => { + const project = new Project({ useInMemoryFileSystem: true, skipLoadingLibFiles: true }); + const sourceFile = project.createSourceFile( + "test.ts", + ` + // Test + export const foo = 42; + export const bar = 99; + `, + ); + const exportDeclaration = sourceFile.getExportedDeclarations().get("bar")?.[0]; + assert(exportDeclaration); + expect(() => exportDeclaration.getLastChildByKindOrThrow(SyntaxKind.IfStatement, () => "This is a demo error message.")) + .to.throw(`This is a demo error message. + +/test.ts:4:22 +> 4 | export const bar = 99;`); + }); +});