Ability to break on `:` for objects (#314)
parent
3aa267d5e8
commit
409d4b6eb5
|
@ -609,7 +609,25 @@ function genericPrintNoParens(path, options, print) {
|
||||||
} else {
|
} else {
|
||||||
parts.push(printPropertyKey(path, options, print));
|
parts.push(printPropertyKey(path, options, print));
|
||||||
}
|
}
|
||||||
parts.push(": ", path.call(print, "value"));
|
|
||||||
|
let printedValue = path.call(print, "value");
|
||||||
|
if (shouldPrintSameLine(n.value)) {
|
||||||
|
parts.push(concat([": ", printedValue]));
|
||||||
|
} else {
|
||||||
|
parts.push(
|
||||||
|
concat([
|
||||||
|
group(
|
||||||
|
concat([
|
||||||
|
":",
|
||||||
|
ifBreak(" (", " "),
|
||||||
|
indent(options.tabWidth, concat([softline, printedValue]))
|
||||||
|
])
|
||||||
|
),
|
||||||
|
line,
|
||||||
|
ifBreak(")")
|
||||||
|
])
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return concat(parts);
|
return concat(parts);
|
||||||
|
@ -2458,6 +2476,26 @@ function isLastStatement(path) {
|
||||||
return body && body[body.length - 1] === node;
|
return body && body[body.length - 1] === node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shouldPrintSameLine(node) {
|
||||||
|
const type = node.type;
|
||||||
|
return namedTypes.Literal.check(node) ||
|
||||||
|
type === "ArrayExpression" ||
|
||||||
|
type === "ArrayPattern" ||
|
||||||
|
type === "ArrowFunctionExpression" ||
|
||||||
|
type === "AssignmentPattern" ||
|
||||||
|
type === "CallExpression" ||
|
||||||
|
type === "FunctionExpression" ||
|
||||||
|
type === "Identifier" ||
|
||||||
|
type === "Literal" ||
|
||||||
|
type === "MemberExpression" ||
|
||||||
|
type === "NewExpression" ||
|
||||||
|
type === "ObjectExpression" ||
|
||||||
|
type === "ObjectPattern" ||
|
||||||
|
type === "StringLiteral" ||
|
||||||
|
type === "ThisExpression" ||
|
||||||
|
type === "TypeCastExpression";
|
||||||
|
}
|
||||||
|
|
||||||
function printAstToDoc(ast, options) {
|
function printAstToDoc(ast, options) {
|
||||||
function printGenerically(path) {
|
function printGenerically(path) {
|
||||||
return comments.printComments(
|
return comments.printComments(
|
||||||
|
|
|
@ -901,14 +901,14 @@ function logical12b(y: number): number {
|
||||||
*/
|
*/
|
||||||
function logical13(x: number): Array<{ x: string }> {
|
function logical13(x: number): Array<{ x: string }> {
|
||||||
return [
|
return [
|
||||||
{ x: x && \"bar\" },
|
{ x: x && \"bar\" },
|
||||||
{ x: true && \"bar\" },
|
{ x: true && \"bar\" },
|
||||||
{ x: true && false },
|
{ x: true && false },
|
||||||
{ x: false && false },
|
{ x: false && false },
|
||||||
{ x: 1 && \"bar\" },
|
{ x: 1 && \"bar\" },
|
||||||
{ x: \"foo\" && \"bar\" },
|
{ x: \"foo\" && \"bar\" },
|
||||||
{ x: \"foo\" && \"bar\" },
|
{ x: \"foo\" && \"bar\" },
|
||||||
{ x: \"foo\" && \"bar\" }
|
{ x: \"foo\" && \"bar\" }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -917,14 +917,14 @@ function logical13(x: number): Array<{ x: string }> {
|
||||||
*/
|
*/
|
||||||
function logical14(x: number): Array<{ x: string }> {
|
function logical14(x: number): Array<{ x: string }> {
|
||||||
return [
|
return [
|
||||||
{ x: x || \"bar\" },
|
{ x: x || \"bar\" },
|
||||||
{ x: false || \"bar\" },
|
{ x: false || \"bar\" },
|
||||||
{ x: false || true },
|
{ x: false || true },
|
||||||
{ x: true || false },
|
{ x: true || false },
|
||||||
{ x: 0 || \"bar\" },
|
{ x: 0 || \"bar\" },
|
||||||
{ x: \"foo\" || \"bar\" },
|
{ x: \"foo\" || \"bar\" },
|
||||||
{ x: \"foo\" || \"bar\" },
|
{ x: \"foo\" || \"bar\" },
|
||||||
{ x: \"foo\" || \"bar\" }
|
{ x: \"foo\" || \"bar\" }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -690,6 +690,71 @@ method()
|
||||||
"
|
"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`test object-prop-break-in.js 1`] = `
|
||||||
|
"const a = classnames({
|
||||||
|
\"some-prop\": this.state.longLongLongLongLongLongLongLongLongTooLongProp
|
||||||
|
});
|
||||||
|
|
||||||
|
const b = classnames({
|
||||||
|
\"some-prop\": this.state.longLongLongLongLongLongLongLongLongTooLongProp === true
|
||||||
|
});
|
||||||
|
|
||||||
|
const c = classnames({
|
||||||
|
\"some-prop\": [ \"foo\", \"bar\", \"foo\", \"bar\", \"foo\", \"bar\", \"foo\", \"bar\", \"foo\" ]
|
||||||
|
});
|
||||||
|
|
||||||
|
const d = classnames({
|
||||||
|
\"some-prop\": () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const e = classnames({
|
||||||
|
\"some-prop\": function bar() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const f = classnames({
|
||||||
|
\"some-prop\": { foo: \"bar\", bar: \"foo\", foo: \"bar\", bar: \"foo\", foo: \"bar\" }
|
||||||
|
});
|
||||||
|
|
||||||
|
const g = classnames({
|
||||||
|
\"some-prop\": longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337
|
||||||
|
});
|
||||||
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
const a = classnames({
|
||||||
|
\"some-prop\": this.state.longLongLongLongLongLongLongLongLongTooLongProp
|
||||||
|
});
|
||||||
|
|
||||||
|
const b = classnames({
|
||||||
|
\"some-prop\": (
|
||||||
|
this.state.longLongLongLongLongLongLongLongLongTooLongProp === true
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
const c = classnames({
|
||||||
|
\"some-prop\": [ \"foo\", \"bar\", \"foo\", \"bar\", \"foo\", \"bar\", \"foo\", \"bar\", \"foo\" ]
|
||||||
|
});
|
||||||
|
|
||||||
|
const d = classnames({
|
||||||
|
\"some-prop\": () => {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const e = classnames({
|
||||||
|
\"some-prop\": function bar() {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const f = classnames({
|
||||||
|
\"some-prop\": { foo: \"bar\", bar: \"foo\", foo: \"bar\", bar: \"foo\", foo: \"bar\" }
|
||||||
|
});
|
||||||
|
|
||||||
|
const g = classnames({
|
||||||
|
\"some-prop\": (
|
||||||
|
longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337
|
||||||
|
)
|
||||||
|
});
|
||||||
|
"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`test optional-type-name.js 1`] = `
|
exports[`test optional-type-name.js 1`] = `
|
||||||
"type Foo = (any) => string
|
"type Foo = (any) => string
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
const a = classnames({
|
||||||
|
"some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp
|
||||||
|
});
|
||||||
|
|
||||||
|
const b = classnames({
|
||||||
|
"some-prop": this.state.longLongLongLongLongLongLongLongLongTooLongProp === true
|
||||||
|
});
|
||||||
|
|
||||||
|
const c = classnames({
|
||||||
|
"some-prop": [ "foo", "bar", "foo", "bar", "foo", "bar", "foo", "bar", "foo" ]
|
||||||
|
});
|
||||||
|
|
||||||
|
const d = classnames({
|
||||||
|
"some-prop": () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const e = classnames({
|
||||||
|
"some-prop": function bar() {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const f = classnames({
|
||||||
|
"some-prop": { foo: "bar", bar: "foo", foo: "bar", bar: "foo", foo: "bar" }
|
||||||
|
});
|
||||||
|
|
||||||
|
const g = classnames({
|
||||||
|
"some-prop": longLongLongLongLongLongLongLongLongLongLongLongLongTooLongVar || 1337
|
||||||
|
});
|
Loading…
Reference in New Issue