Skip to content

Commit a0d2baa

Browse files
author
skidy89
committed
corrected array type definitions
1 parent a0a5b55 commit a0d2baa

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

__test__/languages.d.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
// DO NOT EDIT MANUALLY OR ELSE IT WILL BE OVERWRITTEN
33

44
/* eslint-disable */
5-
65
export interface Lang {
6+
/**
7+
* [
8+
* "key1",
9+
* "key2",
10+
* "key3"
11+
* ]
12+
*/
13+
'array': string[];
714
/** hello world */
815
'hello': string;
916
/**
@@ -13,14 +20,6 @@ export interface Lang {
1320
* test"
1421
*/
1522
'test': string;
16-
/**
17-
* [
18-
* "key1",
19-
* "key2",
20-
* "key3"
21-
* ]
22-
*/
23-
'array': string;
2423
}
2524

2625
export interface Langs {

src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,24 +209,30 @@ pub fn generate_typescript_defs(dir: String, output: String) -> Result<()> {
209209
defs.push_str("// DO NOT EDIT MANUALLY OR ELSE IT WILL BE OVERWRITTEN\n\n");
210210
defs.push_str("/* eslint-disable */\n");
211211
defs.push_str("export interface Lang {\n");
212+
212213
if let Some(first_lang) = langs.values().next() {
213214
for key in first_lang.keys() {
214-
// add comments with the value
215215
if let Some(value) = first_lang.get(key) {
216-
let comment_lines: Vec<&str> = value.lines().collect();
217-
if comment_lines.len() == 1 {
218-
defs.push_str(&format!(" /** {} */\n", comment_lines[0]));
216+
let trimmed = value.trim();
217+
let cm: Vec<&str> = value.lines().collect();
218+
if cm.len() == 1 {
219+
defs.push_str(&format!(" /** {} */\n", cm[0]));
219220
} else {
220221
defs.push_str(" /**\n");
221-
for line in comment_lines {
222+
for line in cm {
222223
defs.push_str(&format!(" * {}\n", line));
223224
}
224225
defs.push_str(" */\n");
225226
}
227+
if trimmed.starts_with('[') && trimmed.ends_with(']') {
228+
defs.push_str(&format!(" '{}': string[];\n", key));
229+
} else {
230+
defs.push_str(&format!(" '{}': string;\n", key));
231+
}
226232
}
227-
defs.push_str(&format!(" '{}': string;\n", key));
228233
}
229234
}
235+
230236
defs.push_str("}\n\n");
231237
defs.push_str("export interface Langs {\n");
232238
for lang in langs.keys() {

0 commit comments

Comments
 (0)