Skip to content
Open
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
8 changes: 4 additions & 4 deletions codeflash/languages/javascript/frameworks/react/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from __future__ import annotations

import logging
import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING
Expand All @@ -18,6 +19,8 @@
from codeflash.languages.javascript.frameworks.react.discovery import ReactComponentInfo
from codeflash.languages.javascript.treesitter import TreeSitterAnalyzer

_CONTEXT_RE = re.compile(r"\buseContext\s*\(\s*(\w+)")

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -167,10 +170,7 @@ def _extract_child_components(component_source: str, analyzer: TreeSitterAnalyze

def _extract_context_subscriptions(component_source: str) -> list[str]:
"""Find React context subscriptions via useContext calls."""
import re

context_re = re.compile(r"\buseContext\s*\(\s*(\w+)")
return [match.group(1) for match in context_re.finditer(component_source)]
return _CONTEXT_RE.findall(component_source)


def _find_type_definition(type_name: str, source: str, analyzer: TreeSitterAnalyzer) -> str | None:
Expand Down
Loading