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-8/

AST Function Analyzer

Build a utility that analyzes JavaScript function AST nodes to extract information about their signatures and generate composition helpers.

Capabilities

Arity analysis for AST nodes

Analyze function AST nodes to determine their effective arity (required parameter count).

  • Given a function AST node with parameters (a, b, c), the analyzer returns arity 3 @test
  • Given a function AST node with parameters (a, b = 10, c), the analyzer returns arity 1 because b has a default value @test
  • Given a function AST node with parameters (a, b, ...rest), the analyzer returns arity 2 because rest parameters are not counted @test

Currying wrapper generation

Generate curried wrapper functions based on AST analysis of the original function's arity.

  • Given a function AST node (a, b) => a + b, generate a curried wrapper that allows calling with one argument at a time @test
  • Given a function AST node (x, y = 5) => x * y, generate a curried wrapper that only requires the first parameter @test

Implementation

@generates

API

/**
 * Analyzes a function AST node and returns its effective arity
 * (number of required parameters before the first optional or rest parameter).
 *
 * @param {import('@babel/types').Function} functionNode - A Babel AST function node
 * @returns {number} The effective arity of the function
 */
function getArity(functionNode) {
  // IMPLEMENTATION HERE
}

/**
 * Generates a curried wrapper function based on the arity of a function AST node.
 * Returns AST nodes representing a curried version of the input function.
 *
 * @param {import('@babel/types').Function} functionNode - A Babel AST function node
 * @returns {import('@babel/types').FunctionExpression} An AST node for the curried wrapper
 */
function generateCurriedWrapper(functionNode) {
  // IMPLEMENTATION HERE
}

module.exports = {
  getArity,
  generateCurriedWrapper,
};

Dependencies { .dependencies }

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

Helper function to determine the effective arity of JavaScript functions.

@satisfied-by

@babel/types { .dependency }

Provides utilities for creating and manipulating Babel AST nodes.

@satisfied-by

Install with Tessl CLI

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

tile.json