MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / extract_decorators_for

Method extract_decorators_for

codegraph-kernel/src/tsjs/extractors.rs:1143–1184  ·  view source on GitHub ↗
(&mut self, decl: Node<'t>, decorated_row: u32)

Source from the content-addressed store, hash-verified

1141 // --- extractDecoratorsFor --------------------------------------------------------------
1142
1143 pub(super) fn extract_decorators_for(&mut self, decl: Node<'t>, decorated_row: u32) {
1144 // 1. Direct children (method/property style).
1145 for i in 0..decl.named_child_count() {
1146 let Some(child) = decl.named_child(i) else { continue };
1147 self.consider_decorator(child, decorated_row);
1148 if child.kind() == "modifiers" {
1149 for j in 0..child.named_child_count() {
1150 if let Some(m) = child.named_child(j) {
1151 self.consider_decorator(m, decorated_row);
1152 }
1153 }
1154 }
1155 }
1156 // 2. Preceding siblings (TypeScript class style), stopping at the
1157 // first non-decorator so an earlier declaration's decorators never
1158 // leak in. Matching by startIndex, not object identity.
1159 let Some(parent) = decl.parent() else { return };
1160 let decl_start = decl.start_byte();
1161 let mut decl_idx: isize = -1;
1162 for i in 0..parent.named_child_count() {
1163 if let Some(sib) = parent.named_child(i) {
1164 if sib.start_byte() == decl_start {
1165 decl_idx = i as isize;
1166 break;
1167 }
1168 }
1169 }
1170 if decl_idx > 0 {
1171 let mut j = decl_idx - 1;
1172 while j >= 0 {
1173 let Some(sib) = parent.named_child(j as usize) else {
1174 j -= 1;
1175 continue;
1176 };
1177 if !matches!(sib.kind(), "decorator" | "annotation" | "marker_annotation") {
1178 break;
1179 }
1180 self.consider_decorator(sib, decorated_row);
1181 j -= 1;
1182 }
1183 }
1184 }
1185
1186 fn consider_decorator(&mut self, n: Node<'t>, decorated_row: u32) {
1187 if !matches!(n.kind(), "decorator" | "annotation" | "marker_annotation" | "attribute") {

Callers 4

extract_functionMethod · 0.45
extract_classMethod · 0.45
extract_methodMethod · 0.45
extract_propertyMethod · 0.45

Calls 1

consider_decoratorMethod · 0.45

Tested by

no test coverage detected