Skip to content

[Bug] Comments before the line to be edited are removed #8

Description

@ParaN3xus

Minimal reproducing example:

import { init, edit } from "@rainbowatcher/toml-edit-js"

const toml = `
[package]
# comment
rand = "1"
`

await init()
const edited = edit(toml, "package.rand", "2")
console.log(edited)

Gives

[package]
rand = "2"

Where the comment line # comment is removed. By contrast, the following Rust code using the toml_edit crate

use toml_edit::{DocumentMut, value};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let toml = r#"
[package]
# comment
rand = "1"
"#;

    let mut doc = toml.parse::<DocumentMut>()?;

    doc["package"]["rand"] = value("2");

    println!("{}", doc.to_string());

    Ok(())
}

Gives

[package]
# comment
rand = "2"

where the comment line is preserved, which is what we expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions