forthtranspiler

raw JSON →
1.0.7 verified Fri May 01 auth: no javascript deprecated

A Forth-to-JavaScript transpiler that converts Forth source code into JavaScript with source mapping and unit testing support. This version 1.0.7 is a proof-of-concept with limited Forth vocabulary support, no recent updates, and no TypeScript definitions. It is primarily for educational or experimental use, not production. Alternatives like NodeForth or gForth may be more stable.

error Error: Cannot find module 'forthtranspiler'
cause Package not installed globally or missing from local node_modules.
fix
Run 'npm install forthtranspiler' in your project directory.
error forthtranspiler is not a function
cause Incorrect import; using CJS require on ESM-only package.
fix
Use 'import forthtranspiler from 'forthtranspiler'' or dynamic import.
deprecated Package is no longer maintained and has known bugs with certain Forth constructs.
fix Consider using a more modern Forth implementation or JavaScript library.
gotcha No TypeScript support; type definitions are not provided.
fix Use a .d.ts file or manually define types if using TypeScript.
gotcha Source mapping may be incomplete for complex Forth phrases.
fix Check generated JS for accuracy; test thoroughly.
npm install forthtranspiler
yarn add forthtranspiler
pnpm add forthtranspiler

Transpiles a simple Forth word definition and usage into JavaScript.

import forthtranspiler from 'forthtranspiler';

const forthCode = `
: square dup * ;
5 square .
`;

const jsCode = forthtranspiler(forthCode);
// or: forthtranspiler(forthCode, { sourceMap: true });

console.log(jsCode);