Skip to content

Commit 013fca0

Browse files
authored
fix(cli): reorder falsy keys (#968)
1 parent 8b306bc commit 013fca0

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

.changeset/sour-owls-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"lingo.dev": patch
3+
---
4+
5+
reorder falsy keys

packages/cli/src/cli/loaders/ensure-key-order.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,38 @@ describe("ensure-key-order loader", () => {
1919
expect(result).toEqual({ a: 11, b: 22, c: 33 });
2020
});
2121

22+
it("should reorder falsy keys to match original input order on push", async () => {
23+
const originalInput = {
24+
a: 1,
25+
b: 0,
26+
c: null,
27+
d: "a",
28+
e: false,
29+
g: "",
30+
h: undefined,
31+
};
32+
await loader.pull("en", originalInput);
33+
const data = {
34+
b: 0,
35+
a: 11,
36+
c: null,
37+
d: "b",
38+
e: false,
39+
g: "",
40+
h: undefined,
41+
};
42+
const result = await loader.push("en", data);
43+
expect(result).toEqual({
44+
a: 11,
45+
b: 0,
46+
c: null,
47+
d: "b",
48+
e: false,
49+
g: "",
50+
h: undefined,
51+
});
52+
});
53+
2254
it("should handle nested objects and preserve key order", async () => {
2355
const originalInput = { x: { b: 2, a: 1 }, y: 3, z: { d: 9, f: 7, e: 8 } };
2456
await loader.pull("en", originalInput);

packages/cli/src/cli/loaders/ensure-key-order.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ function reorderKeys(
3333

3434
for (const key of originalKeys) {
3535
if (dataKeys.has(key)) {
36-
if (data[key]) {
37-
orderedData[key] = reorderKeys(data[key], originalInput[key]);
38-
}
36+
orderedData[key] = reorderKeys(data[key], originalInput[key]);
3937
dataKeys.delete(key);
4038
}
4139
}

packages/cli/src/cli/loaders/unlocalizable.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ describe("unlocalizable loader", () => {
77
num: 1,
88
numStr: "1.0",
99
empty: "",
10-
bool: true,
10+
boolTrue: true,
11+
boolFalse: false,
1112
boolStr: "false",
1213
isoDate: "2025-02-21",
1314
isoDateTime: "2025-02-21T00:00:00.000Z",
@@ -57,7 +58,8 @@ describe("unlocalizable loader", () => {
5758
unlocalizable: {
5859
num: 1,
5960
empty: "",
60-
bool: true,
61+
boolTrue: true,
62+
boolFalse: false,
6163
isoDate: "2025-02-21",
6264
isoDateTime: "2025-02-21T00:00:00.000Z",
6365
url: "https://example.com",

0 commit comments

Comments
 (0)