Babel plugin to ensure function declarations at the block level are block scoped
89
Build a JavaScript code transpiler that transforms function declarations within block statements to ensure proper block-level scoping.
Your transpiler should:
Transform Block-Level Function Declarations: Convert function declarations inside block statements (curly braces) into let-bound variable declarations with function expressions. Preserve the original function name in the variable binding.
Handle Strict Mode Contexts: Apply transformation to all function declarations when code is in strict mode. In non-strict mode, only transform async functions and generator functions.
Process Switch Case Statements: Transform function declarations within switch case bodies using the same rules as block statements.
Skip Function Body Contexts: Do not transform function declarations that are direct children of function bodies
@generates
/**
* Transforms JavaScript code to ensure block-scoped function declarations.
*
* @param {string} code - The JavaScript code to transform
* @param {Object} options - Transformation options
* @param {boolean} options.strictMode - Whether to treat the code as strict mode
* @returns {string} The transformed JavaScript code
*/
function transform(code, options) {
// Implementation
}
module.exports = { transform };Provides block-scoped function transformation capabilities.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel--plugin-transform-block-scoped-functions