2020-03-28 14:16:57 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
pub mod class;
|
|
|
|
pub mod r#enum;
|
|
|
|
pub mod function;
|
|
|
|
pub mod interface;
|
|
|
|
pub mod module;
|
|
|
|
pub mod namespace;
|
|
|
|
mod node;
|
2020-04-08 11:03:42 -04:00
|
|
|
pub mod params;
|
2020-03-28 14:16:57 -04:00
|
|
|
pub mod parser;
|
|
|
|
pub mod printer;
|
|
|
|
pub mod ts_type;
|
2020-04-08 11:03:42 -04:00
|
|
|
pub mod ts_type_param;
|
2020-03-28 14:16:57 -04:00
|
|
|
pub mod type_alias;
|
|
|
|
pub mod variable;
|
|
|
|
|
|
|
|
pub use node::DocNode;
|
|
|
|
pub use node::DocNodeKind;
|
|
|
|
pub use node::Location;
|
|
|
|
pub use node::ParamDef;
|
2020-04-08 11:03:42 -04:00
|
|
|
pub use node::ParamKind;
|
2020-03-28 14:16:57 -04:00
|
|
|
pub use parser::DocParser;
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
|
|
|
|
2020-06-09 08:12:47 -04:00
|
|
|
pub fn find_nodes_by_name_recursively(
|
2020-03-28 14:16:57 -04:00
|
|
|
doc_nodes: Vec<DocNode>,
|
|
|
|
name: String,
|
2020-06-09 08:12:47 -04:00
|
|
|
) -> Vec<DocNode> {
|
2020-03-28 14:16:57 -04:00
|
|
|
let mut parts = name.splitn(2, '.');
|
|
|
|
let name = parts.next();
|
|
|
|
let leftover = parts.next();
|
2020-06-09 08:12:47 -04:00
|
|
|
if name.is_none() {
|
|
|
|
return doc_nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
let name = name.unwrap();
|
|
|
|
let doc_nodes = find_nodes_by_name(doc_nodes, name.to_string());
|
|
|
|
|
|
|
|
let mut found: Vec<DocNode> = vec![];
|
|
|
|
match leftover {
|
|
|
|
Some(leftover) => {
|
|
|
|
for node in doc_nodes {
|
|
|
|
let children = find_children_by_name(node, leftover.to_string());
|
|
|
|
found.extend(children);
|
2020-03-28 14:16:57 -04:00
|
|
|
}
|
2020-06-09 08:12:47 -04:00
|
|
|
found
|
|
|
|
}
|
|
|
|
None => doc_nodes,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn find_nodes_by_name(doc_nodes: Vec<DocNode>, name: String) -> Vec<DocNode> {
|
|
|
|
let mut found: Vec<DocNode> = vec![];
|
|
|
|
for node in doc_nodes {
|
|
|
|
if node.name == name {
|
|
|
|
found.push(node);
|
|
|
|
}
|
2020-03-28 14:16:57 -04:00
|
|
|
}
|
2020-06-09 08:12:47 -04:00
|
|
|
found
|
2020-03-28 14:16:57 -04:00
|
|
|
}
|
|
|
|
|
2020-06-09 08:12:47 -04:00
|
|
|
fn find_children_by_name(node: DocNode, name: String) -> Vec<DocNode> {
|
|
|
|
match node.kind {
|
|
|
|
DocNodeKind::Namespace => {
|
|
|
|
let namespace_def = node.namespace_def.unwrap();
|
|
|
|
find_nodes_by_name_recursively(namespace_def.elements, name)
|
|
|
|
}
|
|
|
|
// TODO(#4516) handle class, interface etc...
|
|
|
|
_ => vec![],
|
2020-03-28 14:16:57 -04:00
|
|
|
}
|
|
|
|
}
|