2020-03-28 14:16:57 -04:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_common;
|
2020-03-28 14:16:57 -04:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
#[derive(Debug, PartialEq, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum DocNodeKind {
|
|
|
|
Function,
|
|
|
|
Variable,
|
|
|
|
Class,
|
|
|
|
Enum,
|
|
|
|
Interface,
|
|
|
|
TypeAlias,
|
|
|
|
Namespace,
|
|
|
|
}
|
|
|
|
|
2020-04-08 11:03:42 -04:00
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub enum ParamKind {
|
|
|
|
Identifier,
|
|
|
|
Rest,
|
|
|
|
Array,
|
|
|
|
Object,
|
|
|
|
}
|
|
|
|
|
2020-03-28 14:16:57 -04:00
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct ParamDef {
|
|
|
|
pub name: String,
|
2020-04-08 11:03:42 -04:00
|
|
|
pub kind: ParamKind,
|
2020-04-13 18:07:06 -04:00
|
|
|
pub optional: bool,
|
2020-03-28 14:16:57 -04:00
|
|
|
pub ts_type: Option<super::ts_type::TsTypeDef>,
|
|
|
|
}
|
|
|
|
|
2020-05-29 10:32:15 -04:00
|
|
|
#[derive(Debug, Serialize, Clone, PartialEq)]
|
2020-03-28 14:16:57 -04:00
|
|
|
pub struct Location {
|
|
|
|
pub filename: String,
|
|
|
|
pub line: usize,
|
|
|
|
pub col: usize,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Into<Location> for swc_common::Loc {
|
|
|
|
fn into(self) -> Location {
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_common::FileName::*;
|
2020-03-28 14:16:57 -04:00
|
|
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 13:47:06 -04:00
|
|
|
#[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<String>),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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<DocNode>,
|
|
|
|
pub reexports: Vec<Reexport>,
|
|
|
|
}
|
|
|
|
|
2020-03-28 14:16:57 -04:00
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct DocNode {
|
|
|
|
pub kind: DocNodeKind,
|
|
|
|
pub name: String,
|
|
|
|
pub location: Location,
|
|
|
|
pub js_doc: Option<String>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub function_def: Option<super::function::FunctionDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub variable_def: Option<super::variable::VariableDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub enum_def: Option<super::r#enum::EnumDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub class_def: Option<super::class::ClassDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub type_alias_def: Option<super::type_alias::TypeAliasDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub namespace_def: Option<super::namespace::NamespaceDef>,
|
|
|
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub interface_def: Option<super::interface::InterfaceDef>,
|
|
|
|
}
|