Avoid unneeded parenthesis for colon with comments (#673)

Because the group was too high up, the comment would be taken into consideration to determine the size and it would break and add parenthesis. Adding a group where we actually want the ifBreak seems to be passing all the existing tests and fixes this edge case.

Fixes #655
master
Christopher Chedeau 2017-02-13 06:55:09 -08:00 committed by James Long
parent 1fed39ae30
commit 76e599ec97
3 changed files with 25 additions and 2 deletions

View File

@ -684,13 +684,13 @@ function genericPrintNoParens(path, options, print) {
parts.push(concat([": ", printedValue])); parts.push(concat([": ", printedValue]));
} else { } else {
parts.push( parts.push(
concat([ group(concat([
":", ":",
ifBreak(" (", " "), ifBreak(" (", " "),
indent(options.tabWidth, concat([softline, printedValue])), indent(options.tabWidth, concat([softline, printedValue])),
softline, softline,
ifBreak(")") ifBreak(")")
]) ]))
); );
} }
} }

View File

@ -1,3 +1,20 @@
exports[`test comment.js 1`] = `
"function foo() {
return {
// this comment causes the problem
bar: baz() + 1
};
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function foo() {
return {
// this comment causes the problem
bar: baz() + 1
};
}
"
`;
exports[`test test.js 1`] = ` exports[`test test.js 1`] = `
"const a = classnames({ "const a = classnames({
\"some-prop\": this.state.longLongLongLongLongLongLongLongLongTooLongProp \"some-prop\": this.state.longLongLongLongLongLongLongLongLongTooLongProp

View File

@ -0,0 +1,6 @@
function foo() {
return {
// this comment causes the problem
bar: baz() + 1
};
}