Skip to content

Commit fbee3fe

Browse files
committed
fix: properly stringify arrays of tables
1 parent 0a42019 commit fbee3fe

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/stringify.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ function stringifyTable (tableKey: string | 0, obj: any, prefix: string, depth:
156156
let key = BARE_KEY.test(k) ? k : formatString(k)
157157

158158
if (type === 'array' && isArrayOfTables(obj[k])) {
159-
tables += stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat)
159+
tables += (tables && '\n') + stringifyArrayTable(obj[k], prefix ? `${prefix}.${key}` : key, depth - 1, numberAsFloat)
160160
} else if (type === 'object') {
161161
let tblKey = prefix ? `${prefix}.${key}` : key
162-
let table = stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat)
163-
tables += (tables && '\n') + table
162+
tables += (tables && '\n') + stringifyTable(tblKey, obj[k], tblKey, depth - 1, numberAsFloat)
164163
} else {
165164
preamble += key
166165
preamble += ' = '

test/stringify.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ tag = "fr"
197197
198198
[language.english]
199199
tag = "en"
200+
201+
[country]
202+
[planet]
203+
[[books]]
204+
title = "an amazing book"
205+
206+
[[books]]
207+
title = "another amazing book"
200208
`.trimStart()
201209

202210
expect(
@@ -212,6 +220,12 @@ tag = "en"
212220
french: { tag: 'fr' },
213221
english: { tag: 'en' },
214222
},
223+
country: {},
224+
planet: {},
225+
books: [
226+
{ title: "an amazing book" },
227+
{ title: "another amazing book" },
228+
]
215229
}),
216230
).toBe(expected)
217231
})

0 commit comments

Comments
 (0)