( path, options, print, shouldExpandParameters, shouldPrintTypeParameters, )
| 63 | - `ComponentTypeAnnotation` (Flow) |
| 64 | */ |
| 65 | function printFunctionParameters( |
| 66 | path, |
| 67 | options, |
| 68 | print, |
| 69 | shouldExpandParameters, |
| 70 | shouldPrintTypeParameters, |
| 71 | ) { |
| 72 | const functionNode = path.node; |
| 73 | const parameters = getFunctionParameters(functionNode); |
| 74 | const typeParametersDoc = |
| 75 | shouldPrintTypeParameters && functionNode.typeParameters |
| 76 | ? print("typeParameters") |
| 77 | : ""; |
| 78 | |
| 79 | if (parameters.length === 0) { |
| 80 | return [ |
| 81 | typeParametersDoc, |
| 82 | "(", |
| 83 | printDanglingCommentsInList( |
| 84 | path, |
| 85 | options, |
| 86 | functionParameterDanglingCommentFilter, |
| 87 | ), |
| 88 | ")", |
| 89 | ]; |
| 90 | } |
| 91 | |
| 92 | const { parent } = path; |
| 93 | const isParametersInTestCall = isTestCall(parent); |
| 94 | const shouldHugParameters = shouldHugTheOnlyFunctionParameter(functionNode); |
| 95 | const printed = []; |
| 96 | iterateFunctionParametersPath(path, (parameterPath, index) => { |
| 97 | const isLastParameter = index === parameters.length - 1; |
| 98 | if (isLastParameter && functionNode.rest) { |
| 99 | printed.push("..."); |
| 100 | } |
| 101 | printed.push(print()); |
| 102 | if (isLastParameter) { |
| 103 | return; |
| 104 | } |
| 105 | printed.push(","); |
| 106 | if (isParametersInTestCall || shouldHugParameters) { |
| 107 | printed.push(" "); |
| 108 | } else if (isNextLineEmpty(parameters[index], options)) { |
| 109 | printed.push(hardline, hardline); |
| 110 | } else { |
| 111 | printed.push(line); |
| 112 | } |
| 113 | }); |
| 114 | |
| 115 | // If the parent is a call with the first/last argument expansion and this is the |
| 116 | // params of the first/last argument, we don't want the arguments to break and instead |
| 117 | // want the whole expression to be on a new line. |
| 118 | // |
| 119 | // Good: Bad: |
| 120 | // verylongcall( verylongcall(( |
| 121 | // (a, b) => { a, |
| 122 | // } b, |
no test coverage detected
searching dependent graphs…