Helper function to get function arity by analyzing parameter lists for assignment patterns and rest parameters
95
Build a utility that analyzes JavaScript function parameter types and provides detailed information about the parameter structure of function declarations.
Create a function that takes Babel AST nodes representing JavaScript functions and returns information about each parameter's type (regular identifier, default parameter, rest parameter, or destructuring pattern).
(a, b, c), return an array indicating all three are identifiers @test(a, b = 10, c), return an array showing the second parameter is a default parameter @test(a, b, ...rest), return an array showing the third parameter is a rest parameter @test({x, y}, z), return an array showing the first parameter is a destructuring pattern @testCreate a function that categorizes all parameters in a function by their type, returning counts of each parameter category.
(a, b = 5, c, ...rest), return counts showing 2 regular parameters, 1 default parameter, and 1 rest parameter @test(x, y, z), return counts showing 3 regular parameters and 0 for other types @test@generates
/**
* Analyzes parameter types in a function node
* @param {Node} functionNode - A Babel AST function node
* @returns {Array<{index: number, type: string}>} Array of parameter information
*/
export function analyzeParameters(functionNode);
/**
* Categorizes parameters by type
* @param {Node} functionNode - A Babel AST function node
* @returns {{identifiers: number, defaults: number, rest: number, patterns: number}} Parameter counts by type
*/
export function categorizeParameters(functionNode);Provides function arity analysis and parameter inspection capabilities.
@satisfied-by
Provides AST node type checking and manipulation utilities.
@satisfied-by
Provides JavaScript parsing to generate AST nodes for testing.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel--helper-get-function-aritydocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10