or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-1/

Module Export Analyzer

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.

Background

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.

Requirements

Create a module export analyzer with the following capabilities:

Core Functionality

Implement a function analyzeModuleExports(sourceCode) that:

  • Takes JavaScript source code as a string
  • Parses the code to extract all named exports
  • Identifies any module reexports
  • Returns the analysis results

Parsing Requirements

The analyzer should correctly parse source code containing:

  • String literals in export statements (both single and double quoted)
  • Line comments (//) and block comments (/* */)
  • Template literals (backtick strings with interpolation)
  • Regular expressions

Output Format

Return an object with this structure:

{
  exports: [...],      // Array of export names found
  reexports: [...]     // Array of reexported module specifiers
}

Test Cases

  • Given source code with a simple export and a line comment, it correctly identifies the export and ignores the comment @test
  • Given source code with exports using template literals, it correctly parses and identifies all exports @test
  • Given source code with a reexport statement, it correctly identifies the reexported module @test
  • Given source code with block comments surrounding exports, it correctly identifies valid exports @test

Implementation

@generates

API

/**
 * 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 };

Dependencies { .dependencies }

cjs-module-lexer { .dependency }

Provides JavaScript lexing and CommonJS export detection capabilities.