CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--helper-module-imports

Babel helper functions for inserting module loads

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-1/

Decorator Transpiler

Build a JavaScript transpiler that transforms class decorators from modern syntax into browser-compatible code.

Requirements

Your transpiler should handle class and method decorators according to the latest ECMAScript decorator proposal. It must parse JavaScript code containing decorator syntax and output equivalent JavaScript code that works in environments that don't support decorators natively.

Input and Output

The transpiler should:

  • Accept JavaScript source code as a string
  • Parse the code to understand its structure
  • Transform any decorator syntax into equivalent code
  • Generate valid JavaScript output
  • Preserve the original behavior of the decorated classes

Decorator Support

Support the following decorator patterns:

  1. Class decorators: Applied to class declarations
  2. Method decorators: Applied to class methods
  3. Multiple decorators: Multiple decorators can be stacked on a single target

Test Cases

  • Given a simple class with a single class decorator, the transpiler produces valid JavaScript that applies the decorator function to the class @test
  • Given a class with a method decorator, the transpiler produces valid JavaScript that applies the decorator to the method @test
  • Given a class with multiple stacked decorators on a method, the transpiler correctly chains them @test
  • Given code without decorators, the transpiler returns functionally equivalent code @test

Implementation

@generates

API

/**
 * Transforms JavaScript code with decorators into compatible JavaScript
 *
 * @param {string} code - The source code containing decorator syntax
 * @param {object} options - Configuration options for transformation
 * @returns {object} Result object containing the transformed code
 */
function transpile(code, options = {}) {
  // Implementation
}

module.exports = { transpile };

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the JavaScript parsing and transformation engine.

@babel/plugin-proposal-decorators { .dependency }

Implements decorator transformation according to ECMAScript proposals.

Install with Tessl CLI

npx tessl i tessl/npm-babel--helper-module-imports

tile.json