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

ES2015 Hexadecimal Literal Formatter

Build a Babel plugin that formats hexadecimal numeric literals for improved readability.

Background

Modern codebases often contain hexadecimal literals that represent various values like colors, memory addresses, or bit masks. While these values are functionally correct, they can benefit from consistent formatting to improve code readability.

Requirements

Create a Babel plugin that processes JavaScript/TypeScript code and applies formatting rules to hexadecimal numeric literals (those starting with 0x or 0X).

Your plugin should:

  1. Normalize prefix casing: Convert all hexadecimal prefixes to lowercase (0x)
  2. Normalize digit casing: Convert all hexadecimal digits (a-f) to uppercase
  3. Preserve numeric values: Ensure the transformed code maintains semantic equivalence
  4. Handle member expressions: Support hexadecimal literals used with method calls (e.g., 0xff.toString())

The plugin should transform code like this:

// Input
const color = 0XaBcDeF;
const mask = 0x1a2b;
const value = 0Xff.toString();

// Output
const color = 0xABCDEF;
const mask = 0x1A2B;
const value = 0xFF.toString();

Implementation

@generates

API

/**
 * Babel plugin that formats hexadecimal literals
 * @returns {Object} Babel plugin object
 */
export default function() {
  // Implementation here
}

Test Cases

  • Transforms 0xabc to 0xABC @test
  • Transforms 0XDEF to 0xDEF @test
  • Transforms 0XaBc123 to 0xABC123 @test
  • Handles member expressions like 0xff.toString() correctly @test

Dependencies { .dependencies }

@babel/helper-plugin-utils { .dependency }

Provides utilities for creating Babel plugins with proper versioning and API compatibility.

@babel/core { .dependency }

Core Babel transformation system. Required for plugin development and testing.

Install with Tessl CLI

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

tile.json