CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-transform-parameters

Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code

91

1.02x
Overview
Eval results
Files

task.mdevals/scenario-5/

ESM to CommonJS Module Converter

Build a module converter that transforms ES Module (ESM) syntax to CommonJS format using Babel's transformation pipeline. The converter should handle various import/export patterns and generate compatible CommonJS code.

Requirements

The converter must handle the following transformations:

  1. Named imports - Convert import { foo, bar } from 'module' to appropriate require() calls
  2. Default imports - Convert import defaultValue from 'module' to CommonJS equivalents
  3. Namespace imports - Convert import * as name from 'module' to require the entire module
  4. Named exports - Convert export const foo = ... and export function bar() {} to exports assignments
  5. Default exports - Convert export default ... to module.exports or exports.default

The converter should:

  • Accept JavaScript source code as a string input
  • Return the transformed CommonJS code as a string
  • Preserve the functionality of the original code
  • Handle mixed import/export patterns in a single file

Test Cases

  • Converting import { add } from './math' followed by export const result = add(1, 2) produces valid CommonJS with require() and exports @test
  • Converting import Calculator from './calculator' produces CommonJS that accesses the default export correctly @test
  • Converting import * as utils from './utils' produces CommonJS that assigns the entire module to a variable @test
  • Converting export default function process() {} produces valid CommonJS default export @test

Implementation

@generates

API

/**
 * Converts ES Module syntax to CommonJS format
 *
 * @param {string} code - JavaScript source code with ESM syntax
 * @returns {string} Transformed code using CommonJS require/exports
 */
function convertToCommonJS(code) {
  // Implementation here
}

module.exports = { convertToCommonJS };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core transformation API for compiling JavaScript code.

@babel/plugin-transform-modules-commonjs { .dependency }

Transforms ES2015 modules to CommonJS format.

Install with Tessl CLI

npx tessl i tessl/npm-babel--plugin-transform-parameters

tile.json