Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jun 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/comments.js
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions tests/cursor/jsfmt.spec.js
Expand Up @@ -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
});
});