Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

fix(ingestion): filter HTML intrinsic elements from JSX component call targets (#1217)

Akshat malik8cb7fba3e27e
diff --git a/packages/core/src/repowise/core/ingestion/queries/javascript.scm b/packages/core/src/repowise/core/ingestion/queries/javascript.scm
index 1bb76a361..a531b0a1d 100644
--- a/packages/core/src/repowise/core/ingestion/queries/javascript.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/javascript.scm
@@ -173,12 +173,35 @@
; JSX element usage (treated as a call to the component)
; ---------------------------------------------------------------------------
-; <Component ... />
+; <Component ... /> — Capitalized React component
(jsx_self_closing_element
name: (identifier) @call.target
+ (#match? @call.target "^[A-Z]")
) @call.site
-; <Component ... > ... </Component>
+; <Component ... > ... </Component> — Capitalized React component
(jsx_opening_element
name: (identifier) @call.target
+ (#match? @call.target "^[A-Z]")
) @call.site
+
+; <Form.Item ... /> or <Form.Item> ... </Form.Item> — Member expression component
+; Casing filter prevents motion.div / styled.button from emitting fake edges.
+; @call.receiver captures the object (e.g. "Form") so Form.Item and Card.Item
+; resolve to distinct call sites via _extract_calls:851.
+(jsx_self_closing_element
+ name: (member_expression
+ object: (identifier) @call.receiver
+ property: (property_identifier) @call.target
+ )
+ (#match? @call.target "^[A-Z]")
+) @call.site
+
+(jsx_opening_element
+ name: (member_expression
+ object: (identifier) @call.receiver
+ property: (property_identifier) @call.target
+ )
+ (#match? @call.target "^[A-Z]")
+) @call.site
+
diff --git a/packages/core/src/repowise/core/ingestion/queries/tsx.scm b/packages/core/src/repowise/core/ingestion/queries/tsx.scm
index 6d869b334..6fa8f7985 100644
--- a/packages/core/src/repowise/core/ingestion/queries/tsx.scm
+++ b/packages/core/src/repowise/core/ingestion/queries/tsx.scm
@@ -10,12 +10,35 @@
; JSX element usage (treated as a call to the component)
; ---------------------------------------------------------------------------
-; <Component ... />
+; <Component ... /> — Capitalized React component
(jsx_self_closing_element
name: (identifier) @call.target
+ (#match? @call.target "^[A-Z]")
) @call.site
-; <Component ... > ... </Component>
+; <Component ... > ... </Component> — Capitalized React component
(jsx_opening_element
name: (identifier) @call.target
+ (#match? @call.target "^[A-Z]")
) @call.site
+
+; <Form.Item ... /> or <Form.Item> ... </Form.Item> — Member expression component
+; Casing filter prevents motion.div / styled.button from emitting fake edges.
+; @call.receiver captures the object (e.g. "Form") so Form.Item and Card.Item
+; resolve to distinct call sites via _extract_calls:851.
+(jsx_self_closing_element
+ name: (member_expression
+ object: (identifier) @call.receiver
+ property: (property_identifier) @call.target
+ )
+ (#match? @call.target "^[A-Z]")
+) @call.site
+
+(jsx_opening_element
+ name: (member_expression
+ object: (identifier) @call.receiver
+ property: (property_identifier) @call.target
+ )
+ (#match? @call.target "^[A-Z]")
+) @call.site
+
diff --git a/tests/unit/ingestion/parser/test_typescript.py b/tests/unit/ingestion/parser/test_typescript.py
index b1ce90408..83d796507 100644
--- a/tests/unit/ingestion/parser/test_typescript.py
+++ b/tests/unit/ingestion/parser/test_typescript.py
@@ -250,6 +250,10 @@ export function Card() {
targets = {c.target_name for c in result.calls}
assert "StatRow" in targets
assert "Section" in targets
+ # Intrinsic HTML tags must NOT be emitted as call targets
+ assert "div" not in targets
+ assert "span" not in targets
+ assert "h2" not in targets
def test_jsx_element_call_works_for_jsx_grammar(self, parser: ASTParser) -> None:
# Same behaviour for .jsx (plain JavaScript grammar already
@@ -267,6 +271,77 @@ export function Card() {
result = parser.parse_file(fi, src)
targets = {c.target_name for c in result.calls}
assert "StatRow" in targets
+ assert "span" not in targets
+
+ def test_jsx_html_intrinsic_elements_filtered_and_member_expressions_captured(
+ self, parser: ASTParser
+ ) -> None:
+ # Test .tsx, .jsx, and member-expression components (<Form.Item />).
+ src = b"""
+import { Form, Button } from 'antd';
+
+export function MyForm() {
+ return (
+ <div className="container">
+ <form>
+ <Form.Item label="Username">
+ <input type="text" />
+ </Form.Item>
+ <Button type="primary">Submit</Button>
+ </form>
+ </div>
+ );
+}
+"""
+ fi = _make_file_info("ui/src/form.tsx", "typescript")
+ result = parser.parse_file(fi, src)
+ targets = {c.target_name for c in result.calls}
+ receivers = {c.receiver_name for c in result.calls if c.receiver_name}
+ assert "Button" in targets
+ assert "Item" in targets
+ # @call.receiver must be captured so Form.Item and Card.Item are disambiguated
+ assert "Form" in receivers
+ assert "div" not in targets
+ assert "form" not in targets
+ assert "input" not in targets
+
+ def test_jsx_motion_and_styled_components_filtered(
+ self, parser: ASTParser
+ ) -> None:
+ # Regression: framer-motion / styled-components bring lowercase member
+ # expressions like <motion.div>, <motion.span>, <styled.button> which
+ # are HTML wrappers and must NOT be emitted as call targets.
+ # Only <motion.Foo> where Foo starts with A-Z should be captured.
+ src = b"""
+import { motion } from 'framer-motion';
+import styled from 'styled-components';
+import { Form } from 'antd';
+
+export function AnimatedCard() {
+ return (
+ <motion.div animate={{ opacity: 1 }}>
+ <motion.span>Label</motion.span>
+ <styled.button>Click</styled.button>
+ <Form.Item>
+ <motion.input />
+ </Form.Item>
+ </motion.div>
+ );
+}
+"""
+ fi = _make_file_info("ui/src/AnimatedCard.tsx", "typescript")
+ result = parser.parse_file(fi, src)
+ targets = {c.target_name for c in result.calls}
+ receivers = {c.receiver_name for c in result.calls if c.receiver_name}
+ # Capitalized member property (Form.Item) is a real component
+ assert "Item" in targets
+ assert "Form" in receivers
+ # Lowercase member properties are HTML wrappers — must be filtered
+ assert "div" not in targets # motion.div
+ assert "span" not in targets # motion.span
+ assert "button" not in targets # styled.button
+ assert "input" not in targets # motion.input
+
def test_class_methods_still_extracted(self, parser: ASTParser) -> None:
# Negative for D5: methods inside class bodies must still be