Babel's modular runtime helpers that provide transpilation support for modern JavaScript features
94
Build a Babel plugin that counts the number of function calls in each file and stores this information during the transformation process.
Your plugin should:
Count function calls: Track every function call expression (both regular calls and member expression calls like obj.method()) encountered in each file.
Store per-file state: Use plugin-specific storage to maintain a count for each file being transformed. The count should be accessible within the plugin throughout the transformation.
Access plugin context: Utilize the plugin pass context to access file information and store the count appropriately.
Add metadata: After transformation, the plugin should add the count to the file's metadata under the key functionCallCount.
When transforming a file with 3 function calls (foo(), bar(), baz()), the metadata should contain functionCallCount: 3 @test
When transforming a file with method calls (obj.method(), arr.push(1)), these should be counted as function calls @test
When transforming a file with nested function calls (foo(bar())), all calls should be counted separately (count should be 2) @test
When transforming a file with no function calls, the metadata should contain functionCallCount: 0 @test
@generates
/**
* Babel plugin that counts function calls in a file
* @returns {object} Babel plugin object
*/
module.exports = function functionCallCounterPlugin() {
return {
name: "function-call-counter",
visitor: {
// Plugin visitor implementation
}
};
};Provides the plugin API and transformation infrastructure.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-babel--runtimedocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10