prettier / prettier-regression-testing

Automates the prettier/prettier regression checks with GitHub Actions.
12 stars 9 forks source link

#11103 Break multiline parenthesized logical expressions #444

Open fisker opened 4 months ago

fisker commented 4 months ago

Run #11103

github-actions[bot] commented 4 months ago

prettier/prettier#11103 VS prettier/prettier@main :: babel/babel@71c247a1831fe70e8b847fdb57b5fc10538d9748

Diff (1425 lines) ```diff diff --git ORI/babel/packages/babel-core/src/config/config-chain.ts ALT/babel/packages/babel-core/src/config/config-chain.ts index 23ce8677..37cbabb7 100644 --- ORI/babel/packages/babel-core/src/config/config-chain.ts +++ ALT/babel/packages/babel-core/src/config/config-chain.ts @@ -808,12 +808,18 @@ function configIsApplicable( configName: string, ): boolean { return ( - (options.test === undefined || - configFieldIsApplicable(context, options.test, dirname, configName)) && - (options.include === undefined || - configFieldIsApplicable(context, options.include, dirname, configName)) && - (options.exclude === undefined || - !configFieldIsApplicable(context, options.exclude, dirname, configName)) + ( + options.test === undefined || + configFieldIsApplicable(context, options.test, dirname, configName) + ) && + ( + options.include === undefined || + configFieldIsApplicable(context, options.include, dirname, configName) + ) && + ( + options.exclude === undefined || + !configFieldIsApplicable(context, options.exclude, dirname, configName) + ) ); } diff --git ORI/babel/packages/babel-generator/src/generators/flow.ts ALT/babel/packages/babel-generator/src/generators/flow.ts index 73d0b7a8..5e9c85f7 100644 --- ORI/babel/packages/babel-generator/src/generators/flow.ts +++ ALT/babel/packages/babel-generator/src/generators/flow.ts @@ -333,10 +333,12 @@ export function FunctionTypeAnnotation( const type = parent?.type; if ( type != null && - (type === "ObjectTypeCallProperty" || + ( + type === "ObjectTypeCallProperty" || type === "ObjectTypeInternalSlot" || type === "DeclareFunction" || - (type === "ObjectTypeProperty" && parent.method)) + (type === "ObjectTypeProperty" && parent.method) + ) ) { this.token(":"); } else { diff --git ORI/babel/packages/babel-generator/src/node/parentheses.ts ALT/babel/packages/babel-generator/src/node/parentheses.ts index d42a2140..47031844 100644 --- ORI/babel/packages/babel-generator/src/node/parentheses.ts +++ ALT/babel/packages/babel-generator/src/node/parentheses.ts @@ -72,13 +72,21 @@ const isClassExtendsClause = ( const hasPostfixPart = (node: t.Node, parent: t.Node) => { const parentType = parent.type; return ( - ((parentType === "MemberExpression" || - parentType === "OptionalMemberExpression") && - parent.object === node) || - ((parentType === "CallExpression" || - parentType === "OptionalCallExpression" || - parentType === "NewExpression") && - parent.callee === node) || + ( + ( + parentType === "MemberExpression" || + parentType === "OptionalMemberExpression" + ) && + parent.object === node + ) || + ( + ( + parentType === "CallExpression" || + parentType === "OptionalCallExpression" || + parentType === "NewExpression" + ) && + parent.callee === node + ) || (parentType === "TaggedTemplateExpression" && parent.tag === node) || parentType === "TSNonNullExpression" ); @@ -107,9 +115,11 @@ export function FunctionTypeAnnotation( // (() => A)[] parentType === "ArrayTypeAnnotation" || // (A: T): (T => T[]) => B => [A, B] - (parentType === "TypeAnnotation" && + ( + parentType === "TypeAnnotation" && // Check grandparent - isArrowFunctionExpression(printStack[printStack.length - 3])) + isArrowFunctionExpression(printStack[printStack.length - 3]) + ) ); } @@ -174,9 +184,11 @@ export function Binary( if ( // Logical expressions with the same precedence don't need parens. - (parentPos === nodePos && + ( + parentPos === nodePos && parent.right === node && - parentType !== "LogicalExpression") || + parentType !== "LogicalExpression" + ) || parentPos > nodePos ) { return true; @@ -241,10 +253,12 @@ export function TSInstantiationExpression( ) { const parentType = parent.type; return ( - (parentType === "CallExpression" || + ( + parentType === "CallExpression" || parentType === "OptionalCallExpression" || parentType === "NewExpression" || - parentType === "TSInstantiationExpression") && + parentType === "TSInstantiationExpression" + ) && !!parent.typeParameters ); } @@ -334,9 +348,11 @@ export function UnaryLike( ): boolean { return ( hasPostfixPart(node, parent) || - (isBinaryExpression(parent) && + ( + isBinaryExpression(parent) && parent.operator === "**" && - parent.left === node) || + parent.left === node + ) || isClassExtendsClause(node, parent) ); } @@ -503,15 +519,21 @@ function isFirstInContext( while (i >= 0) { const parentType = parent.type; if ( - (expressionStatement && + ( + expressionStatement && parentType === "ExpressionStatement" && - parent.expression === node) || - (exportDefault && + parent.expression === node + ) || + ( + exportDefault && parentType === "ExportDefaultDeclaration" && - node === parent.declaration) || - (arrowBody && + node === parent.declaration + ) || + ( + arrowBody && parentType === "ArrowFunctionExpression" && - parent.body === node) || + parent.body === node + ) || (forHead && parentType === "ForStatement" && parent.init === node) || (forInHead && parentType === "ForInStatement" && parent.left === node) || (forOfHead && parentType === "ForOfStatement" && parent.left === node) @@ -521,15 +543,23 @@ function isFirstInContext( if ( i > 0 && - ((hasPostfixPart(node, parent) && parentType !== "NewExpression") || - (parentType === "SequenceExpression" && - parent.expressions[0] === node) || + ( + (hasPostfixPart(node, parent) && parentType !== "NewExpression") || + ( + parentType === "SequenceExpression" && + parent.expressions[0] === node + ) || (parentType === "UpdateExpression" && !parent.prefix) || (parentType === "ConditionalExpression" && parent.test === node) || - ((parentType === "BinaryExpression" || - parentType === "LogicalExpression") && - parent.left === node) || - (parentType === "AssignmentExpression" && parent.left === node)) + ( + ( + parentType === "BinaryExpression" || + parentType === "LogicalExpression" + ) && + parent.left === node + ) || + (parentType === "AssignmentExpression" && parent.left === node) + ) ) { node = parent; i--; diff --git ORI/babel/packages/babel-generator/src/printer.ts ALT/babel/packages/babel-generator/src/printer.ts index e2d21741..e2f27ec0 100644 --- ORI/babel/packages/babel-generator/src/printer.ts +++ ALT/babel/packages/babel-generator/src/printer.ts @@ -268,12 +268,16 @@ class Printer { const lastChar = this.getLastChar(); const strFirst = str.charCodeAt(0); if ( - (lastChar === charCodes.exclamationMark && + ( + lastChar === charCodes.exclamationMark && // space is mandatory to avoid outputting