Skip to content

Commit 6ea914f

Browse files
authored
feat: handle JSDoc for ts type literals (#561)
1 parent 5a7101b commit 6ea914f

13 files changed

+250
-163
lines changed

src/js_doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ lazy_static! {
1919
static ref JS_DOC_TAG_TYPED_RE: Regex = Regex::new(r"(?s)^\s*@(enum|extends|augments|this|type|default)\s+\{([^}]+)\}(?:\s+(.+))?").unwrap();
2020
}
2121

22-
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
22+
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq)]
2323
pub struct JsDoc {
2424
#[serde(skip_serializing_if = "Option::is_none", default)]
2525
pub doc: Option<String>,

src/parser.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,6 +1291,7 @@ fn parse_json_module_type(value: &serde_json::Value) -> TsTypeDef {
12911291
.iter()
12921292
.map(|(key, value)| LiteralPropertyDef {
12931293
name: key.to_string(),
1294+
js_doc: Default::default(),
12941295
ts_type: Some(parse_json_module_type(value)),
12951296
params: Vec::new(),
12961297
readonly: false,

src/tests.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ async fn json_module() {
940940
"methods": [],
941941
"properties": [{
942942
"name": "a",
943+
"jsDoc": {},
943944
"params": [],
944945
"computed": false,
945946
"optional": false,
@@ -954,6 +955,7 @@ async fn json_module() {
954955
"typeParams": []
955956
}, {
956957
"name": "b",
958+
"jsDoc": {},
957959
"params": [],
958960
"computed": false,
959961
"optional": false,
@@ -968,6 +970,7 @@ async fn json_module() {
968970
"typeParams": []
969971
}, {
970972
"name": "c",
973+
"jsDoc": {},
971974
"params": [],
972975
"computed": false,
973976
"optional": false,
@@ -979,6 +982,7 @@ async fn json_module() {
979982
"typeParams": []
980983
}, {
981984
"name": "d",
985+
"jsDoc": {},
982986
"params": [],
983987
"computed": false,
984988
"optional": false,
@@ -994,6 +998,7 @@ async fn json_module() {
994998
"typeParams": []
995999
}, {
9961000
"name": "e",
1001+
"jsDoc": {},
9971002
"params": [],
9981003
"computed": false,
9991004
"optional": false,
@@ -1004,6 +1009,7 @@ async fn json_module() {
10041009
"methods": [],
10051010
"properties": [{
10061011
"name": "a",
1012+
"jsDoc": {},
10071013
"params": [],
10081014
"computed": false,
10091015
"optional": false,

0 commit comments

Comments
 (0)