use tree_sitter::Node;
use super::builder::Builder;
use super::{IntroKind, ScopeId, Write, WriteKind};
impl Builder<'_> {
pub(super) fn collect_masgn_targets(&mut self, list: Node, scope: ScopeId) {
let mut cursor = list.walk();
for child in list.children(&mut cursor) {
match child.kind() {
"identifier" => self.bind_masgn_target(child, scope),
"rest_assignment" | "destructured_left_assignment_list" => {
self.collect_masgn_targets_inner(child, scope);
}
_ => {}
}
}
}
fn collect_masgn_targets_inner(&mut self, list: Node, scope: ScopeId) {
let mut cursor = list.walk();
for child in list.children(&mut cursor) {
if child.kind() == "identifier" {
self.bind_masgn_target(child, scope);
} else if child.named_child_count() > 0 && child.kind() != "integer" {
self.collect_masgn_targets_inner(child, scope);
}
}
}
fn bind_masgn_target(&mut self, ident: Node, scope: ScopeId) {
let name = self.text(ident).to_string();
let w = Write {
byte: ident.start_byte(),
node_id: ident.id(),
kind: WriteKind::Masgn,
rhs: None,
};
self.record_write(scope, &name, w, IntroKind::Binding);
}
}