From 7193ed3eed6d110a39552fa07e2d655b8072908b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Thu, 4 Jul 2024 10:20:08 +1000 Subject: [PATCH 1/4] BREAKING(yaml): rename `StringifyOptions.noRefs` to `StringifyOptions.createRefs` --- yaml/_dumper.ts | 14 +++++++------- yaml/stringify.ts | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/yaml/_dumper.ts b/yaml/_dumper.ts index c6d19c8de6a4..512337f3d533 100644 --- a/yaml/_dumper.ts +++ b/yaml/_dumper.ts @@ -126,10 +126,10 @@ export interface DumperStateOptions { /** set max line width. (default: 80) */ lineWidth?: number; /** - * if true, don't convert duplicate objects - * into references (default: false) + * if false, don't convert duplicate objects + * into references (default: true) */ - noRefs?: boolean; + createRefs?: boolean; /** * if true don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, @@ -153,7 +153,7 @@ export class DumperState { flowLevel: number; sortKeys: boolean | ((a: Any, b: Any) => number); lineWidth: number; - noRefs: boolean; + createRefs: boolean; noCompatMode: boolean; condenseFlow: boolean; implicitTypes: Type[]; @@ -174,7 +174,7 @@ export class DumperState { styles = null, sortKeys = false, lineWidth = 80, - noRefs = false, + createRefs = true, noCompatMode = false, condenseFlow = false, }: DumperStateOptions) { @@ -186,7 +186,7 @@ export class DumperState { this.styleMap = compileStyleMap(this.schema, styles); this.sortKeys = sortKeys; this.lineWidth = lineWidth; - this.noRefs = noRefs; + this.createRefs = createRefs; this.noCompatMode = noCompatMode; this.condenseFlow = condenseFlow; this.implicitTypes = this.schema.compiledImplicit; @@ -965,7 +965,7 @@ function getDuplicateReferences( export function dump(input: Any, options: DumperStateOptions = {}): string { const state = new DumperState(options); - if (!state.noRefs) getDuplicateReferences(input, state); + if (state.createRefs) getDuplicateReferences(input, state); if (writeNode(state, 0, input, true, true)) return `${state.dump}\n`; diff --git a/yaml/stringify.ts b/yaml/stringify.ts index 7c513c928fc9..285c79d14c33 100644 --- a/yaml/stringify.ts +++ b/yaml/stringify.ts @@ -43,10 +43,10 @@ export type StringifyOptions = { /** Set max line width. (default: 80) */ lineWidth?: number; /** - * If true, don't convert duplicate objects - * into references (default: false) + * If false, don't convert duplicate objects + * into references (default: true) */ - noRefs?: boolean; + createRefs?: boolean; /** * If true don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, From 69e056bca3107218d48d6ca1ed371c3a2224e58d Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 5 Jul 2024 13:54:52 +1000 Subject: [PATCH 2/4] refactor: rename to `useAnchors` --- yaml/_dumper.ts | 10 +++++----- yaml/stringify.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/yaml/_dumper.ts b/yaml/_dumper.ts index 30c09740a563..b380ca25788c 100644 --- a/yaml/_dumper.ts +++ b/yaml/_dumper.ts @@ -129,7 +129,7 @@ export interface DumperStateOptions { * if false, don't convert duplicate objects * into references (default: true) */ - createRefs?: boolean; + useAnchors?: boolean; /** * if false don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, @@ -153,7 +153,7 @@ export class DumperState { flowLevel: number; sortKeys: boolean | ((a: Any, b: Any) => number); lineWidth: number; - createRefs: boolean; + useAnchors: boolean; compatMode: boolean; condenseFlow: boolean; implicitTypes: Type[]; @@ -174,7 +174,7 @@ export class DumperState { styles = null, sortKeys = false, lineWidth = 80, - createRefs = true, + useAnchors = true, compatMode = true, condenseFlow = false, }: DumperStateOptions) { @@ -186,7 +186,7 @@ export class DumperState { this.styleMap = compileStyleMap(this.schema, styles); this.sortKeys = sortKeys; this.lineWidth = lineWidth; - this.createRefs = createRefs; + this.useAnchors = useAnchors; this.compatMode = compatMode; this.condenseFlow = condenseFlow; this.implicitTypes = this.schema.compiledImplicit; @@ -965,7 +965,7 @@ function getDuplicateReferences( export function dump(input: Any, options: DumperStateOptions = {}): string { const state = new DumperState(options); - if (state.createRefs) getDuplicateReferences(input, state); + if (state.useAnchors) getDuplicateReferences(input, state); if (writeNode(state, 0, input, true, true)) return `${state.dump}\n`; diff --git a/yaml/stringify.ts b/yaml/stringify.ts index 26a0d71b144d..841072b77c01 100644 --- a/yaml/stringify.ts +++ b/yaml/stringify.ts @@ -46,7 +46,7 @@ export type StringifyOptions = { * If false, don't convert duplicate objects * into references (default: true) */ - createRefs?: boolean; + useAnchors?: boolean; /** * If false don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, From 23475dc1125b90550b9bf0c4b82267e5f433213e Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 5 Jul 2024 13:57:54 +1000 Subject: [PATCH 3/4] fix --- yaml/stringify_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/yaml/stringify_test.ts b/yaml/stringify_test.ts index 9c8ec9d1a2d4..6e36acc8508f 100644 --- a/yaml/stringify_test.ts +++ b/yaml/stringify_test.ts @@ -253,15 +253,15 @@ Deno.test({ }); Deno.test({ - name: "stringify() works with noRefs option", + name: "stringify() works with useAnchors option", fn() { const obj = { foo: "bar" }; assertEquals( - stringify([obj, obj], { noRefs: true }), + stringify([obj, obj], { useAnchors: true }), `- foo: bar\n- foo: bar\n`, ); assertEquals( - stringify([obj, obj], { noRefs: false }), + stringify([obj, obj], { useAnchors: false }), `- &ref_0\n foo: bar\n- *ref_0\n`, ); }, From b5ce607d5448fd88b5aec9372d3155b45c7f60cc Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 5 Jul 2024 13:58:47 +1000 Subject: [PATCH 4/4] fix --- yaml/stringify_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/yaml/stringify_test.ts b/yaml/stringify_test.ts index 6e36acc8508f..7eeb4bbb4fd3 100644 --- a/yaml/stringify_test.ts +++ b/yaml/stringify_test.ts @@ -257,11 +257,11 @@ Deno.test({ fn() { const obj = { foo: "bar" }; assertEquals( - stringify([obj, obj], { useAnchors: true }), + stringify([obj, obj], { useAnchors: false }), `- foo: bar\n- foo: bar\n`, ); assertEquals( - stringify([obj, obj], { useAnchors: false }), + stringify([obj, obj], { useAnchors: true }), `- &ref_0\n foo: bar\n- *ref_0\n`, ); },