fix(yaml): fix StringifyOptions.noRefs (#5292)

This commit is contained in:
Yoshiya Hinosawa 2024-07-04 14:56:40 +09:00 committed by GitHub
parent 484977ff9e
commit ed1ab2684a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -928,7 +928,7 @@ function inspectNode(
if (object !== null && typeof object === "object") {
const index = objects.indexOf(object);
if (index !== -1) {
if (duplicatesIndexes.includes(index)) {
if (!duplicatesIndexes.includes(index)) {
duplicatesIndexes.push(index);
}
} else {

View File

@ -275,3 +275,18 @@ Deno.test({
);
},
});
Deno.test({
name: "stringify() works with noRefs option",
fn() {
const obj = { foo: "bar" };
assertEquals(
stringify([obj, obj], { noRefs: true }),
`- foo: bar\n- foo: bar\n`,
);
assertEquals(
stringify([obj, obj], { noRefs: false }),
`- &ref_0\n foo: bar\n- *ref_0\n`,
);
},
});