Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions codeflash/languages/javascript/treesitter_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ def __init__(self, language: TreeSitterLanguage | str) -> None:

# Cache for function type sets keyed by (include_methods, include_arrow_functions)
self._function_types_cache: dict[tuple[bool, bool], set[str]] = {}
# Cache for exports to avoid repeated parsing
self._exports_cache: dict[str, list[ExportInfo]] = {}

@property
def parser(self) -> Parser:
Expand Down Expand Up @@ -691,12 +693,16 @@ def find_exports(self, source: str) -> list[ExportInfo]:
List of ExportInfo objects describing exports.

"""
if source in self._exports_cache:
return self._exports_cache[source]

source_bytes = source.encode("utf8")
tree = self.parse(source_bytes)
exports: list[ExportInfo] = []

self._walk_tree_for_exports(tree.root_node, source_bytes, exports)

self._exports_cache[source] = exports
return exports

def _walk_tree_for_exports(self, node: Node, source_bytes: bytes, exports: list[ExportInfo]) -> None:
Expand Down
Loading