MCPcopy
hub / github.com/prettier/prettier / printFunction

Function printFunction

src/language-js/print/function.js:39–91  ·  view source on GitHub ↗
(path, options, print, args)

Source from the content-addressed store, hash-verified

37- `TSDeclareFunction`(TypeScript)
38*/
39function 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`

Callers 3

printFlowFunction · 0.90
printEstreeFunction · 0.90
printTypescriptFunction · 0.90

Calls 11

getCallArgumentsFunction · 0.90
getFunctionParametersFunction · 0.90
printFunctionParametersFunction · 0.90
printDeclareTokenFunction · 0.90
groupFunction · 0.90
printSemicolonFunction · 0.90
isMethodValueFunction · 0.85
printMethodValueFunction · 0.85
printReturnTypeFunction · 0.85
printFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…