CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--helper-module-imports

Babel helper functions for inserting module loads

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-7/

Legacy Browser Compatibility Transformer

Build a JavaScript code transformation tool that converts modern block-scoped variable declarations (let/const) into ES5-compatible code for legacy browser support.

Requirements

Your tool must transform JavaScript source code to ensure compatibility with older browsers by converting block-scoped variable declarations into function-scoped equivalents.

Functionality

  • Accept JavaScript source code as a string
  • Transform all let and const declarations to be compatible with ES5
  • Return the transformed code as a string
  • Handle various scoping contexts: functions, blocks, loops, and nested scopes
  • Preserve the original program behavior after transformation

Test Cases

  • Given code with a simple let declaration in a function, the tool transforms it to use var while preserving behavior @test
  • Given code with const declarations, the tool transforms them appropriately while maintaining immutability semantics @test
  • Given code with let in a for loop, the tool correctly transforms it to preserve per-iteration binding @test
  • Given code with let in nested blocks, the tool correctly handles the block scoping by introducing appropriate variable renaming @test

Implementation

@generates

API

/**
 * Transform JavaScript code to convert block-scoped variables to function-scoped equivalents
 *
 * @param {string} code - The JavaScript source code to transform
 * @returns {string} The transformed JavaScript code compatible with ES5 environments
 * @throws {Error} If the input code cannot be parsed or transformed
 */
function transformBlockScoping(code) {
  // Implementation here
}

module.exports = { transformBlockScoping };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core transformation engine for compiling JavaScript code.

@babel/plugin-transform-block-scoping { .dependency }

Handles the transformation of block-scoped variable declarations (let/const) to var.

Install with Tessl CLI

npx tessl i tessl/npm-babel--helper-module-imports

tile.json