or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-4/

CommonJS Export Analyzer

Build a utility that analyzes CommonJS module source code to detect exports defined using Object.defineProperty. The tool should identify both value-based exports and getter-based exports.

Requirements

Your tool should parse JavaScript source code and detect the following export patterns:

  1. Value property exports: Exports defined using Object.defineProperty with a value property
  2. Getter exports: Exports defined using Object.defineProperty with a get function that returns identifiers or member expressions
  3. Output format: Return an object containing an array of detected export names

Test Cases

  • When given source code containing Object.defineProperty(exports, 'myValue', { value: 42, enumerable: true }), the analyzer detects 'myValue' as an export @test
  • When given source code with Object.defineProperty(exports, 'foo', { get: function() { return bar; }, enumerable: true }), it detects 'foo' as an export @test
  • When given source code with multiple Object.defineProperty calls on exports, it returns all detected export names @test

Implementation

@generates

API

/**
 * Analyzes CommonJS source code and detects exports defined via Object.defineProperty
 *
 * @param {string} source - The JavaScript source code to analyze
 * @returns {{ exports: string[] }} An object containing an array of detected export names
 */
function analyzeExports(source) {
  // IMPLEMENTATION HERE
}

module.exports = { analyzeExports };

Dependencies { .dependencies }

cjs-module-lexer { .dependency }

Provides CommonJS module parsing and export detection capabilities.