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

Code Generator with Mozilla Extensions

Build a JavaScript AST code generation utility that can generate code from Abstract Syntax Trees while supporting Mozilla-specific JavaScript extensions through configuration options.

Requirements

Your utility should accept an AST node and generation options, then produce JavaScript code. The utility must handle Mozilla-specific generator function syntax variations through configuration.

Generator Function Handling

The utility should support configuring how generator functions are represented in the output code:

  • When the starless mode is disabled, generator functions should include the * token in their syntax
  • When the starless mode is enabled, generator functions should be represented without the * token

Test Cases

  • Given an AST representing a basic generator function function* gen() { yield 1; } with default settings, the output includes the * token @test
  • Given an AST representing a basic generator function with starless mode enabled, the output omits the * token in the function declaration @test
  • Given an AST representing a generator method in an object with default settings, the output includes the * token @test
  • Given an AST representing a generator method in an object with starless mode enabled, the output omits the * token @test

Implementation

@generates

API

/**
 * Generate JavaScript code from an AST node with Mozilla extension support
 * @param {Object} ast - Mozilla Parser API compatible AST node
 * @param {Object} options - Generation options including Mozilla-specific settings
 * @param {Object} [options.moz] - Mozilla-specific options
 * @param {boolean} [options.moz.starlessGenerator] - Generate generators without * syntax
 * @returns {string} Generated JavaScript code
 */
function generateCode(ast, options);

module.exports = { generateCode };

Dependencies { .dependencies }

escodegen { .dependency }

Provides AST to JavaScript code generation with Mozilla extension support.

Install with Tessl CLI

npx tessl i tessl/npm-escodegen

tile.json