Skip to content

Commit 5e17d0c

Browse files
committed
fixup!
1 parent 4b87c4d commit 5e17d0c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
TYPE_EXPRESSION,
66
} from '../constants.mjs';
77
import parseSignature from './parseSignature.mjs';
8+
import { leftHandAssign } from '../../../utils/generators.mjs';
89
import createQueries from '../../../utils/queries/index.mjs';
910
import { transformNodesToString } from '../../../utils/unist.mjs';
1011

@@ -96,7 +97,7 @@ export function parseList(section, nodes) {
9697
switch (section.type) {
9798
case 'ctor':
9899
// Constructors are their own signatures
99-
Object.assign(section, parseSignature(section.textRaw, values));
100+
leftHandAssign(section, parseSignature(section.textRaw, values));
100101
break;
101102

102103
case 'classMethod':
@@ -110,7 +111,7 @@ export function parseList(section, nodes) {
110111
if (values.length) {
111112
const { type, ...rest } = values[0];
112113
section.type = type;
113-
Object.assign(section, rest);
114+
leftHandAssign(section, rest);
114115
section.textRaw = `\`${section.name}\` ${section.textRaw}`;
115116
}
116117
break;

src/utils/generators.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,16 @@ export const sortChanges = (changes, key = 'version') => {
9696
return compare(coerceSemVer(aVersion), coerceSemVer(bVersion));
9797
});
9898
};
99+
100+
/**
101+
* Assigns properties from one or more source objects to the target object
102+
* **without overwriting existing keys** in the target.
103+
*
104+
* Similar to `Object.assign`, but preserves the target's existing keys.
105+
* The target object is mutated in place.
106+
*
107+
* @param {Object} target - The object to assign properties to.
108+
* @param {Object} source - The source object
109+
*/
110+
export const leftHandAssign = (target, source) =>
111+
Object.keys(source).forEach(k => k in target || (target[k] = source[k]));

0 commit comments

Comments
 (0)