MCPcopy
hub / github.com/tirth8205/code-review-graph / _parse_vue

Method _parse_vue

code_review_graph/parser.py:1047–1156  ·  view source on GitHub ↗

Parse a Vue SFC by extracting blocks and delegating to JS/TS.

(
        self, path: Path, source: bytes,
    )

Source from the content-addressed store, hash-verified

1045 return nodes, edges
1046
1047 def _parse_vue(
1048 self, path: Path, source: bytes,
1049 ) -> tuple[list[NodeInfo], list[EdgeInfo]]:
1050 """Parse a Vue SFC by extracting <script> blocks and delegating to JS/TS."""
1051 vue_parser = self._get_parser("vue")
1052 if not vue_parser:
1053 return [], []
1054
1055 tree = vue_parser.parse(source)
1056 file_path_str = str(path)
1057 test_file = _is_test_file(file_path_str)
1058
1059 all_nodes: list[NodeInfo] = [NodeInfo(
1060 kind="File",
1061 name=file_path_str,
1062 file_path=file_path_str,
1063 line_start=1,
1064 line_end=source.count(b"\n") + 1,
1065 language="vue",
1066 is_test=test_file,
1067 )]
1068 all_edges: list[EdgeInfo] = []
1069
1070 # Find script_element blocks in the Vue AST
1071 for child in tree.root_node.children:
1072 if child.type != "script_element":
1073 continue
1074
1075 # Detect language from lang="ts" attribute
1076 script_lang = "javascript"
1077 start_tag = None
1078 raw_text_node = None
1079 for sub in child.children:
1080 if sub.type == "start_tag":
1081 start_tag = sub
1082 elif sub.type == "raw_text":
1083 raw_text_node = sub
1084
1085 if start_tag:
1086 for attr in start_tag.children:
1087 if attr.type == "attribute":
1088 attr_name = None
1089 attr_value = None
1090 for a in attr.children:
1091 if a.type == "attribute_name":
1092 attr_name = a.text.decode("utf-8", errors="replace")
1093 elif a.type == "quoted_attribute_value":
1094 for v in a.children:
1095 if v.type == "attribute_value":
1096 attr_value = v.text.decode(
1097 "utf-8", errors="replace",
1098 )
1099 if attr_name == "lang" and attr_value in ("ts", "typescript"):
1100 script_lang = "typescript"
1101
1102 if not raw_text_node:
1103 continue
1104

Callers 1

parse_bytesMethod · 0.95

Calls 8

_get_parserMethod · 0.95
_collect_file_scopeMethod · 0.95
_extract_from_treeMethod · 0.95
_qualifyMethod · 0.95
NodeInfoClass · 0.85
EdgeInfoClass · 0.85
countMethod · 0.80
_is_test_fileFunction · 0.70

Tested by

no test coverage detected