Babel plugin that compiles ES2015 default and rest parameters to ES5-compatible code
91
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.
The converter must handle the following transformations:
import { foo, bar } from 'module' to appropriate require() callsimport defaultValue from 'module' to CommonJS equivalentsimport * as name from 'module' to require the entire moduleexport const foo = ... and export function bar() {} to exports assignmentsexport default ... to module.exports or exports.defaultThe converter should:
import { add } from './math' followed by export const result = add(1, 2) produces valid CommonJS with require() and exports @testimport Calculator from './calculator' produces CommonJS that accesses the default export correctly @testimport * as utils from './utils' produces CommonJS that assigns the entire module to a variable @testexport default function process() {} produces valid CommonJS default export @test@generates
/**
* 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 };Provides the core transformation API for compiling JavaScript code.
Transforms ES2015 modules to CommonJS format.
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