Skip to content

Commit 8d005f9

Browse files
authored
Always allow merge key in mapping (#313)
1 parent bbe8648 commit 8d005f9

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/options.test.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import { parse } from "./parse.ts";
22

3+
// `<<` is a special key in YAML 1.1
4+
// https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/merge.ts
5+
test(`duplicate '<<' keys should always be allowed`, () => {
6+
const text = "<<: 1\n<<: 2";
7+
expect(parse(text)).toBeDefined();
8+
expect(parse(text, { uniqueKeys: false })).toBeDefined();
9+
const ast = parse(text, { uniqueKeys: true });
10+
expect(ast).toBeDefined();
11+
const node = ast.children[0].children[1].children[0];
12+
expect(node?.type).toBe("mapping");
13+
});
14+
315
for (const { type, text } of [
416
{ type: "mapping", text: "a: 1\na: 2" },
5-
// `<<` is a special key in YAML 1.1
6-
// https://github.com/eemeli/yaml/blob/main/src/schema/yaml-1.1/merge.ts
7-
// { type: "mapping", text: "<<: 1\n<<: 2" },
817
{ type: "flowMapping", text: `{"a":1,"a":2}` },
918
{ type: "flowMapping", text: `{"a":1,'a':2}` },
19+
{ type: "flowMapping", text: `{"<<":1,"<<":2}` },
1020
]) {
1121
test(`(${type}): duplicate keys in ${text}`, () => {
1222
expect(() => parse(text)).toThrowError(`Map keys must be unique`);

src/parse.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function parse(text: string, options?: ParseOptions): Root {
1818
// https://eemeli.org/yaml/#options
1919
uniqueKeys: options?.uniqueKeys,
2020
lineCounter,
21+
merge: true,
2122
});
2223
const parsedDocuments: YAML.Document.Parsed[] = [];
2324
const cstTokens = [...parser.parse(text)];

0 commit comments

Comments
 (0)