Don't insert a cursor placeholder for a value-less path (#2136)

* Test that no cursor placeholder is inserted for a value-less path

This was taken from https://github.com/prettier/prettier/issues/2131

* Don't insert a cursor placeholder for a value-less path

This fixes https://github.com/prettier/prettier/issues/2131
This commit is contained in:
Joseph Frazier authored and Christopher Chedeau committed 2017-06-14 09:05:06 -07:00
1 parent b7e1c366e0
commit 48bbd9cb6b
2 files changed
+15 -1

No files matched your search

+1 -1
View File
@@ -934,7 +934,7 @@ function printDanglingComments(path, options, sameIndent) {
}
function prependCursorPlaceholder(path, options, printed) {
if (path.getNode() === options.cursorNode) {
if (path.getNode() === options.cursorNode && path.getValue()) {
return concat([cursor, printed]);
}
return printed;
+14
View File
@@ -22,3 +22,17 @@ test("keeps cursor inside formatted node", () => {
cursorOffset: 14 // TODO fix this
});
});
test("doesn't insert second placeholder for nonexistent TypeAnnotation", () => {
const code = `
foo('bar', cb => {
console.log('stuff')
})`;
expect(prettier.formatWithCursor(code, { cursorOffset: 24 })).toEqual({
formatted: `foo("bar", cb => {
console.log("stuff");
});
`,
cursorOffset: 23
});
});