Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code
91
Build a JavaScript code transformation tool that automatically instruments code with logging statements for debugging purposes.
Create a tool that transforms JavaScript source code by inserting console.log statements at key points in the code. The tool should parse JavaScript code, traverse its AST (Abstract Syntax Tree), and inject logging statements before function declarations and return statements.
@generates
Your implementation should:
/**
* Transforms JavaScript source code by adding console.log statements
* @param {string} sourceCode - The JavaScript source code to transform
* @returns {string} The transformed JavaScript code with added logging
*/
function instrumentCode(sourceCode);
module.exports = { instrumentCode };Given source code function add(a, b) { return a + b; }, the transformed code contains console.log('Entering function: add') as the first statement in the function body @test
Given source code function getValue() { return 42; }, the transformed code contains both console.log('Entering function: getValue') at the start and console.log('Returning from getValue') before the return statement @test
function foo() { return 1; } function bar() { return 2; }, both functions are instrumented with their respective entering and returning logs @testProvides JavaScript parsing capabilities to convert source code into an AST.
@satisfied-by
Provides AST traversal capabilities using the visitor pattern to locate and modify specific node types.
@satisfied-by
Converts the modified AST back into JavaScript source code.
@satisfied-by
Provides utilities for creating and manipulating AST nodes.
@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