From b927e8c07486eb62e5265e596157512b82760487 Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Fri, 5 Jul 2024 15:24:13 +1000 Subject: [PATCH] BREAKING(yaml): rename `StringifyOptions.noRefs` to `StringifyOptions.useAnchors` (#5288) --- yaml/_dumper.ts | 14 +++++++------- yaml/stringify.ts | 6 +++--- yaml/stringify_test.ts | 6 +++--- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/yaml/_dumper.ts b/yaml/_dumper.ts index aab3a4adb76c..a542e1eb990c 100644 --- a/yaml/_dumper.ts +++ b/yaml/_dumper.ts @@ -128,10 +128,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; + useAnchors?: boolean; /** * if false don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, @@ -155,7 +155,7 @@ export class DumperState { flowLevel: number; sortKeys: boolean | ((a: Any, b: Any) => number); lineWidth: number; - noRefs: boolean; + useAnchors: boolean; compatMode: boolean; condenseFlow: boolean; implicitTypes: Type[]; @@ -176,7 +176,7 @@ export class DumperState { styles = null, sortKeys = false, lineWidth = 80, - noRefs = false, + useAnchors = true, compatMode = true, condenseFlow = false, }: DumperStateOptions) { @@ -188,7 +188,7 @@ export class DumperState { this.styleMap = compileStyleMap(styles); this.sortKeys = sortKeys; this.lineWidth = lineWidth; - this.noRefs = noRefs; + this.useAnchors = useAnchors; this.compatMode = compatMode; this.condenseFlow = condenseFlow; this.implicitTypes = this.schema.compiledImplicit; @@ -917,7 +917,7 @@ function getDuplicateReferences( export function dump(input: Any, options: DumperStateOptions = {}): string { const state = new DumperState(options); - if (!state.noRefs) 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 dfba209a091f..841072b77c01 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; + useAnchors?: boolean; /** * If false don't try to be compatible with older yaml versions. * Currently: don't quote "yes", "no" and so on, diff --git a/yaml/stringify_test.ts b/yaml/stringify_test.ts index 9c8ec9d1a2d4..7eeb4bbb4fd3 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: false }), `- foo: bar\n- foo: bar\n`, ); assertEquals( - stringify([obj, obj], { noRefs: false }), + stringify([obj, obj], { useAnchors: true }), `- &ref_0\n foo: bar\n- *ref_0\n`, ); },