CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-transform-parameters

Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code

91

1.02x
Overview
Eval results
Files

task.mdevals/scenario-3/

Source Code Analyzer

Build a tool that analyzes JavaScript source code to extract information about function declarations and their parameters.

Requirements

Your tool should parse JavaScript source code and extract detailed information about all function declarations in the code, including:

  1. Function name
  2. Parameter names
  3. Whether parameters have default values
  4. Whether the function uses rest parameters

The tool should handle multiple source types (module, script) and provide accurate parameter information.

Implementation

@generates

API

/**
 * Analyzes JavaScript source code and returns information about all functions
 * @param {string} sourceCode - The JavaScript source code to analyze
 * @param {object} options - Parsing options
 * @param {string} options.sourceType - Source type: 'module', 'script', or 'unambiguous'
 * @returns {Array<FunctionInfo>} Array of function information objects
 */
function analyzeFunctions(sourceCode, options = { sourceType: 'module' }) {
  // Implementation here
}

/**
 * @typedef {object} FunctionInfo
 * @property {string} name - Function name
 * @property {Array<ParameterInfo>} parameters - Array of parameter information
 * @property {number} line - Line number where function is declared
 */

/**
 * @typedef {object} ParameterInfo
 * @property {string} name - Parameter name
 * @property {boolean} hasDefault - Whether parameter has a default value
 * @property {boolean} isRest - Whether this is a rest parameter
 */

module.exports = { analyzeFunctions };

Test Cases

Basic function parsing

  • Given source code "function greet(name) { return 'Hello ' + name; }", the analyzer returns one function named "greet" with one parameter "name" that has no default and is not a rest parameter @test

Default parameters

  • Given source code "function add(a = 0, b = 0) { return a + b; }", the analyzer returns one function named "add" with two parameters "a" and "b" that both have defaults @test

Rest parameters

  • Given source code "function sum(...numbers) { return numbers.reduce((a, b) => a + b, 0); }", the analyzer returns one function named "sum" with one parameter "numbers" that is a rest parameter @test

Multiple functions

  • Given source code containing two functions "function foo(x) {} function bar(y, z) {}", the analyzer returns two function objects with correct names and parameters @test

Dependencies { .dependencies }

@babel/parser { .dependency }

Provides JavaScript/TypeScript parsing capabilities to convert source code into Abstract Syntax Trees (AST).

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel--plugin-transform-parameters

tile.json