Navegador

navegador / navegador / enrichment / react_native.py
Source Blame History 101 lines
96b97a1… lmata 1 """
96b97a1… lmata 2 React Native framework enricher.
96b97a1… lmata 3
96b97a1… lmata 4 Promotes generic Function/Class nodes to semantic React Native types:
96b97a1… lmata 5 - Component — JSX/TSX files (same heuristic as React web)
96b97a1… lmata 6 - Screen — files under screens/ directory or names ending in "Screen"
96b97a1… lmata 7 - Hook — functions whose name starts with "use"
96b97a1… lmata 8 - Navigation — createStackNavigator / createBottomTabNavigator / NavigationContainer etc.
96b97a1… lmata 9 """
96b97a1… lmata 10
96b97a1… lmata 11 from navegador.enrichment.base import EnrichmentResult, FrameworkEnricher
96b97a1… lmata 12
96b97a1… lmata 13 _NAVIGATION_PATTERNS = (
96b97a1… lmata 14 "createStackNavigator",
96b97a1… lmata 15 "createBottomTabNavigator",
96b97a1… lmata 16 "createDrawerNavigator",
96b97a1… lmata 17 "createNativeStackNavigator",
96b97a1… lmata 18 "NavigationContainer",
96b97a1… lmata 19 "useNavigation",
96b97a1… lmata 20 "useRoute",
96b97a1… lmata 21 )
96b97a1… lmata 22
96b97a1… lmata 23
96b97a1… lmata 24 class ReactNativeEnricher(FrameworkEnricher):
96b97a1… lmata 25 """Enricher for React Native and Expo codebases."""
96b97a1… lmata 26
96b97a1… lmata 27 @property
96b97a1… lmata 28 def framework_name(self) -> str:
96b97a1… lmata 29 return "react-native"
96b97a1… lmata 30
96b97a1… lmata 31 @property
96b97a1… lmata 32 def detection_patterns(self) -> list[str]:
2c266d2… lmata 33 return ["react-native", "expo"]
2c266d2… lmata 34
2c266d2… lmata 35 @property
2c266d2… lmata 36 def detection_files(self) -> list[str]:
2c266d2… lmata 37 return ["app.json"]
96b97a1… lmata 38
96b97a1… lmata 39 def enrich(self) -> EnrichmentResult:
96b97a1… lmata 40 result = EnrichmentResult()
96b97a1… lmata 41
96b97a1… lmata 42 # ── Components: functions/classes in .jsx or .tsx files ──────────────
e5e1a3b… lmata 43 component_rows = (
e5e1a3b… lmata 44 self.store.query(
e5e1a3b… lmata 45 "MATCH (n) WHERE (n.file_path CONTAINS '.jsx' OR n.file_path CONTAINS '.tsx') "
e5e1a3b… lmata 46 "AND n.name IS NOT NULL "
e5e1a3b… lmata 47 "RETURN n.name, n.file_path",
e5e1a3b… lmata 48 ).result_set
e5e1a3b… lmata 49 or []
e5e1a3b… lmata 50 )
96b97a1… lmata 51 for name, file_path in component_rows:
96b97a1… lmata 52 self._promote_node(name, file_path, "RNComponent")
96b97a1… lmata 53 result.promoted += 1
96b97a1… lmata 54 result.patterns_found["components"] = len(component_rows)
96b97a1… lmata 55
96b97a1… lmata 56 # ── Screens: nodes under screens/ or whose names end with "Screen" ───
e5e1a3b… lmata 57 screen_rows = (
e5e1a3b… lmata 58 self.store.query(
e5e1a3b… lmata 59 "MATCH (n) WHERE (n.file_path CONTAINS '/screens/' "
e5e1a3b… lmata 60 "OR (n.name IS NOT NULL AND n.name ENDS WITH 'Screen')) "
e5e1a3b… lmata 61 "AND n.name IS NOT NULL "
e5e1a3b… lmata 62 "RETURN n.name, n.file_path",
e5e1a3b… lmata 63 ).result_set
e5e1a3b… lmata 64 or []
e5e1a3b… lmata 65 )
96b97a1… lmata 66 for name, file_path in screen_rows:
96b97a1… lmata 67 self._promote_node(name, file_path, "RNScreen")
96b97a1… lmata 68 result.promoted += 1
96b97a1… lmata 69 result.patterns_found["screens"] = len(screen_rows)
96b97a1… lmata 70
96b97a1… lmata 71 # ── Hooks: functions whose name starts with "use" ─────────────────────
e5e1a3b… lmata 72 hook_rows = (
e5e1a3b… lmata 73 self.store.query(
e5e1a3b… lmata 74 "MATCH (n) WHERE n.name STARTS WITH 'use' "
e5e1a3b… lmata 75 "AND n.name <> 'use' "
e5e1a3b… lmata 76 "AND n.file_path IS NOT NULL "
e5e1a3b… lmata 77 "RETURN n.name, n.file_path",
e5e1a3b… lmata 78 ).result_set
e5e1a3b… lmata 79 or []
e5e1a3b… lmata 80 )
96b97a1… lmata 81 for name, file_path in hook_rows:
96b97a1… lmata 82 self._promote_node(name, file_path, "RNHook")
96b97a1… lmata 83 result.promoted += 1
96b97a1… lmata 84 result.patterns_found["hooks"] = len(hook_rows)
96b97a1… lmata 85
96b97a1… lmata 86 # ── Navigation: navigator factory / container patterns ────────────────
e5e1a3b… lmata 87 nav_conditions = " OR ".join(f"n.name CONTAINS '{pat}'" for pat in _NAVIGATION_PATTERNS)
e5e1a3b… lmata 88 nav_rows = (
e5e1a3b… lmata 89 self.store.query(
e5e1a3b… lmata 90 f"MATCH (n) WHERE ({nav_conditions}) "
e5e1a3b… lmata 91 "AND n.file_path IS NOT NULL "
e5e1a3b… lmata 92 "RETURN n.name, n.file_path",
e5e1a3b… lmata 93 ).result_set
e5e1a3b… lmata 94 or []
e5e1a3b… lmata 95 )
96b97a1… lmata 96 for name, file_path in nav_rows:
96b97a1… lmata 97 self._promote_node(name, file_path, "RNNavigation")
96b97a1… lmata 98 result.promoted += 1
96b97a1… lmata 99 result.patterns_found["navigation"] = len(nav_rows)
96b97a1… lmata 100
96b97a1… lmata 101 return result

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button