lib/getArguments.js
function getArguments(f, amended)
{
  var functionCode = f.toString();
  if(amended){
    //This is a fix for when we are passed anonymous functions (which are passed to us as unassigned)
    //ex: "function (a, b, c) { }"
    //These are actually parse errors so we'll try adding an assignment to fix the parse error
    functionCode = 'var a=' + functionCode;
  }
  try{
    var ast = babylon.parse(functionCode);
    var functionDecl = findFunctionDecl(ast);

    if(!functionDecl) return [];

    return functionDecl.params.map(p => p.name);
  }catch(e){
    //try one more time
    if(!amended){
      return getArguments(f, true);
    }

    throw new Error('Could not parse:\n' + functionCode + '\n' + e);
  }
}
function getArguments(f, amended)
{
  var functionCode = f.toString();
  if(amended){
    //This is a fix for when we are passed anonymous functions (which are passed to us as unassigned)
    //ex: "function (a, b, c) { }"
    //These are actually parse errors so we'll try adding an assignment to fix the parse error
    functionCode = 'var a=' + functionCode;
  }
  try{
    var ast = babylon.parse(functionCode);
    var functionDecl = findFunctionDecl(ast);

    if(!functionDecl) return [];

    return functionDecl.params.map(p => p.name);
  }catch(e){
    //try one more time
    if(!amended){
      return getArguments(f, true);
    }

    throw new Error('Could not parse:\n' + functionCode + '\n' + e);
  }
}
function getArguments ( f , amended ) { var functionCode = f . toString ( ) ; if ( amended ) { //This is a fix for when we are passed anonymous functions (which are passed to us as unassigned) //ex: "function (a, b, c) { }" //These are actually parse errors so we'll try adding an assignment to fix the parse error functionCode = 'var a=' + functionCode ; } try { var ast = babylon . parse ( functionCode ) ; var functionDecl = findFunctionDecl ( ast ) ; if ( ! functionDecl ) return [ ] ; return functionDecl . params . map ( p => p . name ) ; } catch ( e ) { //try one more time if ( ! amended ) { return getArguments ( f , true ) ; } throw new Error ( 'Could not parse:\n' + functionCode + '\n' + e ) ; } }
Get the parameter names of a function.
@param {Function} f A function.
@return {Array.<String>} An array of the argument names of a function.
Get the parameter names of a function .