From a7cf442bf9b819cae3ce6cd269b2524d69350f04 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 4 Jul 2024 09:39:27 +1000 Subject: [PATCH 1/2] BREAKING(yaml): rename `ParseOptions.json` to `ParseOptions.allowDuplicateKeys` --- yaml/_loader.ts | 10 +++++----- yaml/parse.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yaml/_loader.ts b/yaml/_loader.ts index a8532fcb63a5..d0237259a5bc 100644 --- a/yaml/_loader.ts +++ b/yaml/_loader.ts @@ -63,7 +63,7 @@ interface LoaderStateOptions { /** specifies a schema to use. */ schema?: Schema; /** compatibility with JSON.parse behaviour. */ - json?: boolean; + allowDuplicateKeys?: boolean; /** function to call on warning messages. */ onWarning?(this: null, e?: YamlError): void; } @@ -80,7 +80,7 @@ class LoaderState { position = 0; line = 0; onWarning?: (...args: Any[]) => void; - json: boolean; + allowDuplicateKeys: boolean; implicitTypes: Type[]; typeMap: TypeMap; @@ -98,13 +98,13 @@ class LoaderState { { schema = DEFAULT_SCHEMA, onWarning, - json = false, + allowDuplicateKeys = false, }: LoaderStateOptions, ) { this.schema = schema; this.input = input; this.onWarning = onWarning; - this.json = json; + this.allowDuplicateKeys = allowDuplicateKeys; this.implicitTypes = this.schema.compiledImplicit; this.typeMap = this.schema.compiledTypeMap; this.length = input.length; @@ -397,7 +397,7 @@ function storeMappingPair( } } else { if ( - !state.json && + !state.allowDuplicateKeys && !Object.hasOwn(overridableKeys, keyNode) && Object.hasOwn(result, keyNode) ) { diff --git a/yaml/parse.ts b/yaml/parse.ts index c999ec5206a6..afe6ee1736ea 100644 --- a/yaml/parse.ts +++ b/yaml/parse.ts @@ -14,7 +14,7 @@ export interface ParseOptions { /** Name of the schema to use.*/ schema?: "core" | "default" | "failsafe" | "json" | "extended"; /** compatibility with JSON.parse behaviour. */ - json?: boolean; + allowDuplicateKeys?: boolean; /** function to call on warning messages. */ onWarning?(this: null, e?: Error): void; } From 7cc1684ac1f5de8fab71e9ac8a9f8a34389d8ed4 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 4 Jul 2024 14:51:16 +1000 Subject: [PATCH 2/2] fix --- yaml/parse_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaml/parse_test.ts b/yaml/parse_test.ts index eeaa52689691..2780af2b99c5 100644 --- a/yaml/parse_test.ts +++ b/yaml/parse_test.ts @@ -976,13 +976,13 @@ name: Jane Doe`, ); }); -Deno.test("parse() allows duplicate keys when `json` option is set to `true`", () => { +Deno.test("parse() allows duplicate keys when `allowDuplicateKeys` option is set to `true`", () => { assertEquals( parse( `name: John Doe age: 30 name: Jane Doe`, - { json: true }, + { allowDuplicateKeys: true }, ), { name: "Jane Doe", age: 30 }, );