return new CodeGenerator() {
@Override
public void generate(JsWriter out, boolean first) throws IOException {
// collect the ... (rest) parameter and all optional parameters with their position index:
int restParamIndex = -1;
Parameter restParam = null;
Map<Integer,Parameter> paramByIndex = new HashMap<Integer, Parameter>();
Parameters parameters = params;
for (int paramIndex = 0; parameters != null; parameters = parameters.getTail()) {
Parameter param = parameters.getHead();
if (param.isRest()) {
restParamIndex = paramIndex;
restParam = param;
break;
}
if (param.hasInitializer()) {
paramByIndex.put(paramIndex, param);
}
++paramIndex;
}
generateParameterInitializers(out, paramByIndex);