Continuation of revert 7889 (#9024)

* Continuation of revert 7889

* Remove isLiteralLikeValue

* Revert callHasComplexArguments

* Revert usage of shouldMerge
This commit is contained in:
Sosuke Suzuki authored and GitHub committed 2020-08-23 01:23:41 +09:00
1 parent 08e8b40ac6
commit c4e9dd9c36
5 files changed
+14 -67

No files matched your search

+4 -11
View File
@@ -361,7 +361,7 @@ function printMemberChain(path, options, print) {
const expanded = concat([
printGroup(groups[0]),
shouldMerge ? printGroup(groups[1]) : "",
shouldMerge ? concat(groups.slice(1, 2).map(printGroup)) : "",
shouldHaveEmptyLineBeforeIndent ? hardline : "",
printIndentedGroup(groups.slice(shouldMerge ? 2 : 1)),
]);
@@ -370,13 +370,6 @@ function printMemberChain(path, options, print) {
.map(({ node }) => node)
.filter(isCallOrOptionalCallExpression);
function callHasComplexArguments(expr, index) {
return (
(index !== 0 && expr.arguments.length > 2) ||
!expr.arguments.every((arg) => isSimpleCallArgument(arg, 0))
);
}
function lastGroupWillBreakAndOtherCallsHaveFunctionArguments() {
const lastGroupNode = getLast(getLast(groups)).node;
const lastGroupDoc = getLast(printedGroups);
@@ -391,16 +384,16 @@ function printMemberChain(path, options, print) {
// We don't want to print in one line if at least one of these conditions occurs:
// * the chain has comments,
// * the head of the chain is a constructor call,
// * the chain is an expression statement and all the arguments are literal-like ("fluent configuration" pattern),
// * the chain is longer than 2 calls and has non-trivial arguments or more than 2 arguments in any call but the first one,
// * any group but the last one has a hard line,
// * the last call's arguments have a hard line and other calls have non-trivial arguments.
if (
hasComment ||
printedNodes[0].node.type === "NewExpression" ||
(callExpressions.length > 2 &&
callExpressions.some(callHasComplexArguments)) ||
callExpressions.some(
(expr) => !expr.arguments.every((arg) => isSimpleCallArgument(arg, 0))
)) ||
printedGroups.slice(0, -1).some(willBreak) ||
lastGroupWillBreakAndOtherCallsHaveFunctionArguments()
) {
-23
View File
@@ -203,28 +203,6 @@ function isLiteral(node) {
);
}
/**
* @param {any} node
* @returns {boolean}
*/
function isLiteralLikeValue(node) {
return (
isLiteral(node) ||
(node.type === "Identifier" && /^[A-Z_]+$/.test(node.name)) ||
(node.type === "ArrayExpression" &&
node.elements.every(
(element) => element !== null && isLiteralLikeValue(element)
)) ||
(node.type === "ObjectExpression" &&
node.properties.every(
(property) =>
!property.computed &&
property.value &&
isLiteralLikeValue(property.value)
))
);
}
/**
* @param {Node} node
* @returns {boolean}
@@ -1415,7 +1393,6 @@ module.exports = {
isJSXWhitespaceExpression,
isLastStatement,
isLiteral,
isLiteralLikeValue,
isLongCurriedCallExpression,
isSimpleCallArgument,
isMeaningfulJSXText,
@@ -30,10 +30,7 @@ new Test()
.test();
=====================================output=====================================
new Test()
.test()
.test([, 0])
.test();
new Test().test().test([, 0]).test();
================================================================================
`;
@@ -545,9 +545,7 @@ cy.get(".ready")
=====================================output=====================================
cy.get("option:first").should("be.selected").and("have.value", "Metallica");
cy.get(".ready")
.should("have.text", "FOO")
.should("have.css", "color", "#aaa");
cy.get(".ready").should("have.text", "FOO").should("have.css", "color", "#aaa");
================================================================================
`;
@@ -779,9 +777,7 @@ fetched
.then((response) => response.json())
.then((json) => processThings(json.data.things));
let column = new Column(null, conn)
.table(data.table)
.json(data.column);
let column = new Column(null, conn).table(data.table).json(data.column);
================================================================================
`;
@@ -22,17 +22,11 @@ const writer2 = new BufferStackItem(
=====================================output=====================================
const writer = new BufferStackItem(
new BinaryWriter()
.writeUInt8(StackItemType.ByteArray)
.writeVarBytesLE(Buffer.alloc(10, 1))
.toBuffer()
new BinaryWriter().writeUInt8(StackItemType.ByteArray).writeVarBytesLE(Buffer.alloc(10, 1)).toBuffer()
);
const writer2 = new BufferStackItem(
new Extra.BinaryWriter()
.writeUInt8(StackItemType.ByteArray)
.writeVarBytesLE(Buffer.alloc(10, 1))
.toBuffer()
new Extra.BinaryWriter().writeUInt8(StackItemType.ByteArray).writeVarBytesLE(Buffer.alloc(10, 1)).toBuffer()
);
================================================================================
@@ -61,21 +55,11 @@ printWidth: 120
.should("have.css", "background-color", "rgb(222, 222, 222)");
=====================================output=====================================
cy.get(".ready")
.should("have.text", "READY")
.should("have.css", "background-color", "rgb(136, 228, 229)");
cy.get(".pending")
.should("have.text", "PENDING")
.should("have.css", "background-color", "rgb(253, 212, 90)");
cy.get(".live")
.should("have.text", "LIVE")
.should("have.css", "background-color", "rgb(175, 221, 255)");
cy.get(".draft")
.should("have.text", "DRAFT")
.should("have.css", "background-color", "rgb(255, 181, 181)");
cy.get(".scheduled")
.should("have.text", "SCHEDULED")
.should("have.css", "background-color", "rgb(222, 222, 222)");
cy.get(".ready").should("have.text", "READY").should("have.css", "background-color", "rgb(136, 228, 229)");
cy.get(".pending").should("have.text", "PENDING").should("have.css", "background-color", "rgb(253, 212, 90)");
cy.get(".live").should("have.text", "LIVE").should("have.css", "background-color", "rgb(175, 221, 255)");
cy.get(".draft").should("have.text", "DRAFT").should("have.css", "background-color", "rgb(255, 181, 181)");
cy.get(".scheduled").should("have.text", "SCHEDULED").should("have.css", "background-color", "rgb(222, 222, 222)");
================================================================================
`;