or run

npx @tessl/cli init
Log in

Version

Files

docs

index.md
tile.json

task.mdevals/scenario-9/

Transpiler Export Pattern Analyzer

Build a tool that analyzes JavaScript CommonJS modules to detect and report transpiler-generated export patterns. The tool should specifically identify Babel-style star re-export patterns that use Object.keys().forEach() to copy exports from one module to another.

Requirements

Your implementation should:

  1. Parse JavaScript source code to detect Babel-style star re-export patterns that match this structure:

    • Object.keys(sourceModule).forEach(function (key) { ... })
    • The function body should check for "default" or "__esModule" keys and skip them
    • The function body should assign sourceModule[key] to exports[key]
  2. Extract export information including:

    • Whether the module contains a transpiler pattern
    • The source module identifier being re-exported (e.g., _external)
  3. Handle edge cases:

    • Ignore patterns that appear inside nested functions or blocks (only top-level)
    • Correctly identify the source module variable name
    • Detect both function (key) and arrow function (key) => syntax
  4. Provide a simple API with a function that takes source code as input and returns analysis results

Test Cases

Test Case 1: Basic Babel Star Re-export @test

Input (src/analyzer.js or src/analyzer.ts):

Object.keys(_external).forEach(function (key) {
  if (key === "default" || key === "__esModule") return;
  exports[key] = _external[key];
});

Expected behavior: Detect the pattern and identify _external as the source module

Test Case 2: No Transpiler Pattern @test

Input (src/analyzer.js or src/analyzer.ts):

exports.foo = 'bar';
module.exports.baz = 123;

Expected behavior: Report no transpiler pattern detected

Test Case 3: Arrow Function Variant @test

Input (src/analyzer.js or src/analyzer.ts):

Object.keys(_myModule).forEach((key) => {
  if (key === "default" || key === "__esModule") return;
  exports[key] = _myModule[key];
});

Expected behavior: Detect the pattern and identify _myModule as the source module

Implementation Notes

  • Focus on detecting the specific Object.keys().forEach() pattern structure
  • The tool should work with both JavaScript and TypeScript files
  • Test file should be named appropriately: .test.js or .test.ts

Dependencies { .dependencies }

cjs-module-lexer { .dependency }

High-performance lexer for analyzing CommonJS modules and detecting export patterns, including transpiler-generated patterns.