Skip to content

Commit b906f9e

Browse files
committed
fix(legacy-json): misc promotion logic fix
Re nodejs/node#57343 (comment) Signed-off-by: flakey5 <[email protected]>
1 parent a97df05 commit b906f9e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

src/generators/legacy-json/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default {
6767
if (output) {
6868
await writeFile(
6969
join(output, `${node.api}.json`),
70-
JSON.stringify(section)
70+
JSON.stringify(section, null, 2)
7171
);
7272
}
7373
})

src/generators/legacy-json/utils/buildSection.mjs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
import { buildHierarchy } from './buildHierarchy.mjs';
23
import { parseList } from './parseList.mjs';
34
import { enforceArray } from '../../../utils/array.mjs';
@@ -116,11 +117,11 @@ export const createSectionBuilder = () => {
116117
// Only promote certain keys
117118
if (!UNPROMOTED_KEYS.includes(key)) {
118119
// Merge the section's properties into the parent section
119-
parent[key] = parent[key]
120-
? // If the parent already has this key, concatenate the values
121-
[].concat(parent[key], value)
122-
: // Otherwise, directly assign the section's value to the parent
123-
[];
120+
if (parent[key] && Array.isArray(parent[key])) {
121+
parent[key] = parent[key].concat(value);
122+
} else {
123+
parent[key] ||= value;
124+
}
124125
}
125126
});
126127
}

0 commit comments

Comments
 (0)