doof
raw JSON → 0.0.2 verified Fri May 01 auth: no javascript
A TypeScript-like language transpiler targeting C++, JavaScript, and VM bytecode. Version 0.0.2 is the current stable release with an experimental development cadence. It offers a familiar TypeScript syntax for classes, type annotations, and templates, but transpiles to idiomatic C++ with optional runtime support, or JavaScript or abstract VM bytecode. Key differentiators include cross-language output from a single source, integrated C++ compile-and-run, and a format/lint tool. Note: Very early-stage, with limited ecosystem and documentation.
Common errors
error Error: Cannot find module 'doof/runtime' ↓
cause Trying to directly import runtime files without proper path.
fix
Use 'doof' package only for the transpiler and manually copy runtime files from node_modules/doof/.
error TypeError: transpile is not a function ↓
cause Using default import instead of named import.
fix
Change 'import transpile from "doof"' to 'import { transpile } from "doof"'.
error Error: Unknown target 'javascript' ↓
cause Using 'javascript' instead of 'js' as target.
fix
Use target: 'js' (not 'javascript').
error error: cannot find class "Array" ↓
cause Using non-existent built-in types in doof language.
fix
Use doof's built-in types: int, float, string, bool, array, map.
Warnings
gotcha The default target is C++ (cpp), not JavaScript. ↓
fix Explicitly pass {target: 'js'} when you want JavaScript output.
gotcha Package version is 0.0.2, very early stage. Breaking changes can happen with minor updates. ↓
fix Pin to exact version in package.json: "doof": "0.0.2".
gotcha The transpiled C++ output requires the included runtime files (doof_runtime.cpp/.h) to compile. ↓
fix Copy doof_runtime.cpp and doof_runtime.h to your project and compile them with your generated code.
gotcha CLI options have changed between minor versions; '--target' requires a value (cpp/js/vm) and is not optional. ↓
fix Use -t js or --target js; do not omit the flag.
Install
npm install doof yarn add doof pnpm add doof Imports
- Transpiler wrong
const Transpiler = require('doof').Transpilercorrectimport { Transpiler } from 'doof' - transpile wrong
import transpile from 'doof'correctimport { transpile } from 'doof' - TranspilerOptions wrong
import { TranspilerOptions } from 'doof'correctimport type { TranspilerOptions } from 'doof'
Quickstart
import { transpile, Transpiler } from 'doof';
// Simple single-file transpilation
const result = transpile(
`class Greeter {
name: string;
greet(): string {
return \`Hello, \${this.name}!\`;
}
}
function main(): int {
let greeter = Greeter { name: "World" };
print(greeter.greet());
return 0;
}`,
{ target: 'cpp' }
);
console.log(result.code);
// Multi-file project transpilation
const transpiler = new Transpiler({ target: 'js', namespace: 'myapp' });
transpiler.transpileProject(['file1.do', 'file2.do']).then(projectResult => {
projectResult.files.forEach(f => console.log(f.path, f.code));
});