public override parameterDeclaration()

in src/languages/python.ts [355:384]


  public override parameterDeclaration(node: ts.ParameterDeclaration, context: PythonVisitorContext): OTree {
    const type = node.type && context.typeOfType(node.type);

    if (
      context.currentContext.tailPositionParameter &&
      type &&
      analyzeStructType(context.typeChecker, type) !== false
    ) {
      // Return the parameter that we exploded so that we can use this information
      // while translating the body.
      if (context.currentContext.returnExplodedParameter) {
        context.currentContext.returnExplodedParameter.value = {
          variableName: context.textOf(node.name),
          type,
        };
      }

      // Explode to fields
      return new OTree([], ['*', ...propertiesOfStruct(type, context).map(renderStructProperty)], { separator: ', ' });
    }

    const suffix = parameterAcceptsUndefined(node, type) ? '=None' : '';

    return new OTree([node.dotDotDotToken ? '*' : '', context.convert(node.name), suffix]);

    function renderStructProperty(prop: StructProperty): string {
      const sfx = structPropertyAcceptsUndefined(prop) ? '=None' : '';
      return prop.name + sfx;
    }
  }