File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
generators/legacy-json/utils Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change 55 TYPE_EXPRESSION ,
66} from '../constants.mjs' ;
77import parseSignature from './parseSignature.mjs' ;
8+ import { leftHandAssign } from '../../../utils/generators.mjs' ;
89import createQueries from '../../../utils/queries/index.mjs' ;
910import { 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 ;
Original file line number Diff line number Diff 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 ] ) ) ;
You can’t perform that action at this time.
0 commit comments