Skip to content

Commit

Permalink
fix(cst): improve insert for single line json object (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Oct 21, 2024
1 parent b42054f commit 4cdfcf6
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/cst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ impl CstObject {
}

fn insert_or_append(&self, index: Option<usize>, prop_name: &str, value: CstInputValue) -> CstObjectProp {
self.ensure_multiline();
insert_or_append_to_container(
&CstContainerNode::Object(self.clone()),
self.properties().into_iter().map(|c| c.into()).collect(),
Expand Down Expand Up @@ -3235,6 +3236,30 @@ value3: true
r#"{
"value": 4,
"propName": true,
}"#,
);

// insert when is on a single line
run_test(
1,
"propName",
json!(true),
r#"{ "value": 4 }"#,
r#"{
"value": 4,
"propName": true
}"#,
);

// insert when is on a single line with trailing comma
run_test(
1,
"propName",
json!(true),
r#"{ "value": 4, }"#,
r#"{
"value": 4,
"propName": true,
}"#,
);
}
Expand Down

0 comments on commit 4cdfcf6

Please sign in to comment.