fn get_associated_elements()

in src/models/matches.rs [183:220]


  fn get_associated_elements(
    &mut self, node: &Node, code: &String, piranha_arguments: &PiranhaArguments, trailing: bool,
  ) {
    let mut current_node = *node;
    let mut buf = *piranha_arguments.cleanup_comments_buffer();
    loop {
      // If we are looking for trailing elements, we start from the next sibling of the node
      // Else we start from the previous sibling of the node
      while let Some(sibling) = if trailing {
        current_node.next_sibling()
      } else {
        current_node.prev_sibling()
      } {
        // Check if the sibling is a comma
        if !self.found_comma() && self.is_comma_safe_to_delete(&sibling, code, trailing) {
          // Add the comma to the associated matches
          self.associated_comma = Some(sibling.range().into());
          current_node = sibling;
          continue; // Continue the inner loop (i.e. evaluate next sibling)
        } else if self._is_comment_safe_to_delete(&sibling, node, piranha_arguments, trailing) {
          // Add the comment to the associated matches
          self.associated_comments.push(sibling.range().into());
          current_node = sibling;
          continue; // Continue the inner loop (i.e. evaluate next sibling)
        }
        break; // Break the inner loop
      }

      let parent = current_node.parent();
      // If buf is <0 or we have found a comment and a comma, we break
      if buf < 0 || (self.found_comma() && self.found_comment()) || parent.is_none() {
        break; // Break the outer loop
      }
      current_node = parent.unwrap();
      buf -= 1;
      continue; // Continue the outer loop (i.e. lookup parent's siblings for comma/comment)
    }
  }