(path, options, print, args)
| 37 | - `TSDeclareFunction`(TypeScript) |
| 38 | */ |
| 39 | function printFunction(path, options, print, args) { |
| 40 | if (isMethodValue(path)) { |
| 41 | return printMethodValue(path, options, print); |
| 42 | } |
| 43 | |
| 44 | const { node } = path; |
| 45 | |
| 46 | let shouldExpandParameters = false; |
| 47 | if (node.type === "FunctionExpression" && args?.expandLastArg) { |
| 48 | const { parent } = path; |
| 49 | if ( |
| 50 | isCallExpression(parent) && |
| 51 | (getCallArguments(parent).length > 1 || |
| 52 | getFunctionParameters(node).every( |
| 53 | (param) => param.type === "Identifier" && !param.typeAnnotation, |
| 54 | )) |
| 55 | ) { |
| 56 | shouldExpandParameters = true; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | const parametersDoc = printFunctionParameters( |
| 61 | path, |
| 62 | options, |
| 63 | print, |
| 64 | shouldExpandParameters, |
| 65 | ); |
| 66 | const returnTypeDoc = printReturnType(path, print); |
| 67 | const shouldGroupParameters = shouldGroupFunctionParameters( |
| 68 | node, |
| 69 | returnTypeDoc, |
| 70 | ); |
| 71 | |
| 72 | const isFlowHookDeclaration = node.type === "HookDeclaration"; |
| 73 | const keyword = isFlowHookDeclaration ? "hook" : "function"; |
| 74 | |
| 75 | return [ |
| 76 | printDeclareToken(path), |
| 77 | node.async ? "async " : "", |
| 78 | keyword, |
| 79 | node.generator ? "*" : "", |
| 80 | " ", |
| 81 | node.id ? print("id") : "", |
| 82 | print("typeParameters"), |
| 83 | group([ |
| 84 | shouldGroupParameters ? group(parametersDoc) : parametersDoc, |
| 85 | returnTypeDoc, |
| 86 | ]), |
| 87 | node.body ? " " : "", |
| 88 | print("body"), |
| 89 | node.declare || !node.body ? printSemicolon(options) : "", |
| 90 | ]; |
| 91 | } |
| 92 | |
| 93 | /* |
| 94 | - `FunctionDeclaration` |
no test coverage detected
searching dependent graphs…