Babel helper functions for inserting module loads
Overall
score
99%
Build a tool that analyzes JavaScript files transformed by Babel and reports on helper function usage to identify optimization opportunities.
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.
The analyzer should:
_classCallCheck, _asyncToGenerator)The analyzer should produce a report containing:
@babel/plugin-transform-runtime based on duplication levels_classCallCheck and _createClass helpers, the analyzer identifies both helpers @test_asyncToGenerator helper), the analyzer reports the helper appears in multiple files with its total count @test_toConsumableArray helper, the analyzer correctly identifies it @test@generates
/**
* 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
};Provides JavaScript parsing capabilities to analyze transformed code.
Enables AST traversal to identify helper function calls.
Provides utilities for working with AST nodes and identifying helper patterns.
Install with Tessl CLI
npx tessl i tessl/npm-babel--helper-module-importsevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10