dart-decimate 0.0.12 → 0.0.14

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 (41) hide show
  1. package/Cargo.lock +75 -1
  2. package/Cargo.toml +2 -1
  3. package/README.md +31 -27
  4. package/npm/scripts/postinstall.js +33 -12
  5. package/npm/scripts/test-npx-local.js +7 -2
  6. package/npm/scripts/test-npx-mcp-local.js +3 -1
  7. package/npm/scripts/test-npx-prebuilt.js +33 -13
  8. package/npm/scripts/test-postinstall-prebuilt.js +33 -13
  9. package/package.json +11 -1
  10. package/src/changed_scope.rs +4 -7
  11. package/src/cli/audit_run.rs +1 -3
  12. package/src/cli/decision_surface_run.rs +1 -3
  13. package/src/cli/entry_points.rs +75 -13
  14. package/src/dart_parser.rs +1 -3
  15. package/src/dependencies/codegen.rs +26 -0
  16. package/src/dependencies.rs +1 -0
  17. package/src/dependency_scripts.rs +42 -8
  18. package/src/extract.rs +6 -0
  19. package/src/git_command.rs +58 -0
  20. package/src/graph.rs +5 -0
  21. package/src/lib.rs +1 -0
  22. package/src/manifest.rs +1 -1
  23. package/src/output/graph_findings.rs +117 -43
  24. package/src/output/route_cycle/classification.rs +862 -0
  25. package/src/output/route_cycle/navigation.rs +6 -1
  26. package/src/output/route_cycle/registry_api.rs +268 -0
  27. package/src/output/route_cycle.rs +28 -162
  28. package/src/output/types.rs +3 -3
  29. package/src/output.rs +2 -2
  30. package/src/scan/tests.rs +133 -0
  31. package/src/scan.rs +122 -47
  32. package/src/security/detect.rs +1275 -10
  33. package/src/security_gate.rs +3 -5
  34. package/src/trace.rs +22 -13
  35. package/src/widgets/inheritance.rs +250 -0
  36. package/src/widgets/params.rs +81 -1
  37. package/src/widgets/patterns.rs +32 -25
  38. package/src/widgets/reads.rs +61 -11
  39. package/src/widgets/resolution.rs +281 -0
  40. package/src/widgets/unrendered.rs +111 -47
  41. package/src/widgets.rs +69 -11
@@ -1,7 +1,11 @@
1
+ use std::collections::BTreeSet;
1
2
  use std::path::Path;
2
3
 
4
+ use tree_sitter::Node;
5
+
3
6
  use super::{DetectedSecurityCandidate, SecurityCategory, SecurityConfidence, SecurityOccurrence};
4
7
  use crate::Location;
8
+ use crate::dart_parser::parse_dart_source_lossy;
5
9
  use crate::generated::{is_flutterfire_options_path, is_generated_dart_path};
6
10
 
7
11
  pub(super) fn detect_in_source(path: &Path, source: &str) -> Vec<DetectedSecurityCandidate> {
@@ -48,7 +52,13 @@ fn detect_hardcoded_secrets(
48
52
  ));
49
53
  continue;
50
54
  }
51
- if is_placeholder(&literal.value) {
55
+ if oauth_endpoint_metadata_context(source, literal.index, &literal.value) {
56
+ continue;
57
+ }
58
+ let stripe_secret = stripe_secret_prefix(&literal.value)
59
+ || stripe_secret_name(&literal.value)
60
+ || stripe_secret_binding_context(source, literal.index);
61
+ if is_placeholder(&literal.value) && !stripe_secret {
52
62
  continue;
53
63
  }
54
64
  let line = line_at(source, literal.index);
@@ -64,6 +74,22 @@ fn detect_hardcoded_secrets(
64
74
  } else {
65
75
  literal_secret_binding_context(source, literal.index)
66
76
  };
77
+ if stripe_secret && !is_module_uri_directive_line(line) {
78
+ candidates.push(detected(
79
+ path,
80
+ source,
81
+ literal.index,
82
+ SecurityCategory::HardcodedSecret,
83
+ "secret-literal",
84
+ if secret_value {
85
+ SecurityConfidence::High
86
+ } else {
87
+ SecurityConfidence::Medium
88
+ },
89
+ "stripe-secret-signal",
90
+ ));
91
+ continue;
92
+ }
67
93
  if is_module_uri_directive_line(line)
68
94
  || firebase_api_key_context(source, literal.index)
69
95
  || (!secret_value && benign_secret_named_literal(&literal.value, secret_binding_name))
@@ -131,7 +157,9 @@ fn detect_insecure_transport(
131
157
  continue;
132
158
  }
133
159
  let line = line_at(source, literal.index);
134
- if has_network_context(line) {
160
+ if has_network_context(line)
161
+ || oauth_endpoint_url_context(source, literal.index, &literal.value)
162
+ {
135
163
  candidates.push(detected(
136
164
  path,
137
165
  source,
@@ -218,6 +246,19 @@ fn detect_process_execution(
218
246
  source: &str,
219
247
  candidates: &mut Vec<DetectedSecurityCandidate>,
220
248
  ) {
249
+ let parsed = [
250
+ "Process.run(",
251
+ "Process.start(",
252
+ "processManager.run(",
253
+ "processManager.start(",
254
+ ]
255
+ .iter()
256
+ .any(|pattern| source.contains(pattern))
257
+ .then(|| parse_dart_source_lossy(path, source))
258
+ .and_then(Result::ok);
259
+ let syntax = parsed
260
+ .as_ref()
261
+ .map(|parsed| (parsed.tree().root_node(), parsed.source()));
221
262
  for pattern in [
222
263
  "Process.run(",
223
264
  "Process.start(",
@@ -225,11 +266,23 @@ fn detect_process_execution(
225
266
  "processManager.start(",
226
267
  ] {
227
268
  for index in match_indices(source, pattern) {
228
- let window = following_window(source, index, 3);
229
269
  let args = call_inside_after(source, index + pattern.len());
230
- let risky = window.contains("runInShell: true")
270
+ let run_in_shell_disabled = syntax.as_ref().is_some_and(|(root, parsed_source)| {
271
+ parsed_run_in_shell_is_disabled(*root, parsed_source, index)
272
+ });
273
+ let safe_dart_runtime_start = run_in_shell_disabled
274
+ && pattern == "Process.start("
275
+ && args
276
+ .as_deref()
277
+ .is_some_and(|call| resolved_dart_runtime_start(syntax, index, call));
278
+ let risky = args.as_deref().is_some_and(|call| {
279
+ syntax.as_ref().is_some_and(|(root, parsed_source)| {
280
+ call_invokes_command_shell(*root, parsed_source, index, call)
281
+ })
282
+ }) || !run_in_shell_disabled
231
283
  || args.as_deref().is_some_and(|call| {
232
- !first_call_arg_is_fixed_literal(call) || has_dynamic_text(call)
284
+ !safe_dart_runtime_start
285
+ && (!first_call_arg_is_fixed_literal(call) || has_dynamic_text(call))
233
286
  });
234
287
  if risky {
235
288
  candidates.push(detected(
@@ -468,6 +521,1084 @@ fn first_call_arg_is_fixed_literal(call: &str) -> bool {
468
521
  matches!(rest.as_bytes().first(), Some(b',' | b')'))
469
522
  }
470
523
 
524
+ fn call_invokes_command_shell(root: Node<'_>, source: &str, index: usize, call: &str) -> bool {
525
+ let arguments = top_level_call_arguments(call);
526
+ let Some(executable) = arguments
527
+ .first()
528
+ .and_then(|value| resolved_fixed_literal_value(root, source, index, value))
529
+ else {
530
+ return false;
531
+ };
532
+ let executable = executable
533
+ .rsplit(['/', '\\'])
534
+ .next()
535
+ .unwrap_or(&executable)
536
+ .to_ascii_lowercase();
537
+ let Some(shell_arguments) = arguments
538
+ .get(1)
539
+ .and_then(|value| resolved_list_arguments(root, source, index, value))
540
+ else {
541
+ return false;
542
+ };
543
+ let posix_executable = executable.strip_suffix(".exe").unwrap_or(&executable);
544
+ if !matches!(
545
+ executable.as_str(),
546
+ "cmd" | "cmd.exe" | "powershell" | "powershell.exe" | "pwsh" | "pwsh.exe"
547
+ ) && !command_interpreter_uses_c_flag(posix_executable)
548
+ {
549
+ return false;
550
+ }
551
+ for argument in shell_arguments {
552
+ let Some(flag) = resolved_fixed_literal_value(root, source, index, &argument)
553
+ .map(|value| value.to_ascii_lowercase())
554
+ else {
555
+ return true;
556
+ };
557
+ let (invokes_command, is_option) = match executable.as_str() {
558
+ "cmd" | "cmd.exe" => (
559
+ matches!(flag.as_str(), "/c" | "/k"),
560
+ flag.starts_with('/') || flag.starts_with('-'),
561
+ ),
562
+ "powershell" | "powershell.exe" | "pwsh" | "pwsh.exe" => (
563
+ matches!(flag.as_str(), "-c" | "-command" | "-encodedcommand"),
564
+ flag.starts_with('-') || flag.starts_with('/'),
565
+ ),
566
+ _ if command_interpreter_uses_c_flag(posix_executable) => (
567
+ posix_shell_flag_invokes_command(&flag),
568
+ flag.starts_with('-'),
569
+ ),
570
+ _ => return false,
571
+ };
572
+ if invokes_command {
573
+ return true;
574
+ }
575
+ if !is_option {
576
+ return false;
577
+ }
578
+ }
579
+ false
580
+ }
581
+
582
+ fn posix_shell_flag_invokes_command(flag: &str) -> bool {
583
+ flag.strip_prefix('-')
584
+ .is_some_and(|options| !options.starts_with('-') && options.contains('c'))
585
+ }
586
+
587
+ fn command_interpreter_uses_c_flag(executable: &str) -> bool {
588
+ matches!(
589
+ executable,
590
+ "sh" | "ash"
591
+ | "bash"
592
+ | "csh"
593
+ | "dash"
594
+ | "elvish"
595
+ | "fish"
596
+ | "ksh"
597
+ | "mksh"
598
+ | "nu"
599
+ | "osh"
600
+ | "pdksh"
601
+ | "rc"
602
+ | "tcsh"
603
+ | "xonsh"
604
+ | "yash"
605
+ | "ysh"
606
+ | "zsh"
607
+ )
608
+ }
609
+
610
+ fn fixed_literal_value(value: &str) -> Option<String> {
611
+ let value = value.trim();
612
+ let raw = value
613
+ .as_bytes()
614
+ .get(0..2)
615
+ .is_some_and(|prefix| matches!(prefix, [b'r' | b'R', b'\'' | b'"']));
616
+ let quote_index = usize::from(raw);
617
+ read_string(value, quote_index)
618
+ .filter(|(literal, _, end)| *end == value.len() && (raw || !literal.contains('$')))
619
+ .map(|(literal, _, _)| literal)
620
+ }
621
+
622
+ fn resolved_dart_runtime_start(syntax: Option<(Node<'_>, &str)>, index: usize, call: &str) -> bool {
623
+ let Some((root, source)) = syntax else {
624
+ return false;
625
+ };
626
+ let args = top_level_call_arguments(call);
627
+ let Some(executable) = args.first().map(|arg| arg.trim()) else {
628
+ return false;
629
+ };
630
+ let Some(arguments) = args.get(1).map(|arg| arg.trim()) else {
631
+ return false;
632
+ };
633
+ (is_dart_io_platform_reference(root, source, index, executable)
634
+ || is_identifier(executable)
635
+ && lexical_binding_value(root, source, index, executable).is_some_and(|value| {
636
+ value == "Platform.resolvedExecutable"
637
+ && is_dart_io_platform_reference(root, source, index, value)
638
+ }))
639
+ && fixed_argument_list(root, source, index, arguments)
640
+ }
641
+
642
+ fn is_dart_io_platform_reference(root: Node<'_>, source: &str, index: usize, value: &str) -> bool {
643
+ if library_scope_has_parts(root) {
644
+ return false;
645
+ }
646
+ let qualifier = if value == "Platform.resolvedExecutable" {
647
+ ""
648
+ } else if let Some(qualifier) = value.strip_suffix(".Platform.resolvedExecutable") {
649
+ qualifier
650
+ } else {
651
+ return false;
652
+ };
653
+ let prefix = (!qualifier.is_empty()).then_some(qualifier);
654
+ if prefix.is_some_and(|prefix| !is_identifier(prefix)) {
655
+ return false;
656
+ }
657
+ if prefix.is_none()
658
+ && (top_level_declares_name(root, "Platform", source)
659
+ || lexical_name_shadowed(root, source, index, "Platform")
660
+ || import_prefix_declares_name(root, source, "Platform")
661
+ || imported_library_may_expose_name(root, source, "Platform"))
662
+ {
663
+ return false;
664
+ }
665
+ if prefix.is_some_and(|prefix| {
666
+ top_level_declares_name(root, prefix, source)
667
+ || lexical_name_shadowed(root, source, index, prefix)
668
+ }) {
669
+ return false;
670
+ }
671
+ let mut found = false;
672
+ visit_named(root, &mut |node| {
673
+ if found || node.kind() != "library_import" {
674
+ return;
675
+ }
676
+ let Some(specification) = first_named_descendant(node, "import_specification") else {
677
+ return;
678
+ };
679
+ let Some(uri) = specification
680
+ .child_by_field_name("uri")
681
+ .and_then(|uri| uri.utf8_text(source.as_bytes()).ok())
682
+ .and_then(fixed_literal_value)
683
+ else {
684
+ return;
685
+ };
686
+ if uri != "dart:io" {
687
+ return;
688
+ }
689
+ let alias = specification
690
+ .child_by_field_name("alias")
691
+ .and_then(|alias| alias.utf8_text(source.as_bytes()).ok());
692
+ if alias != prefix {
693
+ return;
694
+ }
695
+ if import_exposes_name(node, "Platform", source) {
696
+ found = true;
697
+ }
698
+ });
699
+ found
700
+ }
701
+
702
+ fn import_exposes_name(node: Node<'_>, name: &str, source: &str) -> bool {
703
+ let mut visible = true;
704
+ let mut combinators = Vec::new();
705
+ collect_named_descendants(node, "combinator", &mut combinators);
706
+ for combinator in combinators {
707
+ let Ok(text) = combinator.utf8_text(source.as_bytes()) else {
708
+ return false;
709
+ };
710
+ let text = text.trim_start();
711
+ let mut identifiers = Vec::new();
712
+ collect_named_descendants(combinator, "identifier", &mut identifiers);
713
+ let contains_name = identifiers
714
+ .into_iter()
715
+ .any(|identifier| identifier.utf8_text(source.as_bytes()).ok() == Some(name));
716
+ if text.starts_with("show") {
717
+ visible = contains_name;
718
+ } else if text.starts_with("hide") && contains_name {
719
+ visible = false;
720
+ }
721
+ }
722
+ visible
723
+ }
724
+
725
+ fn lexical_name_shadowed(root: Node<'_>, source: &str, index: usize, name: &str) -> bool {
726
+ let Some(mut child) = root.descendant_for_byte_range(index, index.saturating_add(1)) else {
727
+ return true;
728
+ };
729
+ while let Some(parent) = child.parent() {
730
+ if process_scope_parameters_bind_name(parent, name, source)
731
+ || process_scope_header_binds_name(parent, child, name, source)
732
+ {
733
+ return true;
734
+ }
735
+ let mut cursor = parent.walk();
736
+ if parent
737
+ .named_children(&mut cursor)
738
+ .take_while(|sibling| sibling.start_byte() < child.start_byte())
739
+ .any(|sibling| direct_binding(sibling, name, source, false).is_some())
740
+ {
741
+ return true;
742
+ }
743
+ child = parent;
744
+ }
745
+ false
746
+ }
747
+
748
+ fn top_level_declares_name(root: Node<'_>, name: &str, source: &str) -> bool {
749
+ let mut cursor = root.walk();
750
+ root.named_children(&mut cursor).any(|child| {
751
+ if direct_binding(child, name, source, false).is_some() {
752
+ return true;
753
+ }
754
+ top_level_declaration_name(child, source).as_deref() == Some(name)
755
+ })
756
+ }
757
+
758
+ fn top_level_declaration_name(node: Node<'_>, source: &str) -> Option<String> {
759
+ if !matches!(
760
+ node.kind(),
761
+ "class_declaration"
762
+ | "enum_declaration"
763
+ | "extension_declaration"
764
+ | "extension_type_declaration"
765
+ | "external_function_declaration"
766
+ | "external_getter_declaration"
767
+ | "external_setter_declaration"
768
+ | "function_declaration"
769
+ | "getter_declaration"
770
+ | "mixin_declaration"
771
+ | "setter_declaration"
772
+ | "type_alias"
773
+ ) {
774
+ return None;
775
+ }
776
+ if matches!(
777
+ node.kind(),
778
+ "external_function_declaration"
779
+ | "external_getter_declaration"
780
+ | "external_setter_declaration"
781
+ | "function_declaration"
782
+ | "getter_declaration"
783
+ | "setter_declaration"
784
+ ) {
785
+ return member_signature_name(node, source);
786
+ }
787
+ node.child_by_field_name("name")
788
+ .or_else(|| {
789
+ if node.kind() == "type_alias" {
790
+ first_named_descendant(node, "identifier")
791
+ .or_else(|| first_named_descendant(node, "type_identifier"))
792
+ } else {
793
+ None
794
+ }
795
+ })
796
+ .and_then(|name| name.utf8_text(source.as_bytes()).ok())
797
+ .map(str::to_owned)
798
+ }
799
+
800
+ fn imported_library_may_expose_name(root: Node<'_>, source: &str, name: &str) -> bool {
801
+ let mut may_expose = false;
802
+ visit_named(root, &mut |node| {
803
+ if may_expose || node.kind() != "library_import" {
804
+ return;
805
+ }
806
+ let Some(specification) = first_named_descendant(node, "import_specification") else {
807
+ return;
808
+ };
809
+ if specification.child_by_field_name("alias").is_some() {
810
+ return;
811
+ }
812
+ let uri = specification
813
+ .child_by_field_name("uri")
814
+ .and_then(|uri| uri.utf8_text(source.as_bytes()).ok())
815
+ .and_then(fixed_literal_value);
816
+ if uri.as_deref() != Some("dart:io") && import_exposes_name(node, name, source) {
817
+ may_expose = true;
818
+ }
819
+ });
820
+ may_expose
821
+ }
822
+
823
+ fn library_scope_has_parts(root: Node<'_>) -> bool {
824
+ let mut has_parts = false;
825
+ visit_named(root, &mut |node| {
826
+ if matches!(node.kind(), "part_directive" | "part_of_directive") {
827
+ has_parts = true;
828
+ }
829
+ });
830
+ has_parts
831
+ }
832
+
833
+ fn import_prefix_declares_name(root: Node<'_>, source: &str, name: &str) -> bool {
834
+ let mut found = false;
835
+ visit_named(root, &mut |node| {
836
+ if found || node.kind() != "library_import" {
837
+ return;
838
+ }
839
+ let Some(specification) = first_named_descendant(node, "import_specification") else {
840
+ return;
841
+ };
842
+ if specification
843
+ .child_by_field_name("alias")
844
+ .and_then(|alias| alias.utf8_text(source.as_bytes()).ok())
845
+ == Some(name)
846
+ {
847
+ found = true;
848
+ }
849
+ });
850
+ found
851
+ }
852
+
853
+ fn visit_named(node: Node<'_>, visit: &mut impl FnMut(Node<'_>)) {
854
+ visit(node);
855
+ let mut cursor = node.walk();
856
+ for child in node.named_children(&mut cursor) {
857
+ visit_named(child, visit);
858
+ }
859
+ }
860
+
861
+ fn collect_named_descendants<'tree>(node: Node<'tree>, kind: &str, nodes: &mut Vec<Node<'tree>>) {
862
+ if node.kind() == kind {
863
+ nodes.push(node);
864
+ }
865
+ let mut cursor = node.walk();
866
+ for child in node.named_children(&mut cursor) {
867
+ collect_named_descendants(child, kind, nodes);
868
+ }
869
+ }
870
+
871
+ fn first_named_descendant<'tree>(node: Node<'tree>, kind: &str) -> Option<Node<'tree>> {
872
+ if node.kind() == kind {
873
+ return Some(node);
874
+ }
875
+ let mut cursor = node.walk();
876
+ node.named_children(&mut cursor)
877
+ .find_map(|child| first_named_descendant(child, kind))
878
+ }
879
+
880
+ fn top_level_call_arguments(call: &str) -> Vec<&str> {
881
+ let mut arguments = Vec::new();
882
+ let mut start = 0usize;
883
+ let mut index = 0usize;
884
+ let mut depth = 0usize;
885
+ let bytes = call.as_bytes();
886
+ while index < bytes.len() {
887
+ match bytes[index] {
888
+ b'\'' | b'"' => {
889
+ let Some((_, _, end)) = read_string(call, index) else {
890
+ return Vec::new();
891
+ };
892
+ index = end;
893
+ continue;
894
+ }
895
+ b'(' | b'[' | b'{' => depth += 1,
896
+ b')' | b']' | b'}' => depth = depth.saturating_sub(1),
897
+ b',' if depth == 0 => {
898
+ arguments.push(&call[start..index]);
899
+ start = index + 1;
900
+ }
901
+ _ => {}
902
+ }
903
+ index += 1;
904
+ }
905
+ arguments.push(&call[start..]);
906
+ arguments
907
+ }
908
+
909
+ fn parsed_run_in_shell_is_disabled(root: Node<'_>, source: &str, index: usize) -> bool {
910
+ let Some(call) = call_expression_at(root, index) else {
911
+ return false;
912
+ };
913
+ let Some(arguments) = call.child_by_field_name("arguments") else {
914
+ return false;
915
+ };
916
+ let mut cursor = arguments.walk();
917
+ for argument in arguments.named_children(&mut cursor) {
918
+ if argument.kind() != "named_argument"
919
+ || named_argument_label(argument, source).as_deref() != Some("runInShell")
920
+ {
921
+ continue;
922
+ }
923
+ return named_argument_value(argument)
924
+ .and_then(|value| value.utf8_text(source.as_bytes()).ok())
925
+ .is_some_and(|value| value.trim() == "false");
926
+ }
927
+ true
928
+ }
929
+
930
+ fn call_expression_at(root: Node<'_>, index: usize) -> Option<Node<'_>> {
931
+ let mut node = root.descendant_for_byte_range(index, index.saturating_add(1))?;
932
+ loop {
933
+ if node.kind() == "call_expression" && node.start_byte() <= index && node.end_byte() > index
934
+ {
935
+ return Some(node);
936
+ }
937
+ node = node.parent()?;
938
+ }
939
+ }
940
+
941
+ fn named_argument_label(node: Node<'_>, source: &str) -> Option<String> {
942
+ let mut cursor = node.walk();
943
+ node.named_children(&mut cursor)
944
+ .find(|child| child.kind() == "label")
945
+ .and_then(|label| label.utf8_text(source.as_bytes()).ok())
946
+ .map(str::trim)
947
+ .and_then(|label| label.strip_suffix(':'))
948
+ .map(str::to_owned)
949
+ }
950
+
951
+ fn named_argument_value(node: Node<'_>) -> Option<Node<'_>> {
952
+ let mut cursor = node.walk();
953
+ node.named_children(&mut cursor)
954
+ .find(|child| child.kind() != "label")
955
+ }
956
+
957
+ fn fixed_argument_list(root: Node<'_>, source: &str, index: usize, arguments: &str) -> bool {
958
+ let Some(elements) = resolved_list_arguments(root, source, index, arguments) else {
959
+ return false;
960
+ };
961
+ elements.into_iter().all(|argument| {
962
+ let argument = argument.trim();
963
+ argument.is_empty()
964
+ || fixed_string_literal(argument)
965
+ || is_identifier(argument)
966
+ && lexical_binding_value(root, source, index, argument)
967
+ .is_some_and(fixed_string_literal)
968
+ })
969
+ }
970
+
971
+ fn list_literal_contents(value: &str) -> Option<&str> {
972
+ let value = value.trim();
973
+ let value = value.strip_prefix("const").map_or(value, str::trim_start);
974
+ let start = value.find('[')?;
975
+ if !value[..start].trim().is_empty() && !value[..start].trim().ends_with('>') {
976
+ return None;
977
+ }
978
+ value[start + 1..].strip_suffix(']')
979
+ }
980
+
981
+ fn resolved_fixed_literal_value(
982
+ root: Node<'_>,
983
+ source: &str,
984
+ index: usize,
985
+ value: &str,
986
+ ) -> Option<String> {
987
+ let mut visited = BTreeSet::new();
988
+ resolved_fixed_literal_value_inner(root, source, index, value, &mut visited)
989
+ }
990
+
991
+ fn resolved_fixed_literal_value_inner(
992
+ root: Node<'_>,
993
+ source: &str,
994
+ index: usize,
995
+ value: &str,
996
+ visited: &mut BTreeSet<String>,
997
+ ) -> Option<String> {
998
+ if let Some(literal) = fixed_literal_value(value) {
999
+ return Some(literal);
1000
+ }
1001
+ let name = value.trim();
1002
+ if !is_identifier(name) || !visited.insert(name.to_owned()) {
1003
+ return None;
1004
+ }
1005
+ let binding = lexical_binding_value(root, source, index, name)?;
1006
+ resolved_fixed_literal_value_inner(root, source, index, binding, visited)
1007
+ }
1008
+
1009
+ fn resolved_list_arguments(
1010
+ root: Node<'_>,
1011
+ source: &str,
1012
+ index: usize,
1013
+ value: &str,
1014
+ ) -> Option<Vec<String>> {
1015
+ let mut visited = BTreeSet::new();
1016
+ resolved_list_arguments_inner(root, source, index, value, &mut visited)
1017
+ }
1018
+
1019
+ fn resolved_list_arguments_inner(
1020
+ root: Node<'_>,
1021
+ source: &str,
1022
+ index: usize,
1023
+ value: &str,
1024
+ visited: &mut BTreeSet<String>,
1025
+ ) -> Option<Vec<String>> {
1026
+ let value = value.trim();
1027
+ if let Some(inner) = list_literal_contents(value) {
1028
+ return Some(
1029
+ top_level_call_arguments(inner)
1030
+ .into_iter()
1031
+ .map(str::trim)
1032
+ .map(str::to_owned)
1033
+ .collect(),
1034
+ );
1035
+ }
1036
+ if !is_identifier(value) || !visited.insert(value.to_owned()) {
1037
+ return None;
1038
+ }
1039
+ let binding = lexical_binding_value(root, source, index, value)?;
1040
+ resolved_list_arguments_inner(root, source, index, binding, visited)
1041
+ }
1042
+
1043
+ fn fixed_string_literal(value: &str) -> bool {
1044
+ fixed_literal_value(value).is_some()
1045
+ }
1046
+
1047
+ fn lexical_binding_value<'source>(
1048
+ root: Node<'_>,
1049
+ source: &'source str,
1050
+ index: usize,
1051
+ name: &str,
1052
+ ) -> Option<&'source str> {
1053
+ let mut child = root.descendant_for_byte_range(index, index.saturating_add(1))?;
1054
+ while let Some(parent) = child.parent() {
1055
+ if parent.kind() == "class_body" {
1056
+ if let Some(binding) = class_binding(parent, child, name, source) {
1057
+ return match binding {
1058
+ LexicalBinding::Value(value) => Some(value),
1059
+ LexicalBinding::Unknown => None,
1060
+ };
1061
+ }
1062
+ }
1063
+ if process_scope_parameters_bind_name(parent, name, source)
1064
+ || process_scope_header_binds_name(parent, child, name, source)
1065
+ {
1066
+ return None;
1067
+ }
1068
+ if parent.parent().is_none() {
1069
+ return top_level_binding(parent, name, source);
1070
+ }
1071
+ let mut cursor = parent.walk();
1072
+ let mut siblings = parent
1073
+ .named_children(&mut cursor)
1074
+ .take_while(|sibling| sibling.start_byte() < child.start_byte())
1075
+ .collect::<Vec<_>>();
1076
+ while let Some(sibling) = siblings.pop() {
1077
+ if let Some(binding) = direct_binding(sibling, name, source, false) {
1078
+ return match binding {
1079
+ LexicalBinding::Value(value) => Some(value),
1080
+ LexicalBinding::Unknown => None,
1081
+ };
1082
+ }
1083
+ }
1084
+ child = parent;
1085
+ }
1086
+ None
1087
+ }
1088
+
1089
+ fn top_level_binding<'source>(
1090
+ root: Node<'_>,
1091
+ name: &str,
1092
+ source: &'source str,
1093
+ ) -> Option<&'source str> {
1094
+ let mut cursor = root.walk();
1095
+ let mut binding = None;
1096
+ for child in root.named_children(&mut cursor) {
1097
+ let Some(candidate) = direct_binding(child, name, source, false) else {
1098
+ continue;
1099
+ };
1100
+ if binding.is_some() {
1101
+ return None;
1102
+ }
1103
+ binding = Some(candidate);
1104
+ }
1105
+ match binding {
1106
+ Some(LexicalBinding::Value(value)) => Some(value),
1107
+ Some(LexicalBinding::Unknown) | None => None,
1108
+ }
1109
+ }
1110
+
1111
+ fn class_binding<'source>(
1112
+ class_body: Node<'_>,
1113
+ current_member: Node<'_>,
1114
+ name: &str,
1115
+ source: &'source str,
1116
+ ) -> Option<LexicalBinding<'source>> {
1117
+ let mut cursor = class_body.walk();
1118
+ let direct = class_body
1119
+ .named_children(&mut cursor)
1120
+ .filter(|member| member.start_byte() != current_member.start_byte())
1121
+ .find_map(|member| class_member_binding(member, name, source));
1122
+ if direct.is_some() {
1123
+ return direct;
1124
+ }
1125
+ let class = class_body.parent()?;
1126
+ let mut visited = BTreeSet::new();
1127
+ let root = root_node(class);
1128
+ inherited_class_binding(root, class, name, source, &mut visited).or_else(|| {
1129
+ let mut visited = BTreeSet::new();
1130
+ class_hierarchy_is_unresolved(root, class, source, &mut visited)
1131
+ .then_some(LexicalBinding::Unknown)
1132
+ })
1133
+ }
1134
+
1135
+ fn class_member_binding<'source>(
1136
+ member: Node<'_>,
1137
+ name: &str,
1138
+ source: &'source str,
1139
+ ) -> Option<LexicalBinding<'source>> {
1140
+ direct_binding(member, name, source, false).or_else(|| {
1141
+ class_member_declares_name(member, name, source).then_some(LexicalBinding::Unknown)
1142
+ })
1143
+ }
1144
+
1145
+ fn class_member_declares_name(member: Node<'_>, name: &str, source: &str) -> bool {
1146
+ let mut cursor = member.walk();
1147
+ member
1148
+ .named_children(&mut cursor)
1149
+ .filter(|child| matches!(child.kind(), "declaration" | "method_declaration"))
1150
+ .any(|child| member_signature_name(child, source).as_deref() == Some(name))
1151
+ }
1152
+
1153
+ fn member_signature_name(node: Node<'_>, source: &str) -> Option<String> {
1154
+ if matches!(
1155
+ node.kind(),
1156
+ "function_signature" | "getter_signature" | "setter_signature"
1157
+ ) {
1158
+ return node
1159
+ .child_by_field_name("name")?
1160
+ .utf8_text(source.as_bytes())
1161
+ .ok()
1162
+ .map(str::to_owned);
1163
+ }
1164
+ let mut cursor = node.walk();
1165
+ node.named_children(&mut cursor)
1166
+ .find_map(|child| member_signature_name(child, source))
1167
+ }
1168
+
1169
+ fn inherited_class_binding<'source>(
1170
+ root: Node<'_>,
1171
+ class: Node<'_>,
1172
+ name: &str,
1173
+ source: &'source str,
1174
+ visited: &mut BTreeSet<String>,
1175
+ ) -> Option<LexicalBinding<'source>> {
1176
+ for mixin_name in class_mixin_names(class, source).into_iter().rev() {
1177
+ if !visited.insert(mixin_name.clone()) {
1178
+ continue;
1179
+ }
1180
+ let mixin = find_class_like_declaration(root, &mixin_name, source)?;
1181
+ let body = mixin.child_by_field_name("body")?;
1182
+ let mut cursor = body.walk();
1183
+ if let Some(binding) = body
1184
+ .named_children(&mut cursor)
1185
+ .find_map(|member| class_member_binding(member, name, source))
1186
+ {
1187
+ return Some(binding);
1188
+ }
1189
+ if let Some(binding) = inherited_class_binding(root, mixin, name, source, visited) {
1190
+ return Some(binding);
1191
+ }
1192
+ }
1193
+ let parent_name = class_superclass_name(class, source)?;
1194
+ if !visited.insert(parent_name.clone()) {
1195
+ return None;
1196
+ }
1197
+ let parent = find_class_like_declaration(root, &parent_name, source)?;
1198
+ let body = parent.child_by_field_name("body")?;
1199
+ let mut cursor = body.walk();
1200
+ if let Some(binding) = body
1201
+ .named_children(&mut cursor)
1202
+ .find_map(|member| class_member_binding(member, name, source))
1203
+ {
1204
+ return Some(binding);
1205
+ }
1206
+ inherited_class_binding(root, parent, name, source, visited)
1207
+ }
1208
+
1209
+ fn class_hierarchy_is_unresolved(
1210
+ root: Node<'_>,
1211
+ class: Node<'_>,
1212
+ source: &str,
1213
+ visited: &mut BTreeSet<String>,
1214
+ ) -> bool {
1215
+ for mixin_name in class_mixin_names(class, source) {
1216
+ if !visited.insert(mixin_name.clone()) {
1217
+ return true;
1218
+ }
1219
+ let Some(mixin) = find_class_like_declaration(root, &mixin_name, source) else {
1220
+ return true;
1221
+ };
1222
+ if class_hierarchy_is_unresolved(root, mixin, source, visited) {
1223
+ return true;
1224
+ }
1225
+ }
1226
+ let Some(parent_name) = class_superclass_name(class, source) else {
1227
+ return false;
1228
+ };
1229
+ if !visited.insert(parent_name.clone()) {
1230
+ return true;
1231
+ }
1232
+ if parent_name == "Object" {
1233
+ return false;
1234
+ }
1235
+ let Some(parent) = find_class_like_declaration(root, &parent_name, source) else {
1236
+ return true;
1237
+ };
1238
+ class_hierarchy_is_unresolved(root, parent, source, visited)
1239
+ }
1240
+
1241
+ fn class_mixin_names(class: Node<'_>, source: &str) -> Vec<String> {
1242
+ let Some(superclass) = class.child_by_field_name("superclass") else {
1243
+ return Vec::new();
1244
+ };
1245
+ let mixins = if superclass.kind() == "mixins" {
1246
+ Some(superclass)
1247
+ } else {
1248
+ let mut cursor = superclass.walk();
1249
+ superclass
1250
+ .named_children(&mut cursor)
1251
+ .find(|child| child.kind() == "mixins")
1252
+ };
1253
+ let Some(mixins) = mixins else {
1254
+ return Vec::new();
1255
+ };
1256
+ let mut cursor = mixins.walk();
1257
+ mixins
1258
+ .named_children(&mut cursor)
1259
+ .filter(|child| child.kind() == "type")
1260
+ .filter_map(|child| child.utf8_text(source.as_bytes()).ok())
1261
+ .map(|name| name.split('<').next().unwrap_or(name).trim().to_owned())
1262
+ .collect()
1263
+ }
1264
+
1265
+ fn class_superclass_name(class: Node<'_>, source: &str) -> Option<String> {
1266
+ let superclass = class.child_by_field_name("superclass")?;
1267
+ let name = superclass
1268
+ .child_by_field_name("type")?
1269
+ .utf8_text(source.as_bytes())
1270
+ .ok()?;
1271
+ let name = name.split('<').next()?.trim();
1272
+ Some(name.to_owned())
1273
+ }
1274
+
1275
+ fn find_class_like_declaration<'tree>(
1276
+ node: Node<'tree>,
1277
+ name: &str,
1278
+ source: &str,
1279
+ ) -> Option<Node<'tree>> {
1280
+ if matches!(node.kind(), "class_declaration" | "mixin_declaration")
1281
+ && node
1282
+ .child_by_field_name("name")
1283
+ .and_then(|name| name.utf8_text(source.as_bytes()).ok())
1284
+ == Some(name)
1285
+ {
1286
+ return Some(node);
1287
+ }
1288
+ let mut cursor = node.walk();
1289
+ node.named_children(&mut cursor)
1290
+ .find_map(|child| find_class_like_declaration(child, name, source))
1291
+ }
1292
+
1293
+ fn root_node(mut node: Node<'_>) -> Node<'_> {
1294
+ while let Some(parent) = node.parent() {
1295
+ node = parent;
1296
+ }
1297
+ node
1298
+ }
1299
+
1300
+ enum LexicalBinding<'source> {
1301
+ Value(&'source str),
1302
+ Unknown,
1303
+ }
1304
+
1305
+ fn direct_binding<'source>(
1306
+ node: Node<'_>,
1307
+ name: &str,
1308
+ source: &'source str,
1309
+ immutable: bool,
1310
+ ) -> Option<LexicalBinding<'source>> {
1311
+ let immutable = immutable || declaration_is_immutable(node);
1312
+ if node.kind() == "pattern_variable_declaration" {
1313
+ let mut cursor = node.walk();
1314
+ let pattern = node.named_children(&mut cursor).next()?;
1315
+ return pattern_identifier_binds_name(pattern, name, source)
1316
+ .then_some(LexicalBinding::Unknown);
1317
+ }
1318
+ if matches!(
1319
+ node.kind(),
1320
+ "formal_parameter" | "typed_identifier" | "variable_pattern"
1321
+ ) {
1322
+ let binding_name = node
1323
+ .child_by_field_name("name")?
1324
+ .utf8_text(source.as_bytes())
1325
+ .ok()?;
1326
+ return (binding_name == name).then_some(LexicalBinding::Unknown);
1327
+ }
1328
+ if matches!(
1329
+ node.kind(),
1330
+ "initialized_identifier" | "initialized_variable_definition" | "static_final_declaration"
1331
+ ) {
1332
+ let binding_name = node
1333
+ .child_by_field_name("name")?
1334
+ .utf8_text(source.as_bytes())
1335
+ .ok()?;
1336
+ if binding_name != name {
1337
+ return None;
1338
+ }
1339
+ if !immutable {
1340
+ return Some(LexicalBinding::Unknown);
1341
+ }
1342
+ return Some(
1343
+ node.child_by_field_name("value")
1344
+ .and_then(|value| value.utf8_text(source.as_bytes()).ok())
1345
+ .map(str::trim)
1346
+ .map_or(LexicalBinding::Unknown, LexicalBinding::Value),
1347
+ );
1348
+ }
1349
+ if node.kind() == "assignment_expression" {
1350
+ let left = node
1351
+ .child_by_field_name("left")?
1352
+ .utf8_text(source.as_bytes())
1353
+ .ok()?;
1354
+ let operator = node
1355
+ .child_by_field_name("operator")?
1356
+ .utf8_text(source.as_bytes())
1357
+ .ok()?;
1358
+ if left.trim() == name && operator == "=" {
1359
+ return Some(LexicalBinding::Unknown);
1360
+ }
1361
+ return None;
1362
+ }
1363
+ if !matches!(
1364
+ node.kind(),
1365
+ "class_member"
1366
+ | "declaration"
1367
+ | "expression_statement"
1368
+ | "initialized_identifier_list"
1369
+ | "local_variable_declaration"
1370
+ | "static_final_declaration_list"
1371
+ | "top_level_variable_declaration"
1372
+ ) {
1373
+ return None;
1374
+ }
1375
+ let mut cursor = node.walk();
1376
+ let mut children = node.named_children(&mut cursor).collect::<Vec<_>>();
1377
+ while let Some(child) = children.pop() {
1378
+ if let Some(binding) = direct_binding(child, name, source, immutable) {
1379
+ return Some(binding);
1380
+ }
1381
+ }
1382
+ None
1383
+ }
1384
+
1385
+ fn declaration_is_immutable(node: Node<'_>) -> bool {
1386
+ if node.kind() == "static_final_declaration_list" {
1387
+ return true;
1388
+ }
1389
+ let mut cursor = node.walk();
1390
+ node.children(&mut cursor)
1391
+ .any(|child| matches!(child.kind(), "const" | "final"))
1392
+ }
1393
+
1394
+ fn process_scope_header_binds_name(
1395
+ node: Node<'_>,
1396
+ path_child: Node<'_>,
1397
+ name: &str,
1398
+ source: &str,
1399
+ ) -> bool {
1400
+ if node.kind() == "catch_clause" {
1401
+ return catch_clause_binds_name(node, name, source);
1402
+ }
1403
+ if node.kind() == "try_statement" {
1404
+ let mut cursor = node.walk();
1405
+ let preceding = node
1406
+ .named_children(&mut cursor)
1407
+ .take_while(|child| child.start_byte() < path_child.start_byte())
1408
+ .collect::<Vec<_>>();
1409
+ return preceding
1410
+ .last()
1411
+ .filter(|child| child.kind() == "catch_clause")
1412
+ .is_some_and(|clause| catch_clause_binds_name(*clause, name, source));
1413
+ }
1414
+ match node.kind() {
1415
+ "for_element" | "for_statement" => {
1416
+ let Some(body) = node.child_by_field_name("body") else {
1417
+ return false;
1418
+ };
1419
+ if !node_contains(body, path_child) {
1420
+ return false;
1421
+ }
1422
+ if node
1423
+ .child_by_field_name("name")
1424
+ .is_some_and(|binding| binding.utf8_text(source.as_bytes()).ok() == Some(name))
1425
+ {
1426
+ return true;
1427
+ }
1428
+ let mut cursor = node.walk();
1429
+ if node
1430
+ .children_by_field_name("init", &mut cursor)
1431
+ .any(|binding| direct_binding(binding, name, source, false).is_some())
1432
+ {
1433
+ return true;
1434
+ }
1435
+ let Some(value) = node.child_by_field_name("value") else {
1436
+ return false;
1437
+ };
1438
+ let mut cursor = node.walk();
1439
+ node.named_children(&mut cursor)
1440
+ .take_while(|child| child.end_byte() <= value.start_byte())
1441
+ .any(|pattern| pattern_identifier_binds_name(pattern, name, source))
1442
+ }
1443
+ "if_element" | "if_statement" => node
1444
+ .child_by_field_name("consequence")
1445
+ .filter(|consequence| node_contains(*consequence, path_child))
1446
+ .is_some_and(|consequence| {
1447
+ patterns_before_bind_name(node, consequence.start_byte(), name, source)
1448
+ }),
1449
+ "switch_expression_case" | "switch_statement_case" => {
1450
+ patterns_before_bind_name(node, path_child.start_byte(), name, source)
1451
+ }
1452
+ _ => false,
1453
+ }
1454
+ }
1455
+
1456
+ fn catch_clause_binds_name(node: Node<'_>, name: &str, source: &str) -> bool {
1457
+ ["exception", "stack_trace"].into_iter().any(|field| {
1458
+ node.child_by_field_name(field)
1459
+ .and_then(|binding| binding.utf8_text(source.as_bytes()).ok())
1460
+ == Some(name)
1461
+ })
1462
+ }
1463
+
1464
+ fn node_contains(parent: Node<'_>, child: Node<'_>) -> bool {
1465
+ parent.start_byte() <= child.start_byte() && child.end_byte() <= parent.end_byte()
1466
+ }
1467
+
1468
+ fn patterns_before_bind_name(node: Node<'_>, end: usize, name: &str, source: &str) -> bool {
1469
+ let mut cursor = node.walk();
1470
+ node.named_children(&mut cursor)
1471
+ .take_while(|child| child.end_byte() <= end)
1472
+ .any(|child| variable_pattern_binds_name(child, name, source))
1473
+ }
1474
+
1475
+ fn variable_pattern_binds_name(node: Node<'_>, name: &str, source: &str) -> bool {
1476
+ if node.kind() == "variable_pattern"
1477
+ && node
1478
+ .child_by_field_name("name")
1479
+ .and_then(|binding| binding.utf8_text(source.as_bytes()).ok())
1480
+ == Some(name)
1481
+ {
1482
+ return true;
1483
+ }
1484
+ let mut cursor = node.walk();
1485
+ node.named_children(&mut cursor)
1486
+ .any(|child| variable_pattern_binds_name(child, name, source))
1487
+ }
1488
+
1489
+ fn pattern_identifier_binds_name(node: Node<'_>, name: &str, source: &str) -> bool {
1490
+ if matches!(node.kind(), "identifier" | "identifier_dollar_escaped")
1491
+ && node.utf8_text(source.as_bytes()).ok() == Some(name)
1492
+ {
1493
+ return true;
1494
+ }
1495
+ let mut cursor = node.walk();
1496
+ node.named_children(&mut cursor)
1497
+ .any(|child| pattern_identifier_binds_name(child, name, source))
1498
+ }
1499
+
1500
+ fn process_scope_parameters_bind_name(node: Node<'_>, name: &str, source: &str) -> bool {
1501
+ let parameter_lists = match node.kind() {
1502
+ "function_expression" => parameter_field_lists(node),
1503
+ "method_declaration" => node
1504
+ .child_by_field_name("signature")
1505
+ .map_or_else(Vec::new, collect_parameter_lists),
1506
+ "declaration" | "function_declaration" | "local_function_declaration" => {
1507
+ direct_parameterized_signature(node).map_or_else(Vec::new, collect_parameter_lists)
1508
+ }
1509
+ _ => Vec::new(),
1510
+ };
1511
+ parameter_lists
1512
+ .into_iter()
1513
+ .any(|parameters| parameter_list_binds_name(parameters, name, source))
1514
+ }
1515
+
1516
+ fn parameter_field_lists(node: Node<'_>) -> Vec<Node<'_>> {
1517
+ let mut cursor = node.walk();
1518
+ node.children_by_field_name("parameters", &mut cursor)
1519
+ .filter_map(formal_parameter_list)
1520
+ .collect()
1521
+ }
1522
+
1523
+ fn collect_parameter_lists(node: Node<'_>) -> Vec<Node<'_>> {
1524
+ own_parameter_list(node).into_iter().collect()
1525
+ }
1526
+
1527
+ fn own_parameter_list(node: Node<'_>) -> Option<Node<'_>> {
1528
+ if node.kind() == "formal_parameter_list" {
1529
+ return Some(node);
1530
+ }
1531
+ let mut cursor = node.walk();
1532
+ node.named_children(&mut cursor)
1533
+ .find_map(own_parameter_list)
1534
+ }
1535
+
1536
+ fn formal_parameter_list(node: Node<'_>) -> Option<Node<'_>> {
1537
+ if node.kind() == "formal_parameter_list" {
1538
+ return Some(node);
1539
+ }
1540
+ let mut cursor = node.walk();
1541
+ node.named_children(&mut cursor)
1542
+ .find(|child| child.kind() == "formal_parameter_list")
1543
+ }
1544
+
1545
+ fn parameter_list_binds_name(parameters: Node<'_>, name: &str, source: &str) -> bool {
1546
+ let mut cursor = parameters.walk();
1547
+ parameters.named_children(&mut cursor).any(|candidate| {
1548
+ if candidate.kind() == "formal_parameter" {
1549
+ return formal_parameter_name(candidate, source).as_deref() == Some(name);
1550
+ }
1551
+ candidate.kind() == "optional_formal_parameters"
1552
+ && parameter_list_binds_name(candidate, name, source)
1553
+ })
1554
+ }
1555
+
1556
+ fn formal_parameter_name(param: Node<'_>, source: &str) -> Option<String> {
1557
+ param
1558
+ .child_by_field_name("name")
1559
+ .or_else(|| last_identifier_child(param, source))
1560
+ .and_then(|name| name.utf8_text(source.as_bytes()).ok())
1561
+ .map(str::to_owned)
1562
+ }
1563
+
1564
+ fn last_identifier_child<'tree>(node: Node<'tree>, source: &str) -> Option<Node<'tree>> {
1565
+ let mut cursor = node.walk();
1566
+ node.named_children(&mut cursor)
1567
+ .filter(|child| {
1568
+ matches!(
1569
+ child.kind(),
1570
+ "identifier" | "identifier_dollar_escaped" | "type_identifier"
1571
+ ) && child.utf8_text(source.as_bytes()).ok() != Some("key")
1572
+ })
1573
+ .last()
1574
+ }
1575
+
1576
+ fn direct_parameterized_signature(node: Node<'_>) -> Option<Node<'_>> {
1577
+ let mut cursor = node.walk();
1578
+ node.named_children(&mut cursor).find(|child| {
1579
+ matches!(
1580
+ child.kind(),
1581
+ "constant_constructor_signature"
1582
+ | "constructor_signature"
1583
+ | "factory_constructor_signature"
1584
+ | "function_signature"
1585
+ | "operator_signature"
1586
+ | "redirecting_factory_constructor_signature"
1587
+ | "setter_signature"
1588
+ )
1589
+ })
1590
+ }
1591
+
1592
+ fn is_identifier(value: &str) -> bool {
1593
+ let mut characters = value.chars();
1594
+ characters
1595
+ .next()
1596
+ .is_some_and(|character| character == '_' || character.is_ascii_alphabetic())
1597
+ && characters.all(|character| {
1598
+ character == '_' || character == '$' || character.is_ascii_alphanumeric()
1599
+ })
1600
+ }
1601
+
471
1602
  fn sql_call_is_parameterized(call: &str) -> bool {
472
1603
  call.contains('?') && (call.contains('[') || call.contains("whereArgs"))
473
1604
  }
@@ -545,22 +1676,34 @@ fn firebase_secret_name_context(source: &str, index: usize) -> bool {
545
1676
  }
546
1677
 
547
1678
  fn literal_secret_binding_context(source: &str, index: usize) -> bool {
548
- literal_binding_identifier(source, index).is_some_and(secret_binding_identifier)
1679
+ literal_binding_name(source, index).is_some_and(|name| secret_binding_identifier(&name))
549
1680
  }
550
1681
 
551
- fn literal_binding_identifier(source: &str, index: usize) -> Option<&str> {
1682
+ fn literal_binding_name(source: &str, index: usize) -> Option<String> {
552
1683
  let context = literal_context(source, index)?;
553
1684
  for separator in ['=', ':'] {
554
1685
  let Some((candidate, rest)) = context.rsplit_once(separator) else {
555
1686
  continue;
556
1687
  };
557
1688
  if rest.trim().is_empty() {
558
- return trailing_identifier(candidate);
1689
+ return trailing_identifier(candidate)
1690
+ .map(str::to_owned)
1691
+ .or_else(|| trailing_string_literal(candidate));
559
1692
  }
560
1693
  }
561
1694
  None
562
1695
  }
563
1696
 
1697
+ fn trailing_string_literal(text: &str) -> Option<String> {
1698
+ let trimmed = text.trim_end();
1699
+ trimmed
1700
+ .char_indices()
1701
+ .filter(|(_, character)| matches!(character, '\'' | '"'))
1702
+ .filter_map(|(index, _)| read_string(trimmed, index))
1703
+ .find(|(_, _, end)| *end == trimmed.len())
1704
+ .map(|(value, _, _)| value)
1705
+ }
1706
+
564
1707
  fn secret_binding_identifier(identifier: &str) -> bool {
565
1708
  let lower = identifier.to_ascii_lowercase();
566
1709
  [
@@ -586,6 +1729,69 @@ fn secret_binding_identifier(identifier: &str) -> bool {
586
1729
  .any(|suffix| lower == *suffix || lower.ends_with(suffix))
587
1730
  }
588
1731
 
1732
+ fn stripe_secret_binding_context(source: &str, index: usize) -> bool {
1733
+ literal_binding_name(source, index).is_some_and(|identifier| {
1734
+ identifier
1735
+ .chars()
1736
+ .filter(|character| *character != '_')
1737
+ .collect::<String>()
1738
+ .eq_ignore_ascii_case("stripeSecretKey")
1739
+ })
1740
+ }
1741
+
1742
+ fn stripe_secret_prefix(value: &str) -> bool {
1743
+ value.starts_with("sk_test_") || value.starts_with("sk_live_")
1744
+ }
1745
+
1746
+ fn stripe_secret_name(value: &str) -> bool {
1747
+ value
1748
+ .chars()
1749
+ .filter(|character| !matches!(character, '_' | '-'))
1750
+ .collect::<String>()
1751
+ .eq_ignore_ascii_case("stripeSecretKey")
1752
+ }
1753
+
1754
+ fn oauth_endpoint_metadata_context(source: &str, index: usize, value: &str) -> bool {
1755
+ if oauth_endpoint_name(value) && literal_is_map_key(source, index) {
1756
+ return true;
1757
+ }
1758
+ let Some(identifier) = literal_binding_name(source, index) else {
1759
+ return false;
1760
+ };
1761
+ oauth_endpoint_name(&identifier)
1762
+ && matches_url_scheme(value)
1763
+ && !literal_has_embedded_url_credentials(value)
1764
+ }
1765
+
1766
+ fn oauth_endpoint_name(value: &str) -> bool {
1767
+ let normalized = value
1768
+ .chars()
1769
+ .filter(|character| !matches!(character, '_' | '-'))
1770
+ .collect::<String>();
1771
+ matches!(
1772
+ normalized.to_ascii_lowercase().as_str(),
1773
+ "authorizationendpoint" | "tokenendpoint"
1774
+ )
1775
+ }
1776
+
1777
+ fn literal_is_map_key(source: &str, index: usize) -> bool {
1778
+ read_string(source, index).is_some_and(|(_, _, end)| {
1779
+ source
1780
+ .get(end..)
1781
+ .is_some_and(|rest| rest.trim_start().starts_with(':'))
1782
+ })
1783
+ }
1784
+
1785
+ fn matches_url_scheme(value: &str) -> bool {
1786
+ let lower = value.to_ascii_lowercase();
1787
+ lower.starts_with("https://") || lower.starts_with("http://")
1788
+ }
1789
+
1790
+ fn oauth_endpoint_url_context(source: &str, index: usize, value: &str) -> bool {
1791
+ matches_url_scheme(value)
1792
+ && literal_binding_name(source, index).is_some_and(|name| oauth_endpoint_name(&name))
1793
+ }
1794
+
589
1795
  fn named_argument_context(source: &str, index: usize, name: &str) -> bool {
590
1796
  let Some(context) = literal_argument_context(source, index) else {
591
1797
  return false;
@@ -1080,7 +2286,7 @@ fn benign_secret_named_literal(value: &str, secret_binding_name: bool) -> bool {
1080
2286
  || literal_looks_like_validation_copy(value)
1081
2287
  || literal_looks_like_operational_copy(value);
1082
2288
  (route_or_reset_url
1083
- && !literal_has_secret_like_url_parameter(value)
2289
+ && !literal_has_embedded_url_credentials(value)
1084
2290
  && !literal_has_secret_like_reset_path_segment(value))
1085
2291
  || (benign_copy && !secret_binding_name && !literal_has_concrete_token_like_segment(value))
1086
2292
  }
@@ -1123,15 +2329,41 @@ fn literal_has_secret_like_url_parameter(value: &str) -> bool {
1123
2329
  })
1124
2330
  }
1125
2331
 
2332
+ fn literal_has_embedded_url_credentials(value: &str) -> bool {
2333
+ literal_has_url_userinfo(value) || literal_has_secret_like_url_parameter(value)
2334
+ }
2335
+
2336
+ fn literal_has_url_userinfo(value: &str) -> bool {
2337
+ let trimmed = value.trim();
2338
+ let Some(authority_start) = trimmed.find("://").map(|index| index + 3) else {
2339
+ return false;
2340
+ };
2341
+ let authority_end = trimmed[authority_start..]
2342
+ .find(['/', '?', '#'])
2343
+ .map_or(trimmed.len(), |index| authority_start + index);
2344
+ trimmed[authority_start..authority_end]
2345
+ .split_once('@')
2346
+ .is_some_and(|(userinfo, host)| !userinfo.is_empty() && !host.is_empty())
2347
+ }
2348
+
1126
2349
  fn segment_has_secret_like_url_parameter(segment: &str) -> bool {
1127
2350
  segment.split('&').any(|parameter| {
1128
2351
  let Some((name, value)) = parameter.split_once('=') else {
1129
2352
  return false;
1130
2353
  };
1131
- has_secret_like_name(name) && concrete_url_parameter_value(value)
2354
+ url_parameter_name_is_credential(name) && concrete_url_parameter_value(value)
1132
2355
  })
1133
2356
  }
1134
2357
 
2358
+ fn url_parameter_name_is_credential(name: &str) -> bool {
2359
+ let normalized = name
2360
+ .chars()
2361
+ .filter(|character| !matches!(character, '_' | '-'))
2362
+ .collect::<String>()
2363
+ .to_ascii_lowercase();
2364
+ has_secret_like_name(name) || matches!(normalized.as_str(), "code" | "codeverifier")
2365
+ }
2366
+
1135
2367
  fn concrete_url_parameter_value(value: &str) -> bool {
1136
2368
  let trimmed = value.trim();
1137
2369
  if trimmed.len() < 8
@@ -1483,3 +2715,36 @@ fn location_for_index(source: &str, index: usize) -> Location {
1483
2715
  .map_or(index, |position| index - position - 1);
1484
2716
  Location { line, column }
1485
2717
  }
2718
+
2719
+ #[cfg(test)]
2720
+ mod tests {
2721
+ use std::path::Path;
2722
+
2723
+ use super::*;
2724
+
2725
+ #[test]
2726
+ fn fixed_runtime_lookup_crosses_a_class_without_a_matching_member() {
2727
+ let source = r"import 'dart:io';
2728
+ final dartExe = Platform.resolvedExecutable;
2729
+ class Runner {
2730
+ Future<Process> start() => Process.start(dartExe, const ['/path/to/snapshot']);
2731
+ }
2732
+ ";
2733
+ let parsed = parse_dart_source_lossy(Path::new("lib/main.dart"), source)
2734
+ .unwrap_or_else(|error| panic!("parse fixture: {error}"));
2735
+ let index = source
2736
+ .find("Process.start")
2737
+ .unwrap_or_else(|| panic!("process call"));
2738
+ let call = call_inside_after(source, index + "Process.start(".len())
2739
+ .unwrap_or_else(|| panic!("process arguments"));
2740
+ assert_eq!(
2741
+ lexical_binding_value(parsed.tree().root_node(), parsed.source(), index, "dartExe"),
2742
+ Some("Platform.resolvedExecutable")
2743
+ );
2744
+ assert!(resolved_dart_runtime_start(
2745
+ Some((parsed.tree().root_node(), parsed.source())),
2746
+ index,
2747
+ &call,
2748
+ ));
2749
+ }
2750
+ }