js-yaml icon indicating copy to clipboard operation
js-yaml copied to clipboard

Merge keys shouldn’t be supported by default

Open remcohaszing opened this issue 3 years ago • 2 comments

Support for merge keys was removed in YAML 1.2. However, this is still supported in js-yaml.

See changes in version 1.2

Since js-yaml aims to be YAML 1.2 compatible, it should treat << as a regular key.

Given the following script:

const yaml = require('js-yaml');

console.dir(yaml.load(`
foo: &foo
  f: oo

bar:
 <<: *foo
`))

Expected output:

{ foo: { f: 'oo' }, bar: { '<<': { f: 'oo' } } }

Actual output:

{ foo: { f: 'oo' }, bar: { f: 'oo' } }

I realize many people expect this to work the way as it does now, so a fix should be considered carefully, possibly in a major version release.

remcohaszing avatar Nov 16 '21 09:11 remcohaszing

I would recommend to make this feature an option instead of removing it completely. There's nothing in 1.2 that can replace this feature, and if an app clearly documents that this is supported in its YAML files, then it should be fine to use. Ideally it should be off by default, but that could break stuff of course.

perlpunk avatar Nov 16 '21 12:11 perlpunk

There are a lot of projects which could benefit from anchor merging. Where do I sign to make it optional, as well ?

Mentioned about yarn previously, and here #561 as well.

yuriy-yarosh avatar Jan 03 '24 03:01 yuriy-yarosh