CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--runtime

Babel's modular runtime helpers that provide transpilation support for modern JavaScript features

94

1.18x
Overview
Eval results
Files

task.mdevals/scenario-4/

Custom Babel Plugin with Transformation Tracking

Build a Babel plugin that tracks transformations and modifies parsing behavior based on configuration.

Requirements

Your plugin should:

  1. Accept a configuration option trackStats (boolean) that enables/disables statistics tracking
  2. Before any code transformation begins, initialize a statistics object that tracks:
    • Total number of function declarations found
    • Total number of arrow functions found
  3. During transformation, count all function declarations and arrow function expressions in the code
  4. After all transformations complete, if trackStats is enabled, attach the statistics to the result metadata under the key transformStats
  5. Modify the parser configuration to enable parsing of JSX syntax regardless of the file extension

Test Cases

  • Given a file with 2 function declarations and 3 arrow functions, when trackStats is true, the metadata should contain { transformStats: { functionDeclarations: 2, arrowFunctions: 3 } } @test
  • Given a file with JSX syntax (<div>Hello</div>), the plugin should successfully parse and transform it without errors @test
  • Given a file with 1 function declaration, when trackStats is false, the metadata should not contain transformStats @test

Implementation

@generates

API

/**
 * Babel plugin that tracks transformation statistics and enables JSX parsing
 *
 * @param {object} api - The Babel API object
 * @param {object} options - Plugin options
 * @param {boolean} options.trackStats - Whether to track and report statistics
 * @returns {object} Plugin object with visitor and lifecycle methods
 */
module.exports = function customPlugin(api, options) {
  // Plugin implementation
};

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the Babel transformation API and plugin infrastructure.

Install with Tessl CLI

npx tessl i tessl/npm-babel--runtime

tile.json