docs
evals
scenario-1
scenario-10
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
Build a utility that analyzes CommonJS module source code and reports information about its exports.
Your utility should provide a function that takes CommonJS JavaScript source code as input and returns structured information about the module's exports.
The function should:
namedExports: An array of strings representing the named exports found in the modulehasReexport: A boolean indicating whether the module re-exports another moduleThe analyzer should detect:
exports.foo = 123exports['bar'] = 456module.exports.baz = 789module.exports = { x, y }exports.add = function() {}, the analyzer returns { namedExports: ['add'], hasReexport: false } @testexports['multiply'] = function() {}, the analyzer returns { namedExports: ['multiply'], hasReexport: false } @testmodule.exports.subtract = function() {}, the analyzer returns { namedExports: ['subtract'], hasReexport: false } @testmodule.exports = { sum, product }, the analyzer returns { namedExports: ['sum', 'product'], hasReexport: false } @testmodule.exports = require('./other'), the analyzer returns { namedExports: [], hasReexport: true } @test/**
* Analyzes CommonJS source code and extracts export information
*
* @param {string} source - The JavaScript source code to analyze
* @returns {Object} An object with namedExports (array) and hasReexport (boolean)
*/
function analyzeExports(source) {
// Implementation here
}
module.exports = { analyzeExports };Provides static analysis of CommonJS modules to detect exports and reexports.