CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-flow-remove-types

Fast, zero-configuration Flow type annotation removal tool for JavaScript with CLI and programmatic APIs

84

1.09x
Overview
Eval results
Files

task.mdevals/scenario-10/

Flow Expression Evaluator

Create a command-line utility that evaluates Flow-typed JavaScript expressions dynamically using the flow-node evaluation modes.

Background

Your utility should accept Flow-typed JavaScript code snippets and evaluate them, returning results in different formats based on command-line options.

Requirements

Input Handling

The utility should accept JavaScript expressions as command-line arguments and evaluate them:

  • Accept a code snippet as a string argument
  • Support evaluating expressions that contain Flow type annotations
  • Handle both statements and expressions

Evaluation Modes

The utility must support two evaluation modes:

  1. Eval mode: Execute the code without printing the result
  2. Print mode: Execute the code and print the result to stdout

The mode should be selectable via a command-line flag --mode which accepts values eval or print.

Output Format

  • In eval mode: Execute code silently (no output unless the code itself produces output)
  • In print mode: Print the final expression value to stdout
  • Display any console output from the evaluated code in both modes

Error Handling

  • If invalid code is provided, display a helpful error message
  • If the mode flag is missing or invalid, default to eval mode

Implementation

@generates

API

/**
 * Evaluates a Flow-typed JavaScript expression using the specified mode.
 *
 * @param {string} code - The JavaScript code to evaluate
 * @param {string} mode - Either "eval" or "print"
 * @returns {Promise<{stdout: string, stderr: string, exitCode: number}>}
 */
async function evaluateExpression(code, mode) {
  // Implementation uses flow-node with appropriate flags
}

/**
 * Main CLI handler
 */
async function main() {
  // Parse command line arguments
  // Call evaluateExpression with the code and mode
  // Display output appropriately
}

module.exports = { evaluateExpression, main };

Test Cases

  • Given code "2 + 2" with mode "print", the evaluator prints 4 to stdout @test
  • Given code "const x: number = 5; x * 2" with mode "print", the evaluator prints 10 @test
  • Given code "console.log('hello')" with mode "eval", the evaluator outputs hello (from console.log) but does not print the return value @test
  • Given code "const sum = (a: number, b: number): number => a + b; sum(3, 7)" with mode "print", the evaluator prints 10 @test

Dependencies { .dependencies }

flow-remove-types { .dependency }

Provides Flow type annotation removal and flow-node execution capabilities.

Install with Tessl CLI

npx tessl i tessl/npm-flow-remove-types

tile.json