From 997eb26d3e294f46f9e288f8ee50ed71f7fb9220 Mon Sep 17 00:00:00 2001 From: u9g Date: Wed, 26 Jul 2023 21:46:49 -0400 Subject: [PATCH] feat(query): impl Typename for VariableDeclaration (#638) --- crates/oxc_query/src/lib.rs | 6 +++++- crates/oxc_query/src/vertex.rs | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/crates/oxc_query/src/lib.rs b/crates/oxc_query/src/lib.rs index ecd36f514..54d250d33 100644 --- a/crates/oxc_query/src/lib.rs +++ b/crates/oxc_query/src/lib.rs @@ -103,6 +103,7 @@ query { span_asmt_type_end: u64, entire_span_start: u64, entire_span_end: u64, + __typename: String, } let mut results: Vec = execute_query( @@ -120,6 +121,8 @@ query { } } + __typename @output + entire_span_: entire_span { start @output end @output @@ -142,7 +145,8 @@ query { span_asmt_type_start: 6, span_asmt_type_end: 11, entire_span_start: 6, - entire_span_end: 15 + entire_span_end: 15, + __typename: "VariableDeclarationAST".to_owned() }], results ); diff --git a/crates/oxc_query/src/vertex.rs b/crates/oxc_query/src/vertex.rs index e4ad88b50..ee4d2d7c3 100644 --- a/crates/oxc_query/src/vertex.rs +++ b/crates/oxc_query/src/vertex.rs @@ -176,7 +176,7 @@ impl Typename for Vertex<'_> { Vertex::TypeAnnotation(tn) => tn.typename(), Vertex::Type(_) => "Type", Vertex::Url(_) => "URL", - Vertex::VariableDeclaration(_) => "VariableDeclaration", + Vertex::VariableDeclaration(vd) => vd.typename(), Vertex::ReturnStatementAST(_) => "ReturnStatementAST", } } @@ -346,3 +346,9 @@ pub struct VariableDeclarationVertex<'a> { ast_node: Option>, pub variable_declaration: &'a VariableDeclarator<'a>, } + +impl<'a> Typename for VariableDeclarationVertex<'a> { + fn typename(&self) -> &'static str { + if self.ast_node.is_some() { "VariableDeclarationAST" } else { "VariableDeclaration" } + } +}