Skip to content

Commit d881d36

Browse files
committed
fix eemeli#320; add tests
1 parent 4720524 commit d881d36

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/nodes/addPairToJSMap.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function addPairToJSMap(
1616
{ key, value }: Pair
1717
) {
1818
if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
19-
value = ctx && isAlias(value) ? value.resolve(ctx.doc) : value
19+
value = isAlias(value) ? value.resolve(ctx.doc) : value
2020
if (isSeq(value)) for (const it of value.items) mergeToJSMap(ctx, map, it)
2121
else if (Array.isArray(value))
2222
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)