dart-decimate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,252 @@
1
+ use tree_sitter::Node;
2
+
3
+ use super::{
4
+ DartCombinator, DartCombinatorKind, DartExport, DartImport, DartLibrary, DartPart, DartPartOf,
5
+ DartUriCondition, collect_direct_identifier_children, extract_uri, field_text,
6
+ find_first_named_descendant, first_named_child,
7
+ };
8
+
9
+ pub(super) fn extract_library_name(node: Node<'_>, source: &str) -> DartLibrary {
10
+ DartLibrary {
11
+ name: dotted_identifier_text(node, source),
12
+ augment_uri: node
13
+ .child_by_field_name("uri")
14
+ .and_then(|uri| extract_uri(uri, source)),
15
+ location: node.start_position().into(),
16
+ }
17
+ }
18
+
19
+ pub(super) fn extract_directive(
20
+ node: Node<'_>,
21
+ source: &str,
22
+ imports: &mut Vec<DartImport>,
23
+ exports: &mut Vec<DartExport>,
24
+ ) {
25
+ let Some(kind_node) = first_named_child(&node) else {
26
+ return;
27
+ };
28
+ let Some(uri_node) = directive_uri_node(kind_node) else {
29
+ return;
30
+ };
31
+ let uris = extract_directive_uris(uri_node, source);
32
+ if uris.is_empty() {
33
+ return;
34
+ }
35
+ let location = node.start_position().into();
36
+ let combinators = extract_combinators(kind_node, source);
37
+
38
+ match kind_node.kind() {
39
+ "library_import" => {
40
+ let import_specification =
41
+ find_first_named_descendant(kind_node, "import_specification");
42
+ let prefix = import_specification
43
+ .and_then(|specification| field_text(specification, "alias", source))
44
+ .filter(|prefix| prefix != "_");
45
+ let deferred = import_specification.is_some_and(|specification| {
46
+ import_uses_deferred_as(specification, uri_node, source)
47
+ });
48
+ imports.extend(uris.into_iter().map(|uri| DartImport {
49
+ uri: uri.uri,
50
+ condition: uri.condition,
51
+ prefix: prefix.clone(),
52
+ deferred,
53
+ combinators: combinators.clone(),
54
+ location,
55
+ }));
56
+ }
57
+ "library_export" => {
58
+ exports.extend(uris.into_iter().map(|uri| DartExport {
59
+ uri: uri.uri,
60
+ condition: uri.condition,
61
+ combinators: combinators.clone(),
62
+ location,
63
+ }));
64
+ }
65
+ _ => {}
66
+ }
67
+ }
68
+
69
+ pub(super) fn extract_part_directive(node: Node<'_>, source: &str, parts: &mut Vec<DartPart>) {
70
+ let Some(uri_node) = node.child_by_field_name("uri") else {
71
+ return;
72
+ };
73
+ let Some(uri) = extract_uri(uri_node, source) else {
74
+ return;
75
+ };
76
+
77
+ parts.push(DartPart {
78
+ uri,
79
+ location: node.start_position().into(),
80
+ });
81
+ }
82
+
83
+ pub(super) fn extract_part_of_directive(node: Node<'_>, source: &str) -> DartPartOf {
84
+ let uri = find_first_named_child(node, "uri").and_then(|uri| extract_uri(uri, source));
85
+ DartPartOf {
86
+ name: (uri.is_none())
87
+ .then(|| dotted_identifier_text(node, source))
88
+ .flatten(),
89
+ uri,
90
+ location: node.start_position().into(),
91
+ }
92
+ }
93
+
94
+ fn directive_uri_node(node: Node<'_>) -> Option<Node<'_>> {
95
+ match node.kind() {
96
+ "library_import" => {
97
+ let specification = find_first_named_descendant(node, "import_specification")?;
98
+ specification.child_by_field_name("uri")
99
+ }
100
+ "library_export" => node.child_by_field_name("uri"),
101
+ _ => None,
102
+ }
103
+ }
104
+
105
+ pub(super) fn import_uses_deferred_as(
106
+ specification: Node<'_>,
107
+ uri_node: Node<'_>,
108
+ _source: &str,
109
+ ) -> bool {
110
+ let mut saw_deferred = false;
111
+ let mut cursor = specification.walk();
112
+ for child in specification.children(&mut cursor) {
113
+ if child.end_byte() <= uri_node.end_byte() || child.kind() == "comment" {
114
+ continue;
115
+ }
116
+ match child.kind() {
117
+ "deferred" => saw_deferred = true,
118
+ "as" if saw_deferred => return true,
119
+ _ if !child.is_extra() => saw_deferred = false,
120
+ _ => {}
121
+ }
122
+ }
123
+ false
124
+ }
125
+
126
+ #[derive(Debug, Clone, PartialEq, Eq)]
127
+ struct ConfiguredUri {
128
+ uri: String,
129
+ condition: Option<DartUriCondition>,
130
+ }
131
+
132
+ fn extract_directive_uris(uri_node: Node<'_>, source: &str) -> Vec<ConfiguredUri> {
133
+ if uri_node.kind() == "uri" {
134
+ if let Some(uri) = extract_uri(uri_node, source) {
135
+ return vec![ConfiguredUri {
136
+ uri,
137
+ condition: None,
138
+ }];
139
+ }
140
+ return Vec::new();
141
+ }
142
+
143
+ if uri_node.kind() != "configurable_uri" {
144
+ return Vec::new();
145
+ }
146
+
147
+ let mut uris = Vec::new();
148
+ let mut cursor = uri_node.walk();
149
+ for child in uri_node.named_children(&mut cursor) {
150
+ match child.kind() {
151
+ "uri" => {
152
+ if let Some(uri) = extract_uri(child, source) {
153
+ uris.push(ConfiguredUri {
154
+ uri,
155
+ condition: None,
156
+ });
157
+ }
158
+ }
159
+ "configuration_uri" => {
160
+ if let Some(uri) = configured_branch_uri(child, source) {
161
+ uris.push(uri);
162
+ }
163
+ }
164
+ _ => {}
165
+ }
166
+ }
167
+ uris
168
+ }
169
+
170
+ fn configured_branch_uri(node: Node<'_>, source: &str) -> Option<ConfiguredUri> {
171
+ let mut condition = None;
172
+ let mut uri = None;
173
+ let mut cursor = node.walk();
174
+ for child in node.named_children(&mut cursor) {
175
+ match child.kind() {
176
+ "uri_test" => condition = uri_condition(child, source),
177
+ "uri" => uri = extract_uri(child, source),
178
+ _ => {}
179
+ }
180
+ }
181
+
182
+ Some(ConfiguredUri {
183
+ uri: uri?,
184
+ condition,
185
+ })
186
+ }
187
+
188
+ fn uri_condition(node: Node<'_>, source: &str) -> Option<DartUriCondition> {
189
+ let variable = dotted_identifier_text(node, source)?;
190
+ let expected_value = find_first_named_descendant(node, "string_literal")
191
+ .and_then(|literal| literal.utf8_text(source.as_bytes()).ok())
192
+ .and_then(super::strings::unquote_dart_string)
193
+ .unwrap_or_else(|| "true".to_owned());
194
+
195
+ Some(DartUriCondition {
196
+ variable,
197
+ expected_value,
198
+ location: node.start_position().into(),
199
+ })
200
+ }
201
+
202
+ fn extract_combinators(node: Node<'_>, source: &str) -> Vec<DartCombinator> {
203
+ let mut combinators = Vec::new();
204
+ collect_combinators(node, source, &mut combinators);
205
+ combinators
206
+ }
207
+
208
+ fn collect_combinators(node: Node<'_>, source: &str, combinators: &mut Vec<DartCombinator>) {
209
+ if node.kind() == "combinator" {
210
+ if let Some(combinator) = combinator_from_node(node, source) {
211
+ combinators.push(combinator);
212
+ }
213
+ return;
214
+ }
215
+
216
+ let mut cursor = node.walk();
217
+ for child in node.named_children(&mut cursor) {
218
+ collect_combinators(child, source, combinators);
219
+ }
220
+ }
221
+
222
+ fn combinator_from_node(node: Node<'_>, source: &str) -> Option<DartCombinator> {
223
+ let text = node.utf8_text(source.as_bytes()).ok()?;
224
+ let kind = if text.trim_start().starts_with("show") {
225
+ DartCombinatorKind::Show
226
+ } else if text.trim_start().starts_with("hide") {
227
+ DartCombinatorKind::Hide
228
+ } else {
229
+ return None;
230
+ };
231
+ let mut names = Vec::new();
232
+ collect_direct_identifier_children(node, source, &mut names);
233
+
234
+ Some(DartCombinator {
235
+ kind,
236
+ names,
237
+ location: node.start_position().into(),
238
+ })
239
+ }
240
+
241
+ fn dotted_identifier_text(node: Node<'_>, source: &str) -> Option<String> {
242
+ let dotted = find_first_named_child(node, "dotted_identifier_list")?;
243
+ let mut names = Vec::new();
244
+ collect_direct_identifier_children(dotted, source, &mut names);
245
+ (!names.is_empty()).then(|| names.join("."))
246
+ }
247
+
248
+ fn find_first_named_child<'tree>(node: Node<'tree>, kind: &str) -> Option<Node<'tree>> {
249
+ let mut cursor = node.walk();
250
+ node.named_children(&mut cursor)
251
+ .find(|child| child.kind() == kind)
252
+ }
@@ -0,0 +1,25 @@
1
+ use super::{extract_dart_file, extract_dart_source};
2
+
3
+ #[test]
4
+ fn reports_missing_files() {
5
+ let error = extract_dart_file("__dart_decimate_missing_file__.dart")
6
+ .err()
7
+ .map(|error| error.to_string());
8
+
9
+ assert!(matches!(
10
+ error.as_deref(),
11
+ Some(message) if message.contains("failed to read Dart file")
12
+ ));
13
+ }
14
+
15
+ #[test]
16
+ fn reports_syntax_errors() {
17
+ let error = extract_dart_source("lib/bad.dart", "class {")
18
+ .err()
19
+ .map(|error| error.to_string());
20
+
21
+ assert!(matches!(
22
+ error.as_deref(),
23
+ Some("Dart syntax errors found in lib/bad.dart")
24
+ ));
25
+ }
@@ -0,0 +1,210 @@
1
+ use tree_sitter::Node;
2
+
3
+ use super::{
4
+ MemberDeclaration, MemberKind, collect_direct_identifier_children, collect_named_fields,
5
+ field_text, find_first_named_descendant, find_first_named_descendant_in, first_identifier_text,
6
+ };
7
+
8
+ pub(super) fn push_class_like_members(
9
+ members: &mut Vec<MemberDeclaration>,
10
+ node: Node<'_>,
11
+ source: &str,
12
+ ) {
13
+ let Some(owner) = declaration_owner_name(node, source) else {
14
+ return;
15
+ };
16
+ let Some(body) = node.child_by_field_name("body") else {
17
+ return;
18
+ };
19
+ collect_class_like_members(members, &owner, body, source);
20
+ }
21
+
22
+ fn declaration_owner_name(node: Node<'_>, source: &str) -> Option<String> {
23
+ if node.kind() == "class_declaration" {
24
+ return field_text(node, "name", source).or_else(|| {
25
+ find_first_named_descendant(node, "mixin_application_class")
26
+ .and_then(|child| first_identifier_text(child, source))
27
+ });
28
+ }
29
+ node.child_by_field_name("name")
30
+ .and_then(|child| first_identifier_text(child, source))
31
+ .or_else(|| field_text(node, "name", source))
32
+ }
33
+
34
+ fn collect_class_like_members(
35
+ members: &mut Vec<MemberDeclaration>,
36
+ owner: &str,
37
+ body: Node<'_>,
38
+ source: &str,
39
+ ) {
40
+ let mut cursor = body.walk();
41
+ for child in body.named_children(&mut cursor) {
42
+ match child.kind() {
43
+ "enum_constant" => push_member(members, owner, MemberKind::EnumConstant, child, source),
44
+ "class_member" => push_class_member(members, owner, child, source),
45
+ _ => {}
46
+ }
47
+ }
48
+ }
49
+
50
+ fn push_class_member(
51
+ members: &mut Vec<MemberDeclaration>,
52
+ owner: &str,
53
+ node: Node<'_>,
54
+ source: &str,
55
+ ) {
56
+ let mut cursor = node.walk();
57
+ for child in node.named_children(&mut cursor) {
58
+ match child.kind() {
59
+ "declaration" => push_bodyless_member(members, owner, child, source),
60
+ "method_declaration" => push_method_member(members, owner, child, source),
61
+ _ => {}
62
+ }
63
+ }
64
+ }
65
+
66
+ fn push_bodyless_member(
67
+ members: &mut Vec<MemberDeclaration>,
68
+ owner: &str,
69
+ node: Node<'_>,
70
+ source: &str,
71
+ ) {
72
+ if let Some(kind) = member_signature_kind(node) {
73
+ push_signature_member(members, owner, kind, node, source);
74
+ return;
75
+ }
76
+
77
+ let mut names = Vec::new();
78
+ collect_member_field_names(node, source, &mut names);
79
+ members.extend(names.into_iter().map(|name| MemberDeclaration {
80
+ owner: owner.to_owned(),
81
+ kind: MemberKind::Field,
82
+ name,
83
+ location: node.start_position().into(),
84
+ }));
85
+ }
86
+
87
+ fn push_method_member(
88
+ members: &mut Vec<MemberDeclaration>,
89
+ owner: &str,
90
+ node: Node<'_>,
91
+ source: &str,
92
+ ) {
93
+ let Some(signature) = node.child_by_field_name("signature") else {
94
+ return;
95
+ };
96
+ let Some(kind) = member_signature_kind(signature) else {
97
+ return;
98
+ };
99
+ push_signature_member(members, owner, kind, signature, source);
100
+ }
101
+
102
+ fn member_signature_kind(node: Node<'_>) -> Option<MemberKind> {
103
+ find_first_named_descendant_in(node, SIGNATURE_KINDS).and_then(|signature| {
104
+ match signature.kind() {
105
+ "constant_constructor_signature"
106
+ | "constructor_signature"
107
+ | "factory_constructor_signature"
108
+ | "redirecting_factory_constructor_signature" => Some(MemberKind::Constructor),
109
+ "operator_signature" => Some(MemberKind::Operator),
110
+ "getter_signature" => Some(MemberKind::Getter),
111
+ "setter_signature" => Some(MemberKind::Setter),
112
+ "function_signature" => Some(MemberKind::Method),
113
+ _ => None,
114
+ }
115
+ })
116
+ }
117
+
118
+ fn push_signature_member(
119
+ members: &mut Vec<MemberDeclaration>,
120
+ owner: &str,
121
+ kind: MemberKind,
122
+ node: Node<'_>,
123
+ source: &str,
124
+ ) {
125
+ let Some(signature) = find_member_signature_node(node) else {
126
+ return;
127
+ };
128
+ let name = match kind {
129
+ MemberKind::Constructor => constructor_signature_name(signature, owner, source),
130
+ MemberKind::Operator => field_text(signature, "operator", source),
131
+ _ => field_text(signature, "name", source)
132
+ .map(|name| member_name_without_owner(&name, owner)),
133
+ };
134
+ if let Some(name) = name {
135
+ members.push(MemberDeclaration {
136
+ owner: owner.to_owned(),
137
+ kind,
138
+ name,
139
+ location: node.start_position().into(),
140
+ });
141
+ }
142
+ }
143
+
144
+ fn find_member_signature_node(node: Node<'_>) -> Option<Node<'_>> {
145
+ if SIGNATURE_KINDS.contains(&node.kind()) {
146
+ return Some(node);
147
+ }
148
+ find_first_named_descendant_in(node, SIGNATURE_KINDS)
149
+ }
150
+
151
+ fn constructor_signature_name(signature: Node<'_>, owner: &str, source: &str) -> Option<String> {
152
+ let mut cursor = signature.walk();
153
+ let mut parts = signature
154
+ .children_by_field_name("name", &mut cursor)
155
+ .filter(|child| matches!(child.kind(), "identifier" | "new"))
156
+ .filter_map(|child| child.utf8_text(source.as_bytes()).ok())
157
+ .map(str::to_owned);
158
+ let first = parts.next()?;
159
+ let name = parts.last().unwrap_or(first);
160
+ Some(member_name_without_owner(&name, owner))
161
+ }
162
+
163
+ const SIGNATURE_KINDS: &[&str] = &[
164
+ "constant_constructor_signature",
165
+ "constructor_signature",
166
+ "factory_constructor_signature",
167
+ "redirecting_factory_constructor_signature",
168
+ "operator_signature",
169
+ "getter_signature",
170
+ "setter_signature",
171
+ "function_signature",
172
+ ];
173
+
174
+ fn push_member(
175
+ members: &mut Vec<MemberDeclaration>,
176
+ owner: &str,
177
+ kind: MemberKind,
178
+ node: Node<'_>,
179
+ source: &str,
180
+ ) {
181
+ if let Some(name) = field_text(node, "name", source) {
182
+ members.push(MemberDeclaration {
183
+ owner: owner.to_owned(),
184
+ kind,
185
+ name,
186
+ location: node.start_position().into(),
187
+ });
188
+ }
189
+ }
190
+
191
+ fn collect_member_field_names(node: Node<'_>, source: &str, names: &mut Vec<String>) {
192
+ collect_named_fields(
193
+ node,
194
+ source,
195
+ &["static_final_declaration", "initialized_identifier"],
196
+ names,
197
+ );
198
+ if names.is_empty()
199
+ && let Some(identifier_list) = find_first_named_descendant(node, "identifier_list")
200
+ {
201
+ collect_direct_identifier_children(identifier_list, source, names);
202
+ }
203
+ }
204
+
205
+ fn member_name_without_owner(name: &str, owner: &str) -> String {
206
+ name.strip_prefix(owner)
207
+ .and_then(|rest| rest.strip_prefix('.'))
208
+ .unwrap_or(name)
209
+ .to_owned()
210
+ }