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

Function genericPrintNoParens

lib/printer.ts:229–2562  ·  view source on GitHub ↗
(path: any, options: any, print: any)

Source from the content-addressed store, hash-verified

227// configuration object originally passed into the Printer constructor).
228// Its properties are documented in lib/options.js.
229function genericPrintNoParens(path: any, options: any, print: any) {
230 const n = path.getValue();
231
232 if (!n) {
233 return fromString("");
234 }
235
236 if (typeof n === "string") {
237 return fromString(n, options);
238 }
239
240 namedTypes.Printable.assert(n);
241
242 const parts: (string | Lines)[] = [];
243
244 switch (n.type) {
245 case "File":
246 return path.call(print, "program");
247
248 case "Program":
249 // Babel 6
250 if (n.directives) {
251 path.each(function (childPath: any) {
252 parts.push(print(childPath), ";\n");
253 }, "directives");
254 }
255
256 if (n.interpreter) {
257 parts.push(path.call(print, "interpreter"));
258 }
259
260 parts.push(
261 path.call(
262 (bodyPath: any) => printStatementSequence(bodyPath, options, print),
263 "body",
264 ),
265 );
266
267 return concat(parts);
268
269 case "Noop": // Babel extension.
270 case "EmptyStatement":
271 return fromString("");
272
273 case "ExpressionStatement":
274 return concat([path.call(print, "expression"), ";"]);
275
276 case "ParenthesizedExpression": // Babel extension.
277 return concat(["(", path.call(print, "expression"), ")"]);
278
279 case "BinaryExpression":
280 case "LogicalExpression":
281 case "AssignmentExpression":
282 return fromString(" ").join([
283 path.call(print, "left"),
284 n.operator,
285 path.call(print, "right"),
286 ]);

Callers 1

genericPrintFunction · 0.85

Calls 15

fromStringFunction · 0.90
concatFunction · 0.90
printStatementSequenceFunction · 0.85
printFunctionParamsFunction · 0.85
printMethodFunction · 0.85
printExportDeclarationFunction · 0.85
maybeAddSemicolonFunction · 0.85
printArgumentsListFunction · 0.85
getPossibleRawFunction · 0.85
nodeStrFunction · 0.85
adjustClauseFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…