Babel plugin to ensure function declarations at the block level are block scoped
89
Build a code transformation tool that converts block-scoped function declarations into properly scoped variable declarations. Your tool should preserve function identity while ensuring correct block-level scoping semantics.
Your transformer should:
{ }) into let-bound variable declarationsIn strict mode, convert block-scoped function declarations to let-bound variables:
// Input (strict mode)
{
function greet() {
return "hello";
}
}
// Expected Output
{
let greet = function() {
return "hello";
};
}The transformer must handle:
async function)function*)Do NOT transform functions that are:
@generates
Implement your solution using the Babel transformation pipeline to process JavaScript AST and transform function declarations appropriately.
/**
* Transform block-scoped function declarations into let-bound variables
* @param {string} code - JavaScript code to transform
* @param {object} options - Transformation options
* @param {boolean} options.strictMode - Whether to treat code as strict mode
* @returns {string} Transformed JavaScript code
*/
function transformBlockScopedFunctions(code, options) {
// Implementation here
}
module.exports = { transformBlockScopedFunctions };Provides block-scoped function transformation capabilities for JavaScript code.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel--plugin-transform-block-scoped-functions