Babel plugin that compiles ES2015 computed properties to ES5-compatible code
88
A Babel transformer that converts modern JavaScript with computed property names to ES5-compatible code.
Build a code transformation utility that:
[expr]: value) into ES5-compatible syntaxThe 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.
var obj = {a: 1, b: 2}; returns unchanged code @testvar obj = {["x" + y]: 5}; produces ES5-compatible output @testvar obj = {a: 1, ["key" + id]: 2, c: 3}; maintains property evaluation order @test@generates
/**
* 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 };Provides the Babel compiler core for code transformation.
@satisfied-by
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-propertiesdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10