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

RegExp Code Generator

A utility that generates JavaScript regular expression literals from Abstract Syntax Tree (AST) nodes, with proper handling of Unicode characters and escape sequences.

Capabilities

Generate basic RegExp literals

Transform AST nodes representing regular expressions into JavaScript code with proper syntax.

  • Given an AST node for /hello/i, it generates "/hello/i" @test
  • Given an AST node for /\d+/g, it generates "/\d+/g" @test
  • Given an AST node with flags "gi", it generates the pattern with "/gi" suffix @test

Escape Unicode line terminators

Unicode line separators (U+2028) and paragraph separators (U+2029) in patterns must be escaped to prevent JavaScript syntax errors.

  • Given a pattern containing "\u2028", it generates "/\u2028/" @test
  • Given a pattern containing "\u2029", it generates "/\u2029/" @test
  • Given a pattern "hello\u2028world", it generates "/hello\u2028world/" @test

Implementation

@generates

API

/**
 * Transforms an AST Literal node representing a RegExp into JavaScript code.
 *
 * @param {Object} node - AST node with type 'Literal' and a regex property
 * @param {Object} node.regex - Contains pattern and flags for the regular expression
 * @param {string} node.regex.pattern - The regex pattern string
 * @param {string} node.regex.flags - The regex flags string
 * @returns {string} The generated JavaScript regular expression literal
 */
function transformRegExpNode(node) {
  // IMPLEMENTATION HERE
}

module.exports = { transformRegExpNode };

Dependencies { .dependencies }

escodegen { .dependency }

Provides AST to JavaScript code generation capabilities, including regular expression handling with Unicode support.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-escodegen

tile.json