CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--plugin-proposal-object-rest-spread

Babel plugin that transforms ECMAScript object rest and spread syntax into ES5-compatible code.

85

1.06x

Quality

Pending

Does it follow best practices?

Impact

85%

1.06x

Average score across 10 eval scenarios

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

task.mdevals/scenario-1/

Module Format Converter

Build a command-line tool that converts JavaScript modules between different module formats (ES Modules, CommonJS, AMD, UMD).

Requirements

Your tool should accept JavaScript source code as input and convert it to a target module format. The tool must:

  1. Accept two command-line arguments:

    • Source file path (input JavaScript file)
    • Target format: one of commonjs, amd, umd, or esm
  2. Read the source file and transform it to the target module format

  3. Output the transformed code to stdout

  4. Handle syntax errors gracefully by printing an error message to stderr and exiting with code 1

  5. Support modern JavaScript syntax including ES2015+ features

Example Usage

node converter.js input.js commonjs

Given an input file input.js:

export const greeting = "Hello";
export function sayHello(name) {
  return `${greeting}, ${name}!`;
}

When run with target format commonjs, should output:

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.greeting = void 0;
exports.sayHello = sayHello;
const greeting = "Hello";
exports.greeting = greeting;
function sayHello(name) {
  return `${greeting}, ${name}!`;
}

Test Cases

  • It converts ES modules to CommonJS format @test
  • It converts ES modules to AMD format @test
  • It converts ES modules to UMD format @test
  • It preserves ES module format when target is esm @test
  • It handles files with syntax errors gracefully @test

Implementation

@generates

API

/**
 * Transforms JavaScript code to the specified module format
 *
 * @param {string} code - Source code to transform
 * @param {string} format - Target format: 'commonjs', 'amd', 'umd', or 'esm'
 * @returns {string} Transformed code
 */
function transformModule(code, format) {
  // Implementation here
}

module.exports = { transformModule };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides JavaScript transformation capabilities.

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

Transforms ES modules to CommonJS format.

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

Transforms ES modules to AMD format.

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

Transforms ES modules to UMD format.

tile.json