Skip to content

Commit a522abd

Browse files
committed
fix: prevent generating placeholders for array types in TypeScript definitions
1 parent fcbc477 commit a522abd

3 files changed

Lines changed: 20 additions & 6 deletions

File tree

__test__/e.lang

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,10 @@ array = [
1414
"key2",
1515
"key3"
1616
]
17-
test_placeholder = "This is a {placeholder} test."
17+
# it should not generate placeholder for array types
18+
test_placeholder = "This is a {placeholder} test."
19+
tested_array = [
20+
"value1",
21+
"value2 with {placeholder}",
22+
"value3",
23+
]

__test__/languages.d.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33

44
/* eslint-disable */
55
export interface Lang {
6+
/** This is a {placeholder} test. */
7+
'test_placeholder': (args: { placeholder: string }) => string;
8+
/**
9+
* [
10+
* "value1",
11+
* "value2 with {placeholder}",
12+
* "value3",
13+
* ]
14+
*/
15+
'tested_array': string[];
16+
/** hello world */
17+
'hello': string;
618
/**
719
* "this is
820
* a multi-line
921
* string
1022
* test"
1123
*/
1224
'test': string;
13-
/** hello world */
14-
'hello': string;
15-
/** This is a {placeholder} test. */
16-
'test_placeholder': (args: { placeholder: string }) => string;
1725
/**
1826
* [
1927
* "key1",

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub fn generate_typescript_defs(
238238
}
239239
}
240240
}
241-
if !placeholders.is_empty() && should_gen_placeholder {
241+
if !placeholders.is_empty() && should_gen_placeholder && !trimmed.starts_with('[') {
242242
defs.push_str(&format!(" '{}': (args: {{ ", key));
243243
for (i, p) in placeholders.iter().enumerate() {
244244
if i > 0 {

0 commit comments

Comments
 (0)