CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-eval

Babel plugin that transforms eval() calls containing string literals by parsing and compiling the string content at transform time

Overall
score

98%

Overview
Eval results
Files

task.mdevals/scenario-8/

Console Statement Transformer

A Babel plugin that transforms console statements to include file location information for better debugging.

Problem Description

Create a Babel plugin that automatically enhances console.log(), console.warn(), and console.error() calls by prepending location information (filename and line number) to the first argument. The plugin should only transform console calls that have at least one argument.

For example, this code:

console.log('Hello, world!');
console.warn('Warning message');

Should be transformed to:

console.log('[main.js:1]', 'Hello, world!');
console.warn('[main.js:2]', 'Warning message');

Requirements

  1. The plugin should transform three console methods: log, warn, and error
  2. Only transform console calls that are direct member expressions (e.g., console.log())
  3. Only transform calls that have at least one argument
  4. Prepend a string literal containing the format [filename:line] as the first argument
  5. The filename should be the basename (not the full path)
  6. Do not transform console calls with zero arguments
  7. The plugin should be exported as a default function that returns a visitor object

Implementation

@generates

API

/**
 * Babel plugin that transforms console statements to include file location.
 *
 * @returns {Object} Babel plugin object with visitor
 */
export default function() {
  // Plugin implementation
}

Test Cases

  • Transforms console.log('test') to include file location prefix @test
  • Transforms console.warn('warning') to include file location prefix @test
  • Transforms console.error('error') to include file location prefix @test
  • Does not transform console.log() with zero arguments @test
  • Correctly extracts basename from file path @test

Dependencies { .dependencies }

@babel/core { .dependency }

Provides the Babel transformation API and core functionality.

@satisfied-by

@babel/types { .dependency }

Provides utilities for AST node creation and type checking.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-eval

tile.json