MCPcopy Create free account
hub / github.com/babel/babel / FunctionTypeAnnotation

Function FunctionTypeAnnotation

packages/babel-generator/src/generators/flow.ts:312–362  ·  view source on GitHub ↗
(
  this: Printer,
  node: t.FunctionTypeAnnotation,
  parent?: t.Node,
)

Source from the content-addressed store, hash-verified

310}
311
312export function FunctionTypeAnnotation(
313 this: Printer,
314 node: t.FunctionTypeAnnotation,
315 parent?: t.Node,
316) {
317 this.print(node.typeParameters);
318 this.token("(");
319
320 if (node.this) {
321 this.word("this");
322 this.token(":");
323 this.space();
324 this.print(node.this.typeAnnotation);
325 if (node.params.length || node.rest) {
326 this.token(",");
327 this.space();
328 }
329 }
330
331 this.printList(node.params);
332
333 if (node.rest) {
334 if (node.params.length) {
335 this.token(",");
336 this.space();
337 }
338 this.token("...");
339 this.print(node.rest);
340 }
341
342 this.token(")");
343
344 // this node type is overloaded, not sure why but it makes it EXTREMELY annoying
345
346 const type = parent?.type;
347 if (
348 type != null &&
349 (type === "ObjectTypeCallProperty" ||
350 type === "ObjectTypeInternalSlot" ||
351 type === "DeclareFunction" ||
352 (type === "ObjectTypeProperty" && parent.method))
353 ) {
354 this.token(":");
355 } else {
356 this.space();
357 this.token("=>");
358 }
359
360 this.space();
361 this.print(node.returnType);
362}
363
364export function FunctionTypeParam(this: Printer, node: t.FunctionTypeParam) {
365 this.print(node.name);

Callers

nothing calls this directly

Calls 5

printMethod · 0.45
tokenMethod · 0.45
wordMethod · 0.45
spaceMethod · 0.45
printListMethod · 0.45

Tested by

no test coverage detected