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

Number Literal Method Transformer

Build a command-line tool that transforms JavaScript files containing ES2015 numeric literals used in method calls and member expressions to ES5-compatible code.

Requirements

Your tool should:

  1. Accept a JavaScript source file path as a command-line argument
  2. Transform all ES2015 binary and octal numeric literals that are used with member expressions (e.g., method calls like .toString(), .toFixed())
  3. Output the transformed ES5-compatible JavaScript code to stdout
  4. Preserve the behavior and semantics of the original code

Input Format

Your program will receive a file path as the first command-line argument:

node src/index.js input.js

The input file will contain JavaScript code with ES2015 numeric literal syntax (binary with 0b/0B prefix, octal with 0o/0O prefix) used in member expressions.

Output Format

Your program should output the transformed JavaScript code to stdout, where:

  • Binary literals (e.g., 0b1111) are converted to their decimal equivalents (e.g., 15)
  • Octal literals (e.g., 0o755) are converted to their decimal equivalents (e.g., 493)
  • The member expressions remain intact and functional
  • All other code is preserved as-is

Test Cases

Test Case 1: Binary literal with toString() { .test }

Input file content:

const result = 0b1111.toString();

Expected output:

const result = (15).toString();
  • Binary literal 0b1111 (15 in decimal) is used with .toString() method @test

Test Case 2: Octal literal with toFixed() { .test }

Input file content:

const value = 0o10.toFixed(2);

Expected output:

const value = (8).toFixed(2);
  • Octal literal 0o10 (8 in decimal) is used with .toFixed(2) method @test

Test Case 3: Uppercase prefix variants { .test }

Input file content:

const a = 0B101.valueOf();
const b = 0O77.valueOf();

Expected output:

const a = (5).valueOf();
const b = (63).valueOf();
  • Uppercase binary 0B101 and octal 0O77 are transformed correctly @test

Implementation

@generates

API

// Your program should be executable as a Node.js script
// It reads a file path from process.argv[2]
// It outputs the transformed code to stdout

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the core Babel transformation API for parsing and generating JavaScript code.

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

Babel plugin that transforms ES2015 binary and octal numeric literals to ES5-compatible decimal format.

Install with Tessl CLI

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

tile.json