From 3fac487461abf055165fe0e2bb962573950277b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Sat, 28 Mar 2020 19:16:57 +0100 Subject: feat: Add "deno doc" subcommand (#4500) --- cli/doc/node.rs | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 cli/doc/node.rs (limited to 'cli/doc/node.rs') diff --git a/cli/doc/node.rs b/cli/doc/node.rs new file mode 100644 index 000000000..da4b81c11 --- /dev/null +++ b/cli/doc/node.rs @@ -0,0 +1,77 @@ +// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. +use serde::Serialize; +use swc_common; + +#[derive(Debug, PartialEq, Serialize, Clone)] +#[serde(rename_all = "camelCase")] +pub enum DocNodeKind { + Function, + Variable, + Class, + Enum, + Interface, + TypeAlias, + Namespace, +} + +#[derive(Debug, Serialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct ParamDef { + pub name: String, + pub ts_type: Option, +} + +#[derive(Debug, Serialize, Clone)] +pub struct Location { + pub filename: String, + pub line: usize, + pub col: usize, +} + +impl Into for swc_common::Loc { + fn into(self) -> Location { + use swc_common::FileName::*; + + let filename = match &self.file.name { + Real(path_buf) => path_buf.to_string_lossy().to_string(), + Custom(str_) => str_.to_string(), + _ => panic!("invalid filename"), + }; + + Location { + filename, + line: self.line, + col: self.col_display, + } + } +} + +#[derive(Debug, Serialize, Clone)] +#[serde(rename_all = "camelCase")] +pub struct DocNode { + pub kind: DocNodeKind, + pub name: String, + pub location: Location, + pub js_doc: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub function_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub variable_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub enum_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub class_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub type_alias_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub namespace_def: Option, + + #[serde(skip_serializing_if = "Option::is_none")] + pub interface_def: Option, +} -- cgit v1.2.3