js-yaml
js-yaml copied to clipboard
Merge keys shouldn’t be supported by default
Support for merge keys was removed in YAML 1.2. However, this is still supported in js-yaml
.
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.
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.
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.