Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mock.module('../../../../utils/generators.mjs', {
{ version: '18.0.0', isLts: true, isCurrent: false },
{ version: '19.0.0', isLts: false, isCurrent: true },
],
leftHandAssign: Object.assign,
getVersionFromSemVer: version => version.split('.')[0],
getVersionURL: (version, api) => `/api/${version}/${api}`,
},
Expand Down
10 changes: 6 additions & 4 deletions src/generators/legacy-json/utils/parseList.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
TYPE_EXPRESSION,
} from '../constants.mjs';
import parseSignature from './parseSignature.mjs';
import { leftHandAssign } from '../../../utils/generators.mjs';
import createQueries from '../../../utils/queries/index.mjs';
import { transformNodesToString } from '../../../utils/unist.mjs';

Expand Down Expand Up @@ -95,6 +96,10 @@ export function parseList(section, nodes) {
// Update the section based on its type and parsed values
switch (section.type) {
case 'ctor':
// Constructors are their own signatures
leftHandAssign(section, parseSignature(section.textRaw, values));
break;

case 'classMethod':
case 'method':
// For methods and constructors, parse and attach signatures
Expand All @@ -104,10 +109,7 @@ export function parseList(section, nodes) {
case 'property':
// For properties, update type and other details if values exist
if (values.length) {
const { type, ...rest } = values[0];
section.type = type;
Object.assign(section, rest);
section.textRaw = `\`${section.name}\` ${section.textRaw}`;
leftHandAssign(section, values[0]);
}
break;

Expand Down
13 changes: 13 additions & 0 deletions src/utils/generators.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,16 @@ export const sortChanges = (changes, key = 'version') => {
return compare(coerceSemVer(aVersion), coerceSemVer(bVersion));
});
};

/**
* Assigns properties from one or more source objects to the target object
* **without overwriting existing keys** in the target.
*
* Similar to `Object.assign`, but preserves the target's existing keys.
* The target object is mutated in place.
*
* @param {Object} target - The object to assign properties to.
* @param {Object} source - The source object
*/
export const leftHandAssign = (target, source) =>
Object.keys(source).forEach(k => k in target || (target[k] = source[k]));
Loading