docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a tool that analyzes CommonJS module source code and extracts export metadata, handling various JavaScript token types including strings, comments, template literals, and regular expressions.
When analyzing CommonJS modules, you need to parse JavaScript source code to identify what exports a module provides. The source code may contain various JavaScript syntax elements like string literals, comments, template strings, and regular expressions that need to be correctly parsed to identify exports.
Create a module export analyzer with the following capabilities:
Implement a function analyzeModuleExports(sourceCode) that:
The analyzer should correctly parse source code containing:
//) and block comments (/* */)Return an object with this structure:
{
exports: [...], // Array of export names found
reexports: [...] // Array of reexported module specifiers
}/**
* Analyzes CommonJS module exports in JavaScript source code
*
* @param {string} sourceCode - JavaScript source code to analyze
* @returns {Object} Analysis results with exports and reexports arrays
*/
function analyzeModuleExports(sourceCode) {
// Implementation here
}
module.exports = { analyzeModuleExports };Provides JavaScript lexing and CommonJS export detection capabilities.