Skip to content

Commit daaa5b4

Browse files
authored
fix: Support seq-of-maps merge key values (#321)
Fixes #320
1 parent 697b4b3 commit daaa5b4

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/nodes/addPairToJSMap.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export function addPairToJSMap(
1616
{ key, value }: Pair
1717
) {
1818
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
19+
value = isAlias(value) ? value.resolve(ctx.doc) : value
1920
if (isSeq(value)) for (const it of value.items) mergeToJSMap(ctx, map, it)
2021
else if (Array.isArray(value))
2122
for (const it of value) mergeToJSMap(ctx, map, it)

tests/doc/anchors.js

+10
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,16 @@ describe('merge <<', () => {
225225
])
226226
})
227227

228+
test('alias is associated with a sequence', () => {
229+
const res = YAML.parse(
230+
'- &items [{ a: A }, { b: B }]\n- { <<: *items, c: C }',
231+
{
232+
merge: true
233+
}
234+
)
235+
expect(res[1]).toEqual({ a: 'A', b: 'B', c: 'C' })
236+
})
237+
228238
describe('non-alias merges', () => {
229239
test('single map', () => {
230240
const res = YAML.parse('{ <<: { a: A }, b: B }', { merge: true })

0 commit comments

Comments
 (0)