Skip to content

Commit 8d93a10

Browse files
author
skidy89
committed
added comments to the parser
1 parent b94cc97 commit 8d93a10

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

__test__/languages.d.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
/* eslint-disable */
55

66
export interface Lang {
7-
'hello': string;
7+
/**
8+
* this is
9+
* a multi-line
10+
* string
11+
* test
12+
*/
813
'test': string;
14+
/** hello world */
15+
'hello': string;
916
}
1017

1118
export interface Langs {

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,19 @@ pub fn generate_typescript_defs(dir: String, output: String) -> Result<()> {
203203
defs.push_str("export interface Lang {\n");
204204
if let Some(first_lang) = langs.values().next() {
205205
for key in first_lang.keys() {
206+
// add comments with the value
207+
if let Some(value) = first_lang.get(key) {
208+
let comment_lines: Vec<&str> = value.lines().collect();
209+
if comment_lines.len() == 1 {
210+
defs.push_str(&format!(" /** {} */\n", comment_lines[0]));
211+
} else {
212+
defs.push_str(" /**\n");
213+
for line in comment_lines {
214+
defs.push_str(&format!(" * {}\n", line));
215+
}
216+
defs.push_str(" */\n");
217+
}
218+
}
206219
defs.push_str(&format!(" '{}': string;\n", key));
207220
}
208221
}

0 commit comments

Comments
 (0)