Text or writer function.
Gets the node as the specified kind if it is equal to that kind, otherwise returns undefined.
Syntax kind.
Gets the node as the specified kind if it is equal to that kind, otherwise throws.
Syntax kind.
Optionalmessage: string | (() => string)If the node contains the provided range (inclusive).
Start position.
End position.
Invokes the cbNode callback for each child and the cbNodeArray for every array of nodes stored in properties of the node.
If cbNodeArray is not defined, then it will pass every element of the array to cbNode.
Callback invoked for each child.
OptionalcbNodeArray: (nodes: Node<Node>[]) => T | undefinedCallback invoked for each array of nodes.
The first truthy value returned by a callback.
Gets the child nodes passed to the delegate of node.forEachChild(child => {}) as an array.
Invokes the cbNode callback for each descendant and the cbNodeArray for every array of nodes stored in properties of the node and descendant nodes.
If cbNodeArray is not defined, then it will pass every element of the array to cbNode.
Callback invoked for each descendant.
OptionalcbNodeArray: (Callback invoked for each array of nodes.
The first truthy value returned by a callback.
Gets the descendant nodes passed to the delegate of node.forEachDescendant(descendant => {}) as an array.
Releases the node and all its descendants from the underlying node cache and ast.
This is useful if you want to improve the performance of manipulation by not tracking this node anymore.
Forgets the descendants of this node.
Formats the node's text using the internal TypeScript formatting API.
Optionalsettings: FormatCodeSettingsFormat code settings.
Goes up the tree getting all the parents in ascending order.
Gets the child at the specified index.
Index of the child.
Gets the child at the specified index if it's the specified kind or returns undefined.
Child index to get.
Expected kind.
Gets the child at the specified index if it's the specified kind or throws an exception.
Child index to get.
Expected kind.
Optionalmessage: string | (() => string)Gets the child at the provided text position, or undefined if not found.
Text position to search for.
Gets the number of children the node has.
Gets the child indentation level of the current node.
Gets the next indentation level text.
Optionaloffset: numberOptional number of levels of indentation to add or remove.
Gets the child index of this node relative to the parent.
Gets all the children of the node.
Gets the children based on a kind.
Syntax kind.
Gets the child syntax list if it exists.
Gets the child syntax list or throws if it doesn't exist.
Optionalmessage: string | (() => string)Gets the combined modifier flags.
Gets the most specific descendant at the provided text position, or undefined if not found.
Text position to search for.
Gets the most specific descendant at the provided start text position with the specified width, or undefined if not found.
Start text position to search for.
Text length of the node to search for.
Gets the node's descendants.
Gets the descendants that match a specified syntax kind.
Kind to check.
Gets the node's descendant statements and any arrow function statement-like expressions (ex. returns the expression 5 in () => 5).
Gets the line number of the end of the node.
Gets the first ancestor that matches the provided condition or returns undefined if not found.
Optionalcondition: (node: Node) => node is TCondition to match.
Gets the first ancestor that matches the provided condition or returns undefined if not found.
Optionalcondition: (node: Node) => booleanCondition to match.
Get the first ancestor by syntax kind.
Syntax kind.
Gets the first ancestor by syntax kind or throws if not found.
Syntax kind.
Optionalmessage: string | (() => string)Gets the first ancestor that matches the provided condition or throws if not found.
Optionalcondition: (node: Node) => node is TCondition to match.
Gets the first ancestor that matches the provided condition or throws if not found.
Optionalcondition: (node: Node) => booleanCondition to match.
Gets the first child by a condition.
Optionalcondition: (node: Node) => node is TCondition.
Gets the first child by a condition.
Optionalcondition: (node: Node) => booleanCondition.
Gets the first child by syntax kind.
Syntax kind.
Gets the first child by syntax kind or throws an error if not found.
Syntax kind.
Optionalmessage: string | (() => string)Gets the first child if it matches the specified syntax kind.
Syntax kind.
Gets the first child if it matches the specified syntax kind or throws an error if not found.
Syntax kind.
Optionalmessage: string | (() => string)Gets the first child by a condition or throws.
Optionalcondition: (node: Node) => node is TCondition.
Optionalmessage: string | (() => string)Gets the first child by a condition or throws.
Optionalcondition: (node: Node) => booleanCondition.
Optionalmessage: string | (() => string)Gets the first descendant by a condition.
Optionalcondition: (node: Node) => node is TCondition.
Gets the first descendant by a condition.
Optionalcondition: (node: Node) => booleanCondition.
Gets the first descendant by syntax kind.
Syntax kind.
Gets the first descendant by syntax kind or throws.
Syntax kind.
Optionalmessage: string | (() => string)Gets the first descendant by a condition or throws.
Optionalcondition: (node: Node) => node is TCondition.
Optionalmessage: string | (() => string)Gets the first descendant by a condition or throws.
Optionalcondition: (node: Node) => booleanCondition.
Optionalmessage: string | (() => string)Gets the node's flags.
Gets the source file text position of the end of the last significant token or the start of the source file.
Gets the full text with leading trivia (comments and whitespace).
Gets the text length of the node with trivia.
Gets the indentation level of the current node.
Gets the indentation text.
Optionaloffset: numberOptional number of levels of indentation to add or remove.
Gets the syntax kind.
Gets the syntax kind name.
Gets the last child by a condition.
Optionalcondition: (node: Node) => node is TCondition.
Gets the last child by a condition.
Optionalcondition: (node: Node) => booleanCondition.
Gets the last child by syntax kind.
Syntax kind.
Gets the last child by syntax kind or throws an error if not found.
Syntax kind.
Optionalmessage: string | (() => string)Gets the last child if it matches the specified syntax kind.
Syntax kind.
Gets the last child if it matches the specified syntax kind or throws an error if not found.
Syntax kind.
Optionalmessage: string | (() => string)Gets the last child by a condition or throws.
Optionalcondition: (node: Node) => node is TCondition.
Optionalmessage: string | (() => string)Gets the last child by a condition or throws.
Optionalcondition: (node: Node) => booleanCondition.
Optionalmessage: string | (() => string)Gets the last token of this node. Usually this is a close brace.
Gets the leading comment ranges of the current node.
Gets the node's leading trivia's text length.
Gets the specified local symbol by name or returns undefined if it doesn't exist.
WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break.
Name of the local symbol.
Gets the specified local symbol by name or throws if it doesn't exist.
WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break.
Name of the local symbol.
Optionalmessage: string | (() => string)Gets the symbols within the current scope.
WARNING: The symbol table of locals is not exposed publicly by the compiler. Use this at your own risk knowing it may break.
Gets the next sibling.
Optionalcondition: (node: Node) => node is TOptional condition for getting the next sibling.
Gets the next sibling.
Optionalcondition: (node: Node) => booleanOptional condition for getting the next sibling.
Gets the next sibling if it matches the specified kind.
Kind to check.
Gets the next sibiling if it matches the specified kind, or throws.
Kind to check.
Optionalmessage: string | (() => string)Gets the next sibling or throws.
Optionalcondition: (node: Node) => node is TOptional condition for getting the next sibling.
Optionalmessage: string | (() => string)Gets the next sibling or throws.
Optionalcondition: (node: Node) => booleanOptional condition for getting the next sibling.
Optionalmessage: string | (() => string)Gets the next siblings.
Note: Closest sibling is the zero index.
Gets a compiler node property wrapped in a Node.
Property name.
Gets the first source file text position that is not whitespace taking into account comment nodes and a previous node's trailing trivia.
Get the node's parent.
Gets the parent if it matches a certain condition.
Gets the parent if it matches a certain condition.
Gets the parent if it's a certain syntax kind.
Gets the parent if it's a certain syntax kind or throws.
Optionalmessage: string | (() => string)Gets the parent if it matches a certain condition or throws.
Optionalmessage: string | (() => string)Gets the parent if it matches a certain condition or throws.
Optionalmessage: string | (() => string)Gets the parent or throws an error if it doesn't exist.
Optionalmessage: string | (() => string)Gets the parent if it's a syntax list.
Gets the parent if it's a syntax list or throws an error otherwise.
Optionalmessage: string | (() => string)Goes up the parents (ancestors) of the node while a condition is true. Returns undefined if the initial parent doesn't match the condition.
Condition that tests the parent to see if the expression is true.
Goes up the parents (ancestors) of the node while a condition is true. Returns undefined if the initial parent doesn't match the condition.
Condition that tests the parent to see if the expression is true.
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.
Syntax kind to check for.
Goes up the parents (ancestors) of the node while the parent is the specified syntax kind. Throws if the initial parent is not the specified syntax kind.
Syntax kind to check for.
Optionalmessage: string | (() => string)Goes up the parents (ancestors) of the node while a condition is true. Throws if the initial parent doesn't match the condition.
Condition that tests the parent to see if the expression is true.
Optionalmessage: string | (() => string)Goes up the parents (ancestors) of the node while a condition is true. Throws if the initial parent doesn't match the condition.
Condition that tests the parent to see if the expression is true.
Optionalmessage: string | (() => string)Gets the source file text position where the node starts that includes the leading trivia (comments and whitespace).
Gets the previous sibling.
Optionalcondition: (node: Node) => node is TOptional condition for getting the previous sibling.
Gets the previous sibling.
Optionalcondition: (node: Node) => booleanOptional condition for getting the previous sibling.
Gets the previous sibling if it matches the specified kind.
Kind to check.
Gets the previous sibiling if it matches the specified kind, or throws.
Kind to check.
Optionalmessage: string | (() => string)Gets the previous sibling or throws.
Optionalcondition: (node: Node) => node is TOptional condition for getting the previous sibling.
Optionalmessage: string | (() => string)Gets the previous sibling or throws.
Optionalcondition: (node: Node) => booleanOptional condition for getting the previous sibling.
Optionalmessage: string | (() => string)Gets the previous siblings.
Note: Closest sibling is the zero index.
Gets the project.
Gets the source file.
Gets the source file text position where the node starts that does not include the leading trivia (comments and whitespace).
OptionalincludeJsDocComments: booleanWhether to include the JS doc comments.
Gets the line number at the start of the node.
OptionalincludeJsDocComments: booleanWhether to include the JS doc comments or not.
Gets the position of the start of the line that this node starts on.
OptionalincludeJsDocComments: booleanWhether to include the JS doc comments or not.
Gets the compiler symbol or undefined if it doesn't exist.
Gets the symbol or throws an error if it doesn't exist.
Optionalmessage: string | (() => string)Gets the symbols in the scope of the node.
Note: This will always return the local symbols. If you want the export symbol from a local symbol, then
use the #getExportSymbol() method on the symbol.
Meaning of symbol to filter by.
Gets the text without leading trivia (comments and whitespace).
OptionalincludeJsDocComments: booleanWhether to include the js doc comments when getting the text.
Gets the text without leading trivia (comments and whitespace).
Options for getting the text.
Gets the trailing comment ranges of the current node.
Gets the text position of the next significant token or new line.
Gets the text length from the end of the current node to the next significant token or new line.
Gets the type of the node.
Gets the text length of the node without trivia.
OptionalincludeJsDocComments: booleanWhether to include the JS doc comments in the width or not.
Gets if this is the first node on the current line.
Gets if the specified position is within a string.
Position.
Gets if this node is in a syntax list.
Returns if the node is the specified kind.
This is a type guard.
Syntax kind.
Prepends the specified whitespace to current node.
Text or writer function.
Prints the node using the compiler's printer.
Optionaloptions: PrintNodeOptionsOptions.
Replaces the text of the current node with new text.
This will forget the current node and return a new node that can be asserted or type guarded to the correct type.
Text or writer function to replace with.
The new node.
Transforms the node using the compiler api nodes and functions and returns the node that was transformed (experimental).
WARNING: This will forget descendants of transformed nodes and potentially this node.
sourceFile.transform(traversal => {
const node = traversal.visitChildren(); // recommend always visiting the children first (post order)
if (ts.isNumericLiteral(node))
return ts.createNumericLiteral((parseInt(node.text, 10) + 1).toString());
return node;
});
const classDec = sourceFile.getClassOrThrow("MyClass");
classDec.transform(traversal => {
const node = traversal.currentNode;
return ts.updateClassDeclaration(node, undefined, undefined, ts.createIdentifier("MyUpdatedClass"), undefined, undefined, []);
});
Gets if the compiler node was forgotten.
This will be true when the compiler node was forgotten or removed.
Appends the specified whitespace to current node.