Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code
91
Build a tool that analyzes JavaScript source code to extract information about function declarations and their parameters.
Your tool should parse JavaScript source code and extract detailed information about all function declarations in the code, including:
The tool should handle multiple source types (module, script) and provide accurate parameter information.
@generates
/**
* 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 };"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"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"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"function foo(x) {} function bar(y, z) {}", the analyzer returns two function objects with correct names and parameters @testProvides 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-parametersdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10