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-8/

Code Formatter Configuration Utility

A utility that generates JavaScript code from Abstract Syntax Trees (ASTs) with different formatting styles. The utility should support configuring indentation, whitespace, and quote styles to match different coding standards.

Capabilities

Format with Custom Indentation

Generate code with configurable indentation settings (spaces vs tabs, indent level).

  • Given an AST for function add(a, b) { return a + b; }, formatting with 2-space indentation produces code where the return statement is indented with exactly 2 spaces @test
  • Given an AST for function multiply(x, y) { return x * y; }, formatting with tab indentation produces code where the return statement is indented with exactly one tab character @test

Format with Quote Style Control

Generate code with specified quote styles for string literals.

  • Given an AST for var msg = "hello";, formatting with single quote style produces code with the string as 'hello' @test
  • Given an AST for var msg = 'world';, formatting with double quote style produces code with the string as "world" @test

Format in Compact Mode

Generate minified code with minimal whitespace.

  • Given an AST for function test() { var x = 1; return x + 2; }, formatting in compact mode produces function test(){var x=1;return x+2;} (no spaces around operators or after keywords) @test

Format with Custom Base Indentation

Generate code with a specified base indentation level.

  • Given an AST for var x = { a: 1, b: 2 };, formatting with base indentation of 1 level produces code where var starts with 4 spaces and object properties are indented 8 spaces @test

Implementation

@generates

API

/**
 * Formats JavaScript code from an AST with 2-space indentation.
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @returns {string} The formatted JavaScript code with 2-space indentation
 */
function formatWithTwoSpaces(ast) {
  // IMPLEMENTATION HERE
}

/**
 * Formats JavaScript code from an AST with tab indentation.
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @returns {string} The formatted JavaScript code with tab indentation
 */
function formatWithTabs(ast) {
  // IMPLEMENTATION HERE
}

/**
 * Formats JavaScript code from an AST with single quotes for strings.
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @returns {string} The formatted JavaScript code with single-quoted strings
 */
function formatWithSingleQuotes(ast) {
  // IMPLEMENTATION HERE
}

/**
 * Formats JavaScript code from an AST with double quotes for strings.
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @returns {string} The formatted JavaScript code with double-quoted strings
 */
function formatWithDoubleQuotes(ast) {
  // IMPLEMENTATION HERE
}

/**
 * Formats JavaScript code from an AST in compact mode (minified).
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @returns {string} The formatted JavaScript code with minimal whitespace
 */
function formatCompact(ast) {
  // IMPLEMENTATION HERE
}

/**
 * Formats JavaScript code from an AST with a base indentation level.
 *
 * @param {Object} ast - The Abstract Syntax Tree node to format
 * @param {number} baseIndentLevel - The base indentation level (e.g., 1 for one indent)
 * @returns {string} The formatted JavaScript code with base indentation applied
 */
function formatWithBaseIndent(ast, baseIndentLevel) {
  // IMPLEMENTATION HERE
}

module.exports = {
  formatWithTwoSpaces,
  formatWithTabs,
  formatWithSingleQuotes,
  formatWithDoubleQuotes,
  formatCompact,
  formatWithBaseIndent
};

Dependencies { .dependencies }

escodegen { .dependency }

Provides JavaScript code generation from AST with formatting control.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-escodegen

tile.json