deno_std icon indicating copy to clipboard operation
deno_std copied to clipboard

Yaml library drops comments when round tripping

Open justinmchase opened this issue 2 years ago • 1 comments

Describe the bug

If I parse a yaml file, edit it then save it back, it drops all comments.

Steps to Reproduce

import {
  parse,
  stringify,
} from "https://deno.land/[email protected]/yaml/mod.ts";

const result = stringify(parse(`
# comment
name: example
`));

console.log(stringify(result)) // name: example

Expected behavior

I expect all code comments to be preserved.

Environment

deno 1.31.3 (release, x86_64-apple-darwin)
v8 11.0.226.19
typescript 4.9.4
  • std version: 0.182.0

justinmchase avatar Apr 06 '23 03:04 justinmchase

I would propose an option on parse that would return not a basic record but a YamlDocument class object. Add onto the more complex object a full information about tokens. When passed into stringify it would have the full information needed to write the document about out exactly as it came in.

justinmchase avatar Apr 06 '23 03:04 justinmchase