Skip to content

Commit

Permalink
fix: Support seq-of-maps merge key values (#321)
Browse files Browse the repository at this point in the history
Fixes #320
  • Loading branch information
jjkavalam committed Oct 19, 2021
1 parent 697b4b3 commit daaa5b4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/nodes/addPairToJSMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function addPairToJSMap(
{ key, value }: Pair
) {
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
value = isAlias(value) ? value.resolve(ctx.doc) : value
if (isSeq(value)) for (const it of value.items) mergeToJSMap(ctx, map, it)
else if (Array.isArray(value))
for (const it of value) mergeToJSMap(ctx, map, it)
Expand Down
10 changes: 10 additions & 0 deletions tests/doc/anchors.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ describe('merge <<', () => {
])
})

test('alias is associated with a sequence', () => {
const res = YAML.parse(
'- &items [{ a: A }, { b: B }]\n- { <<: *items, c: C }',
{
merge: true
}
)
expect(res[1]).toEqual({ a: 'A', b: 'B', c: 'C' })
})

describe('non-alias merges', () => {
test('single map', () => {
const res = YAML.parse('{ <<: { a: A }, b: B }', { merge: true })
Expand Down

0 comments on commit daaa5b4

Please sign in to comment.