JSON edit deletes comments. fixes #6725

This commit is contained in:
Martin Aeschlimann
2016-05-25 14:56:01 +02:00
parent 18802ed5f4
commit 462bdd37e5
2 changed files with 5 additions and 1 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ export function setProperty(text: string, path: JSONPath, value: any, formatting
if (value === void 0) { // delete
throw new Error('Can not delete in empty document');
}
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : text.length, content: JSON.stringify(value) }, formattingOptions);
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, formattingOptions);
} else if (parent.type === 'object' && typeof lastSegment === 'string') {
let existing = findNodeAtLocation(parent, [ lastSegment ]);
if (existing !== void 0) {
+4
View File
@@ -83,6 +83,10 @@ suite('JSON - edits', () => {
content = '';
edits = setProperty(content, ['foo', 0], 'bar', formatterOptions);
assertEdit(content, edits, '{\n "foo": [\n "bar"\n ]\n}');
content = '//comment';
edits = setProperty(content, ['foo', 0], 'bar', formatterOptions);
assertEdit(content, edits, '{\n "foo": [\n "bar"\n ]\n} //comment\n');
});
test('remove property', () => {