Skip to content

Commit 4cdfcf6

Browse files
authored
fix(cst): improve insert for single line json object (#48)
1 parent b42054f commit 4cdfcf6

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/cst/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,7 @@ impl CstObject {
16311631
}
16321632

16331633
fn insert_or_append(&self, index: Option<usize>, prop_name: &str, value: CstInputValue) -> CstObjectProp {
1634+
self.ensure_multiline();
16341635
insert_or_append_to_container(
16351636
&CstContainerNode::Object(self.clone()),
16361637
self.properties().into_iter().map(|c| c.into()).collect(),
@@ -3235,6 +3236,30 @@ value3: true
32353236
r#"{
32363237
"value": 4,
32373238
"propName": true,
3239+
}"#,
3240+
);
3241+
3242+
// insert when is on a single line
3243+
run_test(
3244+
1,
3245+
"propName",
3246+
json!(true),
3247+
r#"{ "value": 4 }"#,
3248+
r#"{
3249+
"value": 4,
3250+
"propName": true
3251+
}"#,
3252+
);
3253+
3254+
// insert when is on a single line with trailing comma
3255+
run_test(
3256+
1,
3257+
"propName",
3258+
json!(true),
3259+
r#"{ "value": 4, }"#,
3260+
r#"{
3261+
"value": 4,
3262+
"propName": true,
32383263
}"#,
32393264
);
32403265
}

0 commit comments

Comments
 (0)