Minor refactor to function print (#18671)
This commit is contained in:
1 parent
e11a16a881
commit
7f5c18d719
6 files changed
+12
-16
No files matched your search
@@ -179,9 +179,9 @@ function printArrowFunctionSignature(path, options, print, args) {
|
||||
if (shouldPrintParamsWithoutParens(path, options)) {
|
||||
parts.push(print(["params", 0]));
|
||||
} else {
|
||||
const shouldExpandArgument = args.expandLastArg || args.expandFirstArg;
|
||||
const shouldExpandParameters = args.expandLastArg || args.expandFirstArg;
|
||||
let returnTypeDoc = printReturnType(path, print);
|
||||
if (shouldExpandArgument) {
|
||||
if (shouldExpandParameters) {
|
||||
if (willBreak(returnTypeDoc)) {
|
||||
throw new ArgExpansionBailout();
|
||||
}
|
||||
@@ -193,7 +193,7 @@ function printArrowFunctionSignature(path, options, print, args) {
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
shouldExpandArgument,
|
||||
shouldExpandParameters,
|
||||
/* shouldPrintTypeParameters */ true,
|
||||
),
|
||||
returnTypeDoc,
|
||||
|
||||
@@ -63,7 +63,7 @@ function printFunctionParameters(
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
shouldExpandArgument,
|
||||
shouldExpandParameters,
|
||||
shouldPrintTypeParameters,
|
||||
) {
|
||||
const functionNode = path.node;
|
||||
@@ -119,7 +119,7 @@ function printFunctionParameters(
|
||||
// } b,
|
||||
// ) ) => {
|
||||
// })
|
||||
if (shouldExpandArgument && !isDecoratedFunction(path)) {
|
||||
if (shouldExpandParameters && !isDecoratedFunction(path)) {
|
||||
if (willBreak(typeParametersDoc) || willBreak(printed)) {
|
||||
// Removing lines in this case leads to broken or ugly output
|
||||
throw new ArgExpansionBailout();
|
||||
|
||||
@@ -39,7 +39,7 @@ function printFunctionType(path, options, print) {
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
/* shouldExpandArgument */ false,
|
||||
/* shouldExpandParameters */ false,
|
||||
/* shouldPrintTypeParameters */ true,
|
||||
);
|
||||
|
||||
|
||||
@@ -46,12 +46,8 @@ function printFunction(path, options, print, args) {
|
||||
|
||||
const { node } = path;
|
||||
|
||||
let shouldExpandArgument = false;
|
||||
if (
|
||||
(node.type === "FunctionDeclaration" ||
|
||||
node.type === "FunctionExpression") &&
|
||||
args?.expandLastArg
|
||||
) {
|
||||
let shouldExpandParameters = false;
|
||||
if (node.type === "FunctionExpression" && args?.expandLastArg) {
|
||||
const { parent } = path;
|
||||
if (
|
||||
isCallExpression(parent) &&
|
||||
@@ -60,7 +56,7 @@ function printFunction(path, options, print, args) {
|
||||
(param) => param.type === "Identifier" && !param.typeAnnotation,
|
||||
))
|
||||
) {
|
||||
shouldExpandArgument = true;
|
||||
shouldExpandParameters = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +64,7 @@ function printFunction(path, options, print, args) {
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
shouldExpandArgument,
|
||||
shouldExpandParameters,
|
||||
);
|
||||
const returnTypeDoc = printReturnType(path, print);
|
||||
const shouldGroupParameters = shouldGroupFunctionParameters(
|
||||
|
||||
@@ -51,7 +51,7 @@ function printHookTypeAnnotation(path, options, print) {
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
/* shouldExpandArgument */ false,
|
||||
/* shouldExpandParameters */ false,
|
||||
/* shouldPrintTypeParameters */ true,
|
||||
);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ function printMethodSignature(path, options, print) {
|
||||
path,
|
||||
options,
|
||||
print,
|
||||
/* shouldExpandArgument */ false,
|
||||
/* shouldExpandParameters */ false,
|
||||
/* shouldPrintTypeParameters */ true,
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user