convertParameters method

String convertParameters (
  1. List<ParameterElement> parameters
)

Implementation

String convertParameters(List<ParameterElement> parameters) {
  final nonNamedParams = parameters.where((p) => !p.isNamed);
  final namedParams = parameters.where((p) => p.isNamed);

  final parameterList = StringBuffer()
    ..write(nonNamedParams.map(convertParameterToJs).join(', '));
  if (namedParams.isNotEmpty) {
    if (nonNamedParams.isNotEmpty) parameterList.write(',');
    parameterList
      ..write('() {')
      ..write("final o = JsObject(context['Object']);");
    for (final p in namedParams) {
      parameterList
        ..write('if (${p.displayName} != null)')
        ..write(" o['${p.displayName}'] = ${convertParameterToJs(p)};");
    }
    parameterList.write('return o;} ()');
  }
  return parameterList.toString();
}