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

Function Call Logger Transformer

Build a utility that transforms JavaScript code by wrapping all function calls with a logging statement that records the function name being called.

Requirements

Your solution should:

  1. Parse JavaScript source code to identify all function call expressions
  2. Wrap each function call with a console.log statement that logs the function name
  3. Preserve the original function call and its return value
  4. Return the modified JavaScript source code as a string

For example:

  • Input: add(1, 2)
  • Output: (console.log("Calling: add"), add(1, 2))

The utility should handle:

  • Simple function calls like functionName(args)
  • Method calls like object.method(args)
  • Nested function calls

Implementation

Create a module that exports a wrapFunctionCalls function:

/**
 * Wraps all function calls in the source code with logging statements.
 * @param {string} sourceCode - The JavaScript source code to transform
 * @returns {string} The transformed code with logging around function calls
 */
function wrapFunctionCalls(sourceCode) {
  // Implementation here
}

module.exports = { wrapFunctionCalls };

Test Cases

  • Given add(1, 2) returns code that logs "Calling: add" before calling the function @test
  • Given user.getName() returns code that logs "Calling: getName" before calling the method @test
  • Given const result = multiply(3, 4); returns code where the function call is wrapped but the variable assignment works correctly @test

Dependencies { .dependencies }

@babel/parser { .dependency }

Provides JavaScript parsing to AST.

@satisfied-by

@babel/types { .dependency }

Provides AST node creation, validation, and manipulation utilities.

@satisfied-by

@babel/traverse { .dependency }

Provides AST traversal capabilities.

@satisfied-by

@babel/generator { .dependency }

Provides code generation from AST.

@satisfied-by

Install with Tessl CLI

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

tile.json