Babel plugin that transforms eval() calls containing string literals by parsing and compiling the string content at transform time
Overall
score
98%
Build a tool that transforms modern JavaScript class code containing advanced features into backwards-compatible JavaScript. The tool should handle private fields, private methods, and super calls, making them work in environments that don't natively support these features.
Your tool should accept JavaScript source code as input and return transformed code that:
#) into a backwards-compatible implementation#) into an accessible form for older environmentsThe transformation should preserve the semantic behavior of the original code while making it executable in environments that lack native support for these features.
Given a class with private fields:
class Counter {
#count = 0;
increment() {
this.#count++;
}
getCount() {
return this.#count;
}
}The transformed code should implement private field functionality that works in older environments. The behavior should be identical: private fields remain inaccessible from outside the class.
@test
Given a class with private methods:
class Validator {
#validate(value) {
return value > 0;
}
check(value) {
return this.#validate(value);
}
}The transformed code should maintain the private nature of the method while ensuring it works in environments without native private method support.
@test
Given a class hierarchy with super calls:
class Parent {
constructor(name) {
this.name = name;
}
greet() {
return `Hello, ${this.name}`;
}
}
class Child extends Parent {
constructor(name, age) {
super(name);
this.age = age;
}
greet() {
return super.greet() + ` (${this.age} years old)`;
}
}The transformed code should properly handle both constructor super calls and method super calls, ensuring the inheritance chain works correctly.
@test
@generates
/**
* Transforms JavaScript code containing advanced class features
* into backwards-compatible JavaScript.
*
* @param {string} code - The source code to transform
* @param {Object} options - Transformation options (optional)
* @returns {string} The transformed code
*/
function transformClassFeatures(code, options = {});
module.exports = { transformClassFeatures };Provides the core Babel transformation API for parsing and transforming JavaScript code.
Transforms class properties including private fields and private methods.
Handles class transformation including super calls and inheritance.
Install with Tessl CLI
npx tessl i tessl/npm-babel-plugin-transform-evaldocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10