Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING(yaml): rename ParseOptions.json to ParseOptions.allowDuplicateKeys #5282

Merged
merged 4 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions yaml/_loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?(error?: YamlError): void;
}
Expand All @@ -80,7 +80,7 @@ class LoaderState {
position = 0;
line = 0;
onWarning?: (...args: Any[]) => void;
json: boolean;
allowDuplicateKeys: boolean;
implicitTypes: Type[];
typeMap: TypeMap;

Expand All @@ -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;
Expand Down Expand Up @@ -397,7 +397,7 @@ function storeMappingPair(
}
} else {
if (
!state.json &&
!state.allowDuplicateKeys &&
!Object.hasOwn(overridableKeys, keyNode) &&
Object.hasOwn(result, keyNode)
) {
Expand Down
2 changes: 1 addition & 1 deletion yaml/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ParseOptions {
/** Name of the schema to use.*/
schema?: "core" | "default" | "failsafe" | "json" | "extended";
/** compatibility with JSON.parse behaviour. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also change the description

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be reworking docs for all of @std/yaml once the breaking changes are made.

json?: boolean;
allowDuplicateKeys?: boolean;
/** function to call on warning messages. */
onWarning?(error?: Error): void;
}
Expand Down
4 changes: 2 additions & 2 deletions yaml/parse_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
Expand Down