CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-eval

Babel plugin that transforms eval() calls containing string literals by parsing and compiling the string content at transform time

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-2/

Code Transpilation Tool

Build a command-line tool that transpiles modern JavaScript/TypeScript code to support older browsers and environments. The tool should support multiple input file types and provide appropriate transformations based on the file type.

Requirements

Core Functionality

The tool should accept a source file path as input and output transpiled JavaScript code that is compatible with older environments.

File Type Support

  1. TypeScript Files (.ts): Remove TypeScript type annotations and syntax, converting to standard JavaScript
  2. React/JSX Files (.jsx): Transform JSX syntax into standard JavaScript function calls
  3. Modern JavaScript (.js): Transform modern ECMAScript features (ES6+) to ES5-compatible code

Target Environment

The transpiled output should be compatible with:

  • Internet Explorer 11
  • Node.js 8
  • Chrome 60
  • Firefox 55

Command-Line Interface

The tool should be invoked as:

node transpile.js <input-file>

The output should be written to stdout.

Test Cases

  • Given a TypeScript file containing type annotations, the tool outputs JavaScript without type syntax @test
  • Given a JSX file with React components, the tool outputs JavaScript with transformed JSX @test
  • Given a modern JavaScript file with ES6+ features (arrow functions, const/let, template literals), the tool outputs ES5-compatible code @test
  • Given a file that doesn't exist, the tool handles the error gracefully @test

Implementation

@generates

API

/**
 * Transpile a source file to browser-compatible JavaScript
 * @param {string} filePath - Path to the source file
 * @returns {Promise<string>} Transpiled JavaScript code
 */
async function transpileFile(filePath) {
  // Implementation here
}

module.exports = { transpileFile };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides JavaScript compilation and transformation capabilities.

@babel/preset-env { .dependency }

Provides smart defaults for transforming modern JavaScript based on target environments.

@babel/preset-react { .dependency }

Provides React JSX transformation support.

@babel/preset-typescript { .dependency }

Provides TypeScript syntax support and type stripping.

Install with Tessl CLI

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

tile.json