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_ecma_ast;
|
2020-03-28 14:16:57 -04:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use super::parser::DocParser;
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct EnumMemberDef {
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize, Clone)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct EnumDef {
|
|
|
|
pub members: Vec<EnumMemberDef>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_doc_for_ts_enum_decl(
|
|
|
|
_doc_parser: &DocParser,
|
|
|
|
enum_decl: &swc_ecma_ast::TsEnumDecl,
|
|
|
|
) -> (String, EnumDef) {
|
|
|
|
let enum_name = enum_decl.id.sym.to_string();
|
|
|
|
let mut members = vec![];
|
|
|
|
|
|
|
|
for enum_member in &enum_decl.members {
|
2020-04-03 12:35:03 -04:00
|
|
|
use crate::swc_ecma_ast::TsEnumMemberId::*;
|
2020-03-28 14:16:57 -04:00
|
|
|
|
|
|
|
let member_name = match &enum_member.id {
|
|
|
|
Ident(ident) => ident.sym.to_string(),
|
|
|
|
Str(str_) => str_.value.to_string(),
|
|
|
|
};
|
|
|
|
|
|
|
|
let member_def = EnumMemberDef { name: member_name };
|
|
|
|
members.push(member_def);
|
|
|
|
}
|
|
|
|
|
|
|
|
let enum_def = EnumDef { members };
|
|
|
|
|
|
|
|
(enum_name, enum_def)
|
|
|
|
}
|