Helper function to get function arity by analyzing parameter lists for assignment patterns and rest parameters
95
Build a static analysis tool that analyzes JavaScript/TypeScript code to generate a report on function signatures and their parameter requirements.
Your tool should analyze JavaScript source code files and produce a JSON report containing:
The tool should handle all JavaScript function types including:
@generates
/**
* Analyzes JavaScript source code and generates a function signature report
*
* @param {string} sourceCode - The JavaScript source code to analyze
* @returns {Object} Analysis report with function details and summary statistics
*
* Report structure:
* {
* functions: [
* {
* name: string, // Function name or "<anonymous>"
* type: string, // Function type (e.g., "FunctionDeclaration")
* totalParams: number, // Total parameter count
* requiredParams: number, // Required parameter count
* hasOptional: boolean, // Has default parameters
* hasRest: boolean // Has rest parameter
* }
* ],
* summary: {
* totalFunctions: number,
* avgRequiredParams: number,
* highArityCount: number // Functions with > 3 required params
* }
* }
*/
function analyzeFunctions(sourceCode) {
// IMPLEMENTATION HERE
}
module.exports = { analyzeFunctions };Parses JavaScript source code into an Abstract Syntax Tree (AST).
Traverses the AST to find and visit function nodes.
Determines the effective arity (required parameter count) of functions.
Provides utilities for checking AST node types and properties.
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