eo2js

raw JSON →
0.0.8 verified Fri May 01 auth: no javascript

eo2js is a transpiler that converts EOLANG (EO) programs to JavaScript, enabling execution in Node.js and browser environments. Current version 0.0.8 is pre-1.0 with active development. It translates EO objects and contracts into equivalent JS classes and functions, preserving the purely object-oriented paradigm. Unlike general transpilers, it is purpose-built for EO's abstract object model, including attributes, dataization, and runtime type checking. Release cadence is irregular; frequent breaking changes expected. Differentiators: native EO-to-JS mapping, minimal runtime, and support for EO's freeze/lock semantics.

error Error: Cannot find module 'eo2js'
cause Package is not installed or import path incorrect.
fix
Run npm install eo2js and ensure you are using ESM import syntax (not require).
error SyntaxError: Unexpected token 'export'
cause Using CommonJS require() with an ESM-only package.
fix
Change to import statement and use .mjs file extension or 'type':'module' in package.json.
error TypeError: eo2js is not a function
cause Default import used when package only provides named exports.
fix
Use import { compile } from 'eo2js' or import * as eo2js from 'eo2js' and call eo2js.compile().
breaking API changes between minor versions: eo2js function signature changed in 0.0.5 from (code, options) to (source, options).
fix Update calls to use new parameter order: eo2js(source, options)
breaking Default export removed in 0.0.7; use named exports like compile instead.
fix import { compile } from 'eo2js' instead of import eo2js from 'eo2js'
gotcha Transpiled JS requires eolang runtime to execute; not standalone.
fix Ensure eolang package is installed and imported before executing transpiled code
deprecated Options.target deprecated since 0.0.6; use options.platform instead.
fix Replace target with platform in options object
npm install eo2js
yarn add eo2js
pnpm add eo2js

This code transpiles a simple EO program to JavaScript and executes it using the eolang runtime.

import eo2js from 'eo2js';

// Sample EO program
const eoCode = `
[] > main
  "Hello, EO!" > msg
  QQ.io.stdout > @
    msg
    \n
`;

try {
  const jsCode = eo2js(eoCode, { target: 'node' });
  console.log('Transpiled JS:');
  console.log(jsCode);
  // Execute the generated JS (requires eolang runtime)
  const { evaluate } = await import('eolang');
  const result = await evaluate(jsCode);
  console.log('Output:', result);
} catch (err) {
  console.error('Transpilation failed:', err);
}