diff --git a/src/comments.js b/src/comments.js index 515ed12d3..d2b257072 100644 --- a/src/comments.js +++ b/src/comments.js @@ -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; diff --git a/tests/cursor/jsfmt.spec.js b/tests/cursor/jsfmt.spec.js index e5a0dc39d..e92b0d4e4 100644 --- a/tests/cursor/jsfmt.spec.js +++ b/tests/cursor/jsfmt.spec.js @@ -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 + }); +});