diff --git a/yaml/_loader_state.ts b/yaml/_loader_state.ts index 918ab5f68..cd0375bb2 100644 --- a/yaml/_loader_state.ts +++ b/yaml/_loader_state.ts @@ -348,6 +348,28 @@ export class LoaderState { } return false; } + mergeMappings( + destination: Record, + source: Record, + overridableKeys: Set, + ) { + if (!isObject(source)) { + return this.throwError( + "cannot merge mappings; the provided source object is unacceptable", + ); + } + + for (const [key, value] of Object.entries(source)) { + if (Object.hasOwn(destination, key)) continue; + Object.defineProperty(destination, key, { + value, + writable: true, + enumerable: true, + configurable: true, + }); + overridableKeys.add(key); + } + } readDocument() { const documentStart = this.position; @@ -475,30 +497,6 @@ export class LoaderState { } } -function mergeMappings( - state: LoaderState, - destination: Record, - source: Record, - overridableKeys: Set, -) { - if (!isObject(source)) { - return state.throwError( - "cannot merge mappings; the provided source object is unacceptable", - ); - } - - for (const [key, value] of Object.entries(source)) { - if (Object.hasOwn(destination, key)) continue; - Object.defineProperty(destination, key, { - value, - writable: true, - enumerable: true, - configurable: true, - }); - overridableKeys.add(key); - } -} - function storeMappingPair( state: LoaderState, result: Record | null, @@ -552,11 +550,10 @@ function storeMappingPair( index < valueNode.length; index++ ) { - mergeMappings(state, result, valueNode[index], overridableKeys); + state.mergeMappings(result, valueNode[index], overridableKeys); } } else { - mergeMappings( - state, + state.mergeMappings( result, valueNode as Record, overridableKeys,