use crate::query::match_ast;
use crate::syntax::builders::pair::build_pair_node;
use crate::syntax::fields::javascript::pair;
use crate::syntax::{SyntaxGraphArgs, SyntaxGraphError};
use crate::{CodeGraph, NodeId};
pub fn reader(
args: &mut SyntaxGraphArgs<'_>,
n_id: NodeId,
) -> Result<Option<NodeId>, SyntaxGraphError> {
let graph = args.ast_graph;
let mut key_id = args.required_field_alt(n_id, pair::KEY)?;
let value_id = args.required_field_alt(n_id, pair::VALUE)?;
if graph.label_type(key_id) == Some("computed_property_name") {
if let Some(inner_id) = match_ast(graph, key_id, &["[", "]"], None)
.get("__0__")
.copied()
.flatten()
{
key_id = inner_id;
}
}
build_pair_node(args, n_id, key_id, value_id).map(Some)
}