CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel--helper-module-imports

Babel helper functions for inserting module loads

Overall
score

99%

Overview
Eval results
Files

task.mdevals/scenario-9/

AST Code Generator

Build a utility that programmatically generates JavaScript code by constructing Abstract Syntax Tree (AST) nodes. The tool should provide functions to create common JavaScript patterns like variable declarations, function calls, and conditional statements, then convert these AST structures into executable JavaScript code.

Capabilities

Variable Declaration Generation

Generates variable declarations with different types (const, let, var) and initializer values.

  • Creating const x = 5; returns an AST node representing a constant declaration named "x" initialized to the number 5 @test
  • Creating let message = "hello"; returns an AST node representing a let declaration named "message" initialized to the string "hello" @test
  • Creating var flag = true; returns an AST node representing a var declaration named "flag" initialized to the boolean true @test

Function Call Generation

Generates function call expressions with arguments.

  • Creating a call to console.log("test") returns an AST node representing a member expression calling log on console with one string argument @test
  • Creating a call to Math.max(1, 2, 3) returns an AST node representing a member expression calling max on Math with three numeric arguments @test

Conditional Statement Generation

Generates if statements with conditions and consequent blocks.

  • Creating if (x > 5) { return true; } returns an AST node representing an if statement with a binary expression condition and a return statement in the consequent @test

Code Generation

Converts AST nodes to JavaScript source code.

  • Given an AST node representing const x = 10;, converting it to code returns the string "const x = 10;" (whitespace may vary) @test

Implementation

@generates

API

/**
 * Creates a variable declaration AST node.
 *
 * @param {string} kind - The kind of declaration: "const", "let", or "var"
 * @param {string} name - The variable name
 * @param {any} value - The initialization value (number, string, boolean)
 * @returns {Object} AST node representing the variable declaration
 */
function createVariableDeclaration(kind, name, value) {
  // IMPLEMENTATION HERE
}

/**
 * Creates a function call expression AST node.
 *
 * @param {string} objectName - The object name (e.g., "console")
 * @param {string} methodName - The method name (e.g., "log")
 * @param {Array<any>} args - Array of argument values
 * @returns {Object} AST node representing the call expression
 */
function createMemberCall(objectName, methodName, args) {
  // IMPLEMENTATION HERE
}

/**
 * Creates an if statement AST node with a simple comparison condition.
 *
 * @param {string} leftName - Left side identifier name
 * @param {string} operator - Comparison operator (">", "<", "===", etc.)
 * @param {any} rightValue - Right side value
 * @param {Object} consequent - AST node for the consequent statement
 * @returns {Object} AST node representing the if statement
 */
function createIfStatement(leftName, operator, rightValue, consequent) {
  // IMPLEMENTATION HERE
}

/**
 * Converts an AST node to JavaScript source code.
 *
 * @param {Object} astNode - The AST node to convert
 * @returns {string} JavaScript source code
 */
function generateCode(astNode) {
  // IMPLEMENTATION HERE
}

module.exports = {
  createVariableDeclaration,
  createMemberCall,
  createIfStatement,
  generateCode,
};

Dependencies { .dependencies }

@babel/types { .dependency }

Provides AST node builder functions for constructing JavaScript AST nodes.

@satisfied-by

@babel/generator { .dependency }

Converts AST nodes back into JavaScript source code.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-babel--helper-module-imports

tile.json