CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--helper-get-function-arity

Helper function to get function arity by analyzing parameter lists for assignment patterns and rest parameters

95

1.06x
Overview
Eval results
Files

task.mdevals/scenario-9/

Function Parameter Analyzer

Build a utility that analyzes JavaScript function parameter types and provides detailed information about the parameter structure of function declarations.

Capabilities

Analyze parameter types

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).

  • Given a function with parameters (a, b, c), return an array indicating all three are identifiers @test
  • Given a function with parameters (a, b = 10, c), return an array showing the second parameter is a default parameter @test
  • Given a function with parameters (a, b, ...rest), return an array showing the third parameter is a rest parameter @test
  • Given a function with parameters ({x, y}, z), return an array showing the first parameter is a destructuring pattern @test

Categorize parameters by type

Create a function that categorizes all parameters in a function by their type, returning counts of each parameter category.

  • Given a function with mixed parameter types (a, b = 5, c, ...rest), return counts showing 2 regular parameters, 1 default parameter, and 1 rest parameter @test
  • Given a function with all regular parameters (x, y, z), return counts showing 3 regular parameters and 0 for other types @test

Implementation

@generates

API

/**
 * 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);

Dependencies { .dependencies }

@babel/helper-get-function-arity { .dependency }

Provides function arity analysis and parameter inspection capabilities.

@satisfied-by

@babel/types { .dependency }

Provides AST node type checking and manipulation utilities.

@satisfied-by

@babel/parser { .dependency }

Provides JavaScript parsing to generate AST nodes for testing.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel--helper-get-function-arity

tile.json