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-2/

Modern JavaScript Transpiler

Build a tool that transpiles modern JavaScript code to ES5-compatible code for older browser environments.

Requirements

Your tool should transform JavaScript source code to run in older environments. It must:

  1. Transform modern JavaScript syntax to ES5-compatible code
  2. Configure target environments (e.g., IE 11, Chrome 58) to control which transformations are applied
  3. Generate source maps for debugging transformed code
  4. Handle errors gracefully with clear error messages

The tool should process string input and return transformed output.

Behavior

  • Accept JavaScript source code as a string
  • Transform the code based on target environment configuration
  • Return transformed code and source maps
  • Handle invalid syntax with descriptive error messages

Test Cases

  • Transforms arrow functions to regular functions @test
  • Transforms async/await to generator functions @test
  • Transforms class syntax to constructor functions @test
  • Generates valid source maps @test
  • Reports syntax errors with helpful messages @test

Implementation

@generates

API

/**
 * Transpiles JavaScript code to ES5-compatible syntax.
 *
 * @param {string} code - The source code to transpile
 * @param {object} options - Configuration options
 * @param {string[]} options.targets - Target browser environments (e.g., ['ie 11', 'chrome 58'])
 * @param {boolean} options.sourceMaps - Whether to generate source maps (default: false)
 * @param {string} options.filename - Source filename for error reporting
 * @returns {object} Result object with code, map, and metadata
 * @throws {Error} Throws an error if transformation fails
 */
function transpile(code, options) {
  // IMPLEMENTATION HERE
}

/**
 * Transpiles a JavaScript file and writes output to disk.
 *
 * @param {string} inputPath - Path to input JavaScript file
 * @param {string} outputPath - Path to output JavaScript file
 * @param {object} options - Configuration options (same as transpile)
 * @returns {Promise<void>}
 * @throws {Error} Throws an error if file operations or transformation fail
 */
async function transpileFile(inputPath, outputPath, options) {
  // IMPLEMENTATION HERE
}

module.exports = {
  transpile,
  transpileFile,
};

Dependencies { .dependencies }

@babel/core { .dependency }

Provides JavaScript compilation and transformation APIs.

@babel/preset-env { .dependency }

Provides environment-based transformation presets.

Install with Tessl CLI

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

tile.json