Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code
91
A Babel transformation tool that automatically adds context information to console.log statements in JavaScript code.
Create a code transformation tool that processes JavaScript files and enriches console.log statements with contextual information. When the tool encounters a console.log statement, it should prepend the function name (or "global" if not inside a function) to the logged message.
The tool should accept JavaScript source code as input and return the transformed code as output.
The tool should return valid JavaScript code that can be executed. The transformed code should maintain the same behavior as the original, with the addition of context information in console.log statements.
Input:
function calculateSum(a, b) {
console.log("Adding numbers");
return a + b;
}Output:
function calculateSum(a, b) {
console.log("[calculateSum]", "Adding numbers");
return a + b;
}Input:
console.log("Application started");
function init() {
console.log("Initializing");
}Output:
console.log("[global]", "Application started");
function init() {
console.log("[init]", "Initializing");
}@generates
/**
* Transforms JavaScript source code to add context to console.log statements.
*
* @param {string} sourceCode - The JavaScript source code to transform
* @returns {string} The transformed JavaScript code with enhanced console.log statements
*/
function transform(sourceCode) {
// IMPLEMENTATION HERE
}
module.exports = { transform };Provides the core Babel transformation API for compiling JavaScript code.
Provides utilities for AST node manipulation and creation.
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