TSExport
Represents a single exported symbol. There is a 1:M relationship between an ExportStatement and an Export
Inherits from
HasValue, Export, Editable, Exportable, Usable, Importable, Expression, HasName
Properties
declared_symbol
Returns the symbol that was defined in this export.
Returns the symbol that was directly declared within this export statement. For class, function, interface, type alias, enum declarations or assignments, returns the declared symbol. For re-exports or exports without declarations, returns None.
Returns: Union[TSSymbol, TSImport, None]: The symbol declared within this export statement, or None if no symbol was declared.
dependencies
Returns a list of symbols that this symbol depends on.
Returns a list of symbols (including imports) that this symbol directly depends on. The returned list is sorted by file location for consistent ordering.
Returns: list[Union[Symbol, Import]]: A list of symbols and imports that this symbol directly depends on, sorted by file location.
descendant_symbols
Returns a list of all descendant symbols from this export’s declared symbol.
Returns all child symbols that are contained within the declared symbol of this export. For example, if the declared symbol is a class, this will return all methods, properties and nested classes. If the export has no declared symbol, returns an empty list.
Returns: list[Importable]: List of descendant symbols. Empty list if no declared symbol exists.
export
Returns the export object that exports this symbol.
Retrieves the export object by examining incoming EXPORT edges in the CodebaseGraph.
Args: None
Returns: Export | None: The Export object that exports this symbol, or None if not exported.
exported_name
Retrieves the exported name of a symbol from its file.
If the symbol is an export node, returns the node’s name. If the symbol is not exported, returns None.
Returns: str | None: The name the symbol is exported as, or None if not exported.
exported_symbol
Returns the symbol, file, or import being exported from this export object.
Retrieves the symbol or module being exported by this export node by finding the node connected via an EXPORT edge. This method is the inverse of Import.imported_symbol.
Args: None
Returns: Exportable | None: The exported symbol, file, or import, or None if no symbol is exported.
extended
Returns a SymbolGroup of all extended nodes associated with this element.
Creates a SymbolGroup that provides a common interface for editing all extended nodes, such as decorators, modifiers, and comments associated with the element.
Args: None
Returns: SymbolGroup: A group containing this node and its extended nodes that allows batch modification through a common interface.
extended_source
Returns the source text representation of all extended nodes.
Gets the source text of all extended nodes combined. This property allows reading the source text of all extended nodes (e.g. decorators, export statements) associated with this node.
Returns: str: The combined source text of all extended nodes.
file
The file object that this Editable instance belongs to.
Retrieves or caches the file object associated with this Editable instance.
Returns: File: The File object containing this Editable instance.
filepath
The file path of the file that this Editable instance belongs to.
Returns a string representing the absolute file path of the File that contains this Editable instance.
Returns: str: The absolute file path.
full_name
Returns the full name of the object, including the namespace path.
For class methods, this returns the parent class’s full name followed by the method name. For chained attributes (e.g., ‘a.b’), this returns the full chained name.
Returns: str | None: The complete qualified name of the object. Returns None if no name is available.
function_calls
Returns a list of all function calls contained within this expression.
Traverses the extended nodes of this expression to find all function calls within it. This is useful for tasks like analyzing call patterns or renaming function invocations.
Returns: list[FunctionCall]: A list of FunctionCall objects representing all function calls contained within this expression.
is_exported
Indicates if the symbol is exported from its defining file.
Returns: bool: True if the symbol has an export object, False otherwise.
is_external_export
Determines if this export is exporting a symbol from an external (non-relative) module.
An external module is one that comes from outside the project’s codebase.
Returns: bool: True if the export is from an external module, False otherwise.
is_reexported
Determines if the symbol is re-exported from a different file.
A re-export occurs when a symbol is imported into a file and then exported from that same file.
Returns: bool: True if the symbol is re-exported from a different file than where it was defined, False otherwise.
name
Retrieves the base name of the object without namespace prefixes.
Returns: str | None: The base name of the object, or None if no name node is associated.
parent_class
Find the class this node is contained in
parent_function
Find the function this node is contained in
parent_statement
Find the statement this node is contained in
resolved_symbol
Returns the Symbol, SourceFile or External module that this export resolves to.
Recursively traverses through indirect imports and exports to find the final resolved symbol. This is useful for determining what symbol an export ultimately points to, particularly in cases of re-exports and import-export chains.
Returns: Exportable | None: The final resolved Symbol, SourceFile or External module, or None if the resolution fails. The resolution follows this chain:
- If the symbol is an Import, resolves to its imported symbol
- If the symbol is an Export, resolves to its exported symbol
- Otherwise returns the symbol itself
Note: Handles circular references by tracking visited symbols to prevent infinite loops.
resolved_value
Returns the resolved type of an Expression.
Returns the inferred type of the expression. For example, a function call’s resolved value will be its definition.
Returns: Expression | list[Expression]: The resolved expression type(s). Returns a single Expression if there is only one resolved type, or a list of Expressions if there are multiple resolved types. Returns self if the expression is not resolvable or has no resolved types.
source
Returns the source code of the symbol.
Gets the source code of the symbol from its extended representation, which includes the export statement.
Returns: str: The complete source code of the symbol including any extended nodes.
value
Gets the value node of the object.
Returns: Expression | None: The value node of the object. None if no value is set.
variable_usages
Returns Editables for all TreeSitter node instances of variable usages within this node’s scope.
This method finds all variable identifier nodes in the TreeSitter AST, excluding:
- Function names in function calls
- Import names in import statements
- Property access identifiers (except the base object)
- Keyword argument names (in Python and TypeScript)
This is useful for variable renaming and usage analysis within a scope.
Returns: list[Editable]: A list of Editable nodes representing variable usages. Each Editable corresponds to a TreeSitter node instance where the variable is referenced.
Methods
ancestors
Find all ancestors of the node of the given type. Does not return itself
edit
Replace the source of this Editable
with new_src
.
Replaces the text representation of this Editable instance with new text content. The method handles indentation adjustments and transaction management.
Args:
new_src (str): The new source text to replace the current text with.
fix_indentation (bool): If True, adjusts the indentation of new_src
to match the current text’s indentation level. Defaults to False.
priority (int): The priority of the edit transaction. Higher priority edits are applied first. Defaults to 0.
dedupe (bool): If True, deduplicates identical transactions. Defaults to True.
Returns: None
find
Find and return matching nodes or substrings within an Editable instance.
This method searches through the extended_nodes of the Editable instance and returns all nodes or substrings that match the given search criteria.
Args: strings_to_match (Union[list[str], str]): One or more strings to search for. exact (bool): If True, only return nodes whose source exactly matches one of the strings_to_match. If False, return nodes that contain any of the strings_to_match as substrings. Defaults to False.
Returns: list[Editable]: A list of Editable instances that match the search criteria.
find_string_literals
Returns a list of string literals within this node’s source that match any of the given strings.
Args: strings_to_match (list[str]): A list of strings to search for in string literals. fuzzy_match (bool): If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False.
Returns: list[Editable]: A list of Editable objects representing the matching string literals.
flag
Adds a visual flag comment to the end of this Editable’s source text.
Flags this Editable by appending a comment with emoji flags at the end of its source text. This is useful for visually highlighting specific nodes in the source code during development and debugging.
Returns: None
get_import_string
Returns the import string for this export.
Args: alias (str | None): Optional alias to use when importing the symbol. module (str | None): Optional module name to import from. import_type (ImportType): The type of import to generate. is_type_import (bool): Whether this is a type-only import.
Returns: str: The formatted import string.
get_name
Returns the name node of the object.
Args: None
Returns: Name | ChainedAttribute | None: The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name.
get_variable_usages
Returns Editables for all TreeSitter nodes corresponding to instances of variable usage that matches the given variable name.
Retrieves a list of variable usages that match a specified name, with an option for fuzzy matching. By default, excludes property identifiers and argument keywords.
Args: var_name (str): The variable name to search for. fuzzy_match (bool): If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False.
Returns: list[Editable]: List of Editable objects representing variable usage nodes matching the given name.
insert_after
Inserts code after this node.
Args: new_src (str): The source code to insert after this node. fix_indentation (bool, optional): Whether to adjust the indentation of new_src to match the current node. Defaults to False. newline (bool, optional): Whether to add a newline before the new_src. Defaults to True. priority (int, optional): Priority of the insertion transaction. Defaults to 0. dedupe (bool, optional): Whether to deduplicate identical transactions. Defaults to True.
Returns: None
insert_before
Inserts text before this node’s source with optional indentation and newline handling.
This method inserts the provided text before the current node’s source code. It can automatically handle indentation and newline placement.
Args: new_src (str): The text to insert before this node. fix_indentation (bool): Whether to fix the indentation of new_src to match the current node. Defaults to False. newline (bool): Whether to add a newline after new_src. Defaults to True. priority (int): Transaction priority for managing multiple edits. Defaults to 0. dedupe (bool): Whether to deduplicate identical transactions. Defaults to True.
Returns: None
is_aliased
Determines if the Export object is aliased.
Checks if the exported symbol has a different name than the name it is exported as.
Returns: bool: True if the exported symbol has a different name than the name it is exported as, False otherwise.
is_default_export
Determines if an export is the default export for a file.
This function checks if the export is a default export by examining the export source code and the export’s symbol. It handles various cases of default exports including:
- Re-exports as default (
export { foo as default }
) - Default exports (
export default foo
) - Module exports (
export = foo
)
Returns: bool: True if this is a default export, False otherwise.
is_default_symbol_export
Returns True if this is exporting a default symbol, as opposed to a default object export.
This method checks if an export is a default symbol export (e.g. ‘export default foo’) rather than a default object export (e.g. ‘export default ’). It handles both direct exports and re-exports.
Args: self (TSExport): The export object being checked.
Returns: bool: True if this is a default symbol export, False otherwise.
is_module_export
Determines if the export is exporting a module rather than a symbol.
Returns True if the export is a wildcard export (e.g. ‘export *’) or if it is a default export but not of a symbol (e.g. ‘export default ’).
Returns: bool: True if the export represents a module export, False otherwise.
is_named_export
Determines whether this export is a named export.
Named exports are exports that are not default exports. For example, export const foo = 'bar'
is a named export,
while export default foo
is not.
Returns: bool: True if this is a named export, False if it is a default export.
is_reexport
Returns whether the export is re-exporting an import or export.
Checks if this export node is re-exporting a symbol that was originally imported from another module or exported from another location. This includes wildcard re-exports of entire modules.
Args: self (TSExport): The export node being checked.
Returns: bool: True if this export re-exports an imported/exported symbol or entire module, False otherwise.
is_type_export
Determines if this export is exclusively exporting a type.
Checks if this export starts with “export type” to identify if it’s only exporting a type definition. This method is used to distinguish between value exports and type exports in TypeScript.
Returns: bool: True if this is a type-only export, False otherwise.
is_wildcard_export
Determines if the export is a wildcard export.
Checks if the export statement contains a wildcard export pattern ‘export *’ or ‘export *;’. A wildcard export exports all symbols from a module.
Returns: bool: True if the export is a wildcard export (e.g. ‘export * from ”./module”’), False otherwise.
is_wrapped_in
Check if this node is contained another node of the given class
make_non_default
Converts the export to a named export.
Transforms default exports into named exports by modifying the export syntax and updating any corresponding export/import usages. For default exports, it removes the ‘default’ keyword and adjusts all import statements that reference this export.
Args: None
Returns: None
parent_of_type
Find the first ancestor of the node of the given type. Does not return itself
reduce_condition
Reduces an editable to the following condition
reexport_symbol
Returns the import object that is re-exporting this symbol.
For re-exports like:
export { foo } from './bar'
# Direct re-exportexport { default as baz } from './bar'
# Direct default re-exportexport * from './bar'
# Direct wildcard re-exportimport { foo } from './bar'; export { foo }
# Local re-export
This returns the corresponding import object that’s being re-exported.
Returns: TSImport | None: The import object being re-exported, or None if this is not a re-export or no import was found.
remove
Deletes this Node and its related extended nodes (e.g. decorators, comments).
Removes the current node and its extended nodes (e.g. decorators, comments) from the codebase. After removing the node, it handles cleanup of any surrounding formatting based on the context.
Args: delete_formatting (bool): Whether to delete surrounding whitespace and formatting. Defaults to True. priority (int): Priority of the removal transaction. Higher priority transactions are executed first. Defaults to 0. dedupe (bool): Whether to deduplicate removal transactions at the same location. Defaults to True.
Returns: None
rename
Renames a symbol and updates all its references in the codebase.
Args: new_name (str): The new name for the symbol. priority (int): Priority of the edit operation. Defaults to 0.
Returns: tuple[NodeId, NodeId]: A tuple containing the file node ID and the new node ID of the renamed symbol.
replace
Search and replace occurrences of text within this node’s source and its extended nodes.
This method performs string replacement similar to Python’s string.replace(), with support for regex patterns. It operates on both the main node and any extended nodes (e.g. decorators, exports).
Args: old (str): The text or pattern to search for. new (str): The text to replace matches with. count (int, optional): Maximum number of replacements to make. Defaults to -1 (replace all). is_regex (bool, optional): Whether to treat ‘old’ as a regex pattern. Defaults to False. priority (int, optional): Priority of the replacement operation. Defaults to 0.
Returns: int: The total number of replacements made.
Raises: ValueError: If there are multiple occurrences of the substring in a node’s source.
search
Returns a list of all regex match of regex_pattern
, similar to python’s re.search().
Searches for matches of a regular expression pattern within the text of this node and its extended nodes.
Args: regex_pattern (str): The regular expression pattern to search for. include_strings (bool): When False, excludes the contents of string literals from the search. Defaults to True. include_comments (bool): When False, excludes the contents of comments from the search. Defaults to True.
Returns: list[Editable]: A list of Editable objects corresponding to the matches found.
set_name
Sets the name of a code element.
Modifies the name of the object’s underlying name node. Works with both simple names and chained attributes (e.g., ‘a.b’).
Args: name (str): The new name to set for the object.
Returns: None
set_value
Sets the value of the node’s value Expression.
Updates the value of the underlying Expression node if it exists. No action is taken if the value node is None.
Args: value (str): The new value to set.
Returns: None
symbol_usages
Returns a list of symbols that use or import the exportable object.
Args: usage_types (UsageType | None): The types of usages to search for. Defaults to any.
Returns: list[Import | Symbol | Export]: A list of symbols that use or import the exportable object.
Note: This method can be called as both a property or a method. If used as a property, it is equivalent to invoking it without arguments.
to_import_string
Converts this export into its equivalent import string representation.
This is primarily used for handling re-exports, converting them into their equivalent import statements.
Returns: str: The import string representation of this export.
Examples:
- For
export { foo } from './bar'
->import { foo } from './bar'
- For
export * from './bar'
->import * as _namespace from './bar'
- For
export { default as foo } from './bar'
->import foo from './bar'
usages
Returns a list of usages of the exportable object.
Retrieves all locations where the exportable object is used in the codebase. By default, returns all usages, such as imports or references within the same file.
Args: usage_types (UsageType | None): Specifies which types of usages to include in the results. Default is any usages.
Returns: list[Usage]: A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse.
Raises: ValueError: If no usage types are specified or if only ALIASED and DIRECT types are specified together.
Note: This method can be called as both a property or a method. If used as a property, it is equivalent to invoking it without arguments.
Was this page helpful?