@@ -10,7 +10,6 @@ import {
1010import { getScalarValue } from './parser_scalar.ts'
1111import { CORE_SCHEMA , type Schema } from '../schema.ts'
1212import {
13- MERGE_KEY ,
1413 NOT_RESOLVED ,
1514 type MappingTagDefinition ,
1615 type ScalarTagDefinition ,
@@ -21,6 +20,8 @@ import { tagNameFull } from '../common/tagname.ts'
2120
2221const NO_RANGE = - 1
2322
23+ const MERGE_TAG_NAME = 'tag:yaml.org,2002:merge'
24+
2425interface DocumentFrame {
2526 kind : 'document'
2627 position : number
@@ -46,6 +47,8 @@ interface MappingFrame {
4647 key : unknown
4748 keyPosition : number
4849 hasKey : boolean
50+ // The key slot drops its tag, but `<<` is recognized by tag, not by value.
51+ keyIsMerge : boolean
4952 // Keys brought in by a merge that an explicit pair is still allowed to
5053 // override. Lazily allocated: stays null for mappings without `<<`.
5154 overridable : Set < unknown > | null
@@ -276,7 +279,7 @@ function addMappingValue (state: ConstructorState, frame: MappingFrame, key: unk
276279 state . position = frame . keyPosition
277280
278281 // `<<` is intercepted before dedup, so a repeated merge key is allowed.
279- if ( key === MERGE_KEY ) {
282+ if ( frame . keyIsMerge ) {
280283 mergeSource ( state , frame , value , tag )
281284 return
282285 }
@@ -311,6 +314,7 @@ function addValue (state: ConstructorState, value: unknown, tag: AnyTag) {
311314 frame . key = value
312315 frame . keyPosition = state . position
313316 frame . hasKey = true
317+ frame . keyIsMerge = tag . tagName === MERGE_TAG_NAME
314318 }
315319}
316320
@@ -409,6 +413,7 @@ function constructFromEvents (events: Event[], options: ConstructorOptions): unk
409413 key : undefined ,
410414 keyPosition : state . position ,
411415 hasKey : false ,
416+ keyIsMerge : false ,
412417 overridable : null
413418 } )
414419 break
0 commit comments