CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-escodegen

ECMAScript code generator that transforms Mozilla's Parser API ASTs back into executable JavaScript code

95

1.07x
Overview
Eval results
Files

task.mdevals/scenario-1/

AST Code Formatter

Build a simple code formatter tool that can generate JavaScript code from Abstract Syntax Trees (ASTs) in two different output styles: a readable format and a minified format.

Overview

Create a module that takes JavaScript AST nodes and generates corresponding source code. The module should support two formatting modes: one that produces human-readable code with proper indentation and spacing, and another that produces compact, minified output suitable for production deployment.

Capabilities

Readable Code Generation

Generate well-formatted, human-readable JavaScript code from AST nodes.

  • Given a simple variable declaration AST node, generate readable code with proper spacing and indentation @test
  • Given a function expression AST node, generate readable code with proper line breaks and indentation @test

Minified Code Generation

Generate compact, minified JavaScript code from AST nodes to minimize file size.

  • Given a simple variable declaration AST node, generate minified code with minimal whitespace @test
  • Given a function expression AST node, generate minified code with no unnecessary spacing @test

API

/**
 * Generates readable, formatted JavaScript code from an AST node
 * @param {Object} astNode - Mozilla Parser API compliant AST node
 * @returns {string} Formatted JavaScript code
 */
function generateReadable(astNode)

/**
 * Generates minified JavaScript code from an AST node
 * @param {Object} astNode - Mozilla Parser API compliant AST node
 * @returns {string} Minified JavaScript code
 */
function generateMinified(astNode)

Implementation

@generates

Dependencies { .dependencies }

escodegen { .dependency }

Provides JavaScript code generation from AST nodes with formatting options.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-escodegen

tile.json