CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-literals

Babel plugin that compiles ES2015 unicode string and number literals to ES5

86

0.97x
Overview
Eval results
Files

task.mdevals/scenario-1/

Code Transpilation Tool

Build a simple command-line tool that transforms JavaScript code files to be compatible with older JavaScript environments. The tool should process input files and output transpiled versions.

Requirements

Your tool should:

  1. Accept a JavaScript source file path as input
  2. Transform the code to be compatible with older JavaScript environments
  3. Write the transpiled output to a new file with the same name but with .transpiled.js extension
  4. Include proper error handling for file operations and transformation errors
  5. Provide basic feedback (e.g., "Successfully transpiled input.js to input.transpiled.js")

Implementation Guidelines

  • Create a main entry point file (e.g., transpile.js) that implements the CLI functionality
  • The tool should be runnable via node transpile.js <input-file>
  • Use proper asynchronous file operations
  • Ensure the transformation process is properly configured with no additional manual configuration needed

Test Cases

Test Case 1: Basic Binary and Octal Literal Transformation { .test }

Input file (test-input.js):

const binary = 0b1010;
const octal = 0o755;
console.log(binary, octal);

Expected output file (test-input.transpiled.js):

const binary = 10;
const octal = 493;
console.log(binary, octal);

Test Case 2: Mixed Literal Types { .test }

Input file (mixed.js):

const flags = 0b11110000;
const permissions = 0o644;
const hex = 0xFF;

Expected output file (mixed.transpiled.js):

const flags = 240;
const permissions = 420;
const hex = 0xFF;

Test Case 3: String with Unicode Escapes { .test }

Input file (unicode.js):

const greeting = "Hello\u{0020}World";
const emoji = "\u{1F600}";

Expected output file (unicode.transpiled.js):

const greeting = "Hello World";
const emoji = "😀";

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core transformation engine.

@babel/plugin-transform-literals { .dependency }

Provides ES2015 literal transformation capabilities.

Deliverables

  1. transpile.js - Main CLI tool implementation
  2. transpile.test.js - Test file containing the three test cases above
  3. package.json - Package configuration with required dependencies

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-es2015-literals

tile.json