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

Function FunctionTypeAnnotation

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

Source from the content-addressed store, hash-verified

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