static ImmutableMap<String, Node> getFunctionCallParameterMap(
      final Node fnNode, Node callNode, Supplier<String> safeNameIdSupplier) {
    checkNotNull(fnNode);
    // Create an argName -> expression map
    ImmutableMap.Builder<String, Node> argMap = ImmutableMap.builder();

    // CALL NODE: [ NAME, ARG1, ARG2, ... ]
    Node cArg = callNode.getSecondChild();
    if (cArg != null && NodeUtil.isFunctionObjectCall(callNode)) {
      argMap.put(THIS_MARKER, cArg);
      cArg = cArg.getNext();
    } else {
      // 'apply' isn't supported yet.
      checkState(!NodeUtil.isFunctionObjectApply(callNode), callNode);
      argMap.put(THIS_MARKER, NodeUtil.newUndefinedNode(callNode));
    }

    for (Node fnParam : NodeUtil.getFunctionParameters(fnNode).children()) {
      if (cArg != null) {
        if (fnParam.isRest()) {
          checkState(fnParam.getOnlyChild().isName(), fnParam.getOnlyChild());
          Node array = IR.arraylit();
          array.useSourceInfoIfMissingFromForTree(cArg);
          while (cArg != null) {
            array.addChildToBack(cArg.cloneTree());
            cArg = cArg.getNext();
          }
          argMap.put(fnParam.getOnlyChild().getString(), array);
          return argMap.build();
        } else {
          checkState(fnParam.isName(), fnParam);
          argMap.put(fnParam.getString(), cArg);
        }
        cArg = cArg.getNext();
      } else { // cArg != null
        if (fnParam.isRest()) {
          checkState(fnParam.getOnlyChild().isName(), fnParam);
          //No arguments for REST parameters
          Node array = IR.arraylit();
          argMap.put(fnParam.getOnlyChild().getString(), array);
        } else {
          checkState(fnParam.isName(), fnParam);
          Node srcLocation = callNode;
          argMap.put(fnParam.getString(), NodeUtil.newUndefinedNode(srcLocation));
        }
      }
    }

    // Add temp names for arguments that don't have named parameters in the
    // called function.
    while (cArg != null) {
      String uniquePlaceholder = getUniqueAnonymousParameterName(safeNameIdSupplier);
      argMap.put(uniquePlaceholder, cArg);
      cArg = cArg.getNext();
    }

    return argMap.build();
  }
static ImmutableMap < String , Node > getFunctionCallParameterMap ( final Node fnNode , Node callNode , Supplier < String > safeNameIdSupplier ) { checkNotNull ( fnNode ) ; ImmutableMap . Builder < String , Node > argMap = ImmutableMap . builder ( ) ; Node cArg = callNode . getSecondChild ( ) ; if ( cArg != null && NodeUtil . isFunctionObjectCall ( callNode ) ) { argMap . put ( THIS_MARKER , cArg ) ; cArg = cArg . getNext ( ) ; } else { checkState ( ! NodeUtil . isFunctionObjectApply ( callNode ) , callNode ) ; argMap . put ( THIS_MARKER , NodeUtil . newUndefinedNode ( callNode ) ) ; } for ( Node fnParam : NodeUtil . getFunctionParameters ( fnNode ) . children ( ) ) { if ( cArg != null ) { if ( fnParam . isRest ( ) ) { checkState ( fnParam . getOnlyChild ( ) . isName ( ) , fnParam . getOnlyChild ( ) ) ; Node array = IR . arraylit ( ) ; array . useSourceInfoIfMissingFromForTree ( cArg ) ; while ( cArg != null ) { array . addChildToBack ( cArg . cloneTree ( ) ) ; cArg = cArg . getNext ( ) ; } argMap . put ( fnParam . getOnlyChild ( ) . getString ( ) , array ) ; return argMap . build ( ) ; } else { checkState ( fnParam . isName ( ) , fnParam ) ; argMap . put ( fnParam . getString ( ) , cArg ) ; } cArg = cArg . getNext ( ) ; } else { if ( fnParam . isRest ( ) ) { checkState ( fnParam . getOnlyChild ( ) . isName ( ) , fnParam ) ; Node array = IR . arraylit ( ) ; argMap . put ( fnParam . getOnlyChild ( ) . getString ( ) , array ) ; } else { checkState ( fnParam . isName ( ) , fnParam ) ; Node srcLocation = callNode ; argMap . put ( fnParam . getString ( ) , NodeUtil . newUndefinedNode ( srcLocation ) ) ; } } } while ( cArg != null ) { String uniquePlaceholder = getUniqueAnonymousParameterName ( safeNameIdSupplier ) ; argMap . put ( uniquePlaceholder , cArg ) ; cArg = cArg . getNext ( ) ; } return argMap . build ( ) ; }
Get a mapping for function parameter names to call arguments.