MCPcopy
hub / github.com/prettier/prettier / printFunctionParameters

Function printFunctionParameters

src/language-js/print/function-parameters.js:65–196  ·  view source on GitHub ↗
(
  path,
  options,
  print,
  shouldExpandParameters,
  shouldPrintTypeParameters,
)

Source from the content-addressed store, hash-verified

63- `ComponentTypeAnnotation` (Flow)
64*/
65function 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,

Callers 7

printComponentFunction · 0.90
printMethodSignatureFunction · 0.90
printFunctionFunction · 0.90
printMethodValueFunction · 0.90
printHookTypeAnnotationFunction · 0.90
printFunctionTypeFunction · 0.90

Calls 15

getFunctionParametersFunction · 0.90
isTestCallFunction · 0.90
isNextLineEmptyFunction · 0.90
willBreakFunction · 0.90
groupFunction · 0.90
removeLinesFunction · 0.90
isSimpleTypeFunction · 0.90
indentFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…