MCPcopy
hub / github.com/benjamn/recast / genericPrint

Function genericPrint

lib/printer.ts:188–223  ·  view source on GitHub ↗
(path: any, config: any, options: any, printPath: any)

Source from the content-addressed store, hash-verified

186export { Printer };
187
188function genericPrint(path: any, config: any, options: any, printPath: any) {
189 assert.ok(path instanceof FastPath);
190
191 const node = path.getValue();
192 const parts = [];
193 const linesWithoutParens = genericPrintNoParens(path, config, printPath);
194
195 if (!node || linesWithoutParens.isEmpty()) {
196 return linesWithoutParens;
197 }
198
199 let shouldAddParens = false;
200 const decoratorsLines = printDecorators(path, printPath);
201
202 if (decoratorsLines.isEmpty()) {
203 // Nodes with decorators can't have parentheses, so we can avoid
204 // computing path.needsParens() except in this case.
205 if (!options.avoidRootParens) {
206 shouldAddParens = path.needsParens();
207 }
208 } else {
209 parts.push(decoratorsLines);
210 }
211
212 if (shouldAddParens) {
213 parts.unshift("(");
214 }
215
216 parts.push(linesWithoutParens);
217
218 if (shouldAddParens) {
219 parts.push(")");
220 }
221
222 return concat(parts);
223}
224
225// Note that the `options` parameter of this function is what other
226// functions in this file call the `config` object (that is, the

Callers 2

printFunction · 0.85
printGenericallyFunction · 0.85

Calls 6

concatFunction · 0.90
genericPrintNoParensFunction · 0.85
printDecoratorsFunction · 0.85
getValueMethod · 0.80
isEmptyMethod · 0.80
needsParensMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…