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
master
Joseph Frazier 2017-06-14 12:05:06 -04:00 committed by Christopher Chedeau
parent b7e1c366e0
commit 48bbd9cb6b
2 changed files with 15 additions and 1 deletions

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;

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
});
});