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/2131master
parent
b7e1c366e0
commit
48bbd9cb6b
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue