// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. use crate::swc_common; use serde::Serialize; #[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 enum ParamKind { Identifier, Rest, Array, Object, } #[derive(Debug, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct ParamDef { pub name: String, pub kind: ParamKind, pub optional: bool, pub ts_type: Option, } #[derive(Debug, Serialize, Clone, PartialEq)] pub struct Location { pub filename: String, pub line: usize, pub col: usize, } impl Into for swc_common::Loc { fn into(self) -> Location { use crate::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 enum ReexportKind { /// export * from "./path/to/module.js"; All, /// export * as someNamespace from "./path/to/module.js"; Namespace(String), /// export default from "./path/to/module.js"; Default, /// (identifier, optional alias) /// export { foo } from "./path/to/module.js"; /// export { foo as bar } from "./path/to/module.js"; Named(String, Option), } #[derive(Debug, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct Reexport { pub kind: ReexportKind, pub src: String, } #[derive(Debug, Serialize, Clone)] #[serde(rename_all = "camelCase")] pub struct ModuleDoc { pub exports: Vec, pub reexports: Vec, } #[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, }