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-5/

Babel Helper Optimizer

Build a tool that analyzes JavaScript files transformed by Babel and reports on helper function usage to identify optimization opportunities.

Overview

When Babel transforms modern JavaScript code, it injects helper functions (like _classCallCheck, _createClass, _extends, etc.) to support the transformed features. In large projects with multiple files, these helpers are often duplicated across files, increasing bundle size. Your task is to create an analyzer that detects helper usage patterns and suggests optimizations.

Requirements

Analyze transformed code for helper usage

The analyzer should:

  1. Parse JavaScript files that have been transformed by Babel
  2. Detect all Babel helper functions used in each file (helpers typically start with underscore, like _classCallCheck, _asyncToGenerator)
  3. Count the total number of helper occurrences across all analyzed files

Generate optimization report

The analyzer should produce a report containing:

  1. List of all helpers found across analyzed files, sorted by frequency
  2. For each helper, list which files use it
  3. Total estimated size overhead from duplicated helpers
  4. Recommendation on whether to use @babel/plugin-transform-runtime based on duplication levels

Test Cases

  • Given a single file with a class using _classCallCheck and _createClass helpers, the analyzer identifies both helpers @test
  • Given multiple files each containing the same async function (with _asyncToGenerator helper), the analyzer reports the helper appears in multiple files with its total count @test
  • Given a file using _toConsumableArray helper, the analyzer correctly identifies it @test
  • Given files with total helper duplication exceeding 10KB, the analyzer recommends using transform-runtime plugin @test

Implementation

@generates

API

/**
 * Analyzes JavaScript files for Babel helper usage
 *
 * @param {string[]} filePaths - Array of file paths to analyze
 * @returns {Object} Analysis report with helper usage statistics
 * @returns {Object} report.helpers - Map of helper names to usage details
 * @returns {number} report.totalHelpers - Total count of helper occurrences
 * @returns {number} report.estimatedOverhead - Estimated size overhead in bytes
 * @returns {boolean} report.recommendTransformRuntime - Whether to use transform-runtime
 */
function analyzeHelperUsage(filePaths) {
  // Implementation here
}

/**
 * Parses a JavaScript file to extract Babel helper function calls
 *
 * @param {string} code - JavaScript source code
 * @returns {string[]} Array of helper function names found
 */
function extractHelpers(code) {
  // Implementation here
}

/**
 * Generates a formatted report from analysis results
 *
 * @param {Object} analysisReport - Report from analyzeHelperUsage
 * @returns {string} Formatted text report
 */
function formatReport(analysisReport) {
  // Implementation here
}

module.exports = {
  analyzeHelperUsage,
  extractHelpers,
  formatReport
};

Dependencies { .dependencies }

@babel/parser { .dependency }

Provides JavaScript parsing capabilities to analyze transformed code.

@babel/traverse { .dependency }

Enables AST traversal to identify helper function calls.

@babel/types { .dependency }

Provides utilities for working with AST nodes and identifying helper patterns.

Install with Tessl CLI

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

tile.json