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 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.
Your implementation should:
Parse JavaScript source code to detect Babel-style star re-export patterns that match this structure:
Object.keys(sourceModule).forEach(function (key) { ... })"default" or "__esModule" keys and skip themsourceModule[key] to exports[key]Extract export information including:
_external)Handle edge cases:
function (key) and arrow function (key) => syntaxProvide a simple API with a function that takes source code as input and returns analysis results
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
Input (src/analyzer.js or src/analyzer.ts):
exports.foo = 'bar';
module.exports.baz = 123;Expected behavior: Report no transpiler pattern detected
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
Object.keys().forEach() pattern structure.test.js or .test.tsHigh-performance lexer for analyzing CommonJS modules and detecting export patterns, including transpiler-generated patterns.