CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-computed-properties

Babel plugin that compiles ES2015 computed properties to ES5-compatible code

88

1.07x
Overview
Eval results
Files

task.mdevals/scenario-10/

Babel Code Transformer

A Babel transformer that converts modern JavaScript with computed property names to ES5-compatible code.

Requirements

Build a code transformation utility that:

  • Parses JavaScript code strings containing object literals
  • Transforms object literals that have computed property names (e.g., [expr]: value) into ES5-compatible syntax
  • Preserves the order and values of all properties
  • Returns the transformed code as a string
  • Handles objects with both regular properties and computed properties

Expected Behavior

The transformer should convert computed property syntax into equivalent code that works in ES5 environments. Objects with only regular properties should remain unchanged. When computed properties are present, the transformation should maintain the original semantics and property order.

Test Cases

  • Transforming var obj = {a: 1, b: 2}; returns unchanged code @test
  • Transforming var obj = {["x" + y]: 5}; produces ES5-compatible output @test
  • Transforming var obj = {a: 1, ["key" + id]: 2, c: 3}; maintains property evaluation order @test

Implementation

@generates

API

/**
 * Transforms JavaScript code containing computed properties to ES5-compatible code.
 *
 * @param {string} code - JavaScript code string to transform
 * @returns {string} The transformed code
 */
function transform(code) {
  // IMPLEMENTATION HERE
}

module.exports = { transform };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the Babel compiler core for code transformation.

@satisfied-by

@babel/plugin-transform-computed-properties { .dependency }

Provides transformation logic for computed properties in object literals.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-es2015-computed-properties

tile.json