mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
feat(query) add declaration field to VarRef (#774)
This commit is contained in:
parent
29f8c02258
commit
2b1e535e6d
2 changed files with 28 additions and 1 deletions
|
|
@ -3504,6 +3504,7 @@ pub(super) fn resolve_var_ref_edge<'a, 'b: 'a>(
|
|||
) -> ContextOutcomeIterator<'a, Vertex<'b>, VertexIterator<'a, Vertex<'b>>> {
|
||||
match edge_name {
|
||||
"span" => var_ref::span(contexts, resolve_info),
|
||||
"declaration" => var_ref::declaration(contexts, resolve_info, adapter),
|
||||
"ancestor" => ancestors(contexts, adapter),
|
||||
"parent" => parents(contexts, adapter),
|
||||
"strip_parens" => strip_parens(contexts, parameters),
|
||||
|
|
@ -3515,11 +3516,35 @@ pub(super) fn resolve_var_ref_edge<'a, 'b: 'a>(
|
|||
|
||||
mod var_ref {
|
||||
use trustfall::provider::{
|
||||
ContextIterator, ContextOutcomeIterator, ResolveEdgeInfo, VertexIterator,
|
||||
resolve_neighbors_with, ContextIterator, ContextOutcomeIterator, ResolveEdgeInfo,
|
||||
VertexIterator,
|
||||
};
|
||||
|
||||
use crate::Adapter;
|
||||
|
||||
use super::{super::vertex::Vertex, get_span};
|
||||
|
||||
pub(super) fn declaration<'a, 'b: 'a>(
|
||||
contexts: ContextIterator<'a, Vertex<'b>>,
|
||||
_resolve_info: &ResolveEdgeInfo,
|
||||
adapter: &'a Adapter<'b>,
|
||||
) -> ContextOutcomeIterator<'a, Vertex<'b>, VertexIterator<'a, Vertex<'b>>> {
|
||||
resolve_neighbors_with(contexts, |v| {
|
||||
let var_ref = v
|
||||
.as_var_ref()
|
||||
.unwrap_or_else(|| panic!("expected to have a varref vertex, instead have: {v:#?}"))
|
||||
.identifier_reference;
|
||||
let v = var_ref
|
||||
.reference_id
|
||||
.get()
|
||||
.and_then(|x| adapter.semantic.symbols().references.get(x))
|
||||
.and_then(oxc_semantic::Reference::symbol_id)
|
||||
.map(|x| adapter.semantic.symbol_declaration(x));
|
||||
|
||||
Box::new(v.into_iter().map(|x| (*x).into()))
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) fn span<'a, 'b: 'a>(
|
||||
contexts: ContextIterator<'a, Vertex<'b>>,
|
||||
_resolve_info: &ResolveEdgeInfo,
|
||||
|
|
|
|||
|
|
@ -823,6 +823,7 @@ type FnDeclarationAST implements Function & ASTNode & FnDeclaration & HasSpan &
|
|||
|
||||
interface VarRef implements HasSpan & Expression {
|
||||
name: String!
|
||||
declaration: ASTNode
|
||||
# Expression
|
||||
as_constant_string: String
|
||||
"""
|
||||
|
|
@ -835,6 +836,7 @@ interface VarRef implements HasSpan & Expression {
|
|||
|
||||
type VarRefAST implements HasSpan & Expression & VarRef & ASTNode {
|
||||
name: String!
|
||||
declaration: ASTNode
|
||||
# ASTNode
|
||||
parent: ASTNode
|
||||
ancestor: [ASTNode!]!
|
||||
|
|
|
|||
Loading…
Reference in a new issue