@ball-lang/compiler
v1.59.8
Published
Ball → TypeScript compiler. Consumes a Ball protobuf Program and emits idiomatic TypeScript via ts-morph. The canonical TS compiler for Ball — lives in TS land so TS syntax knowledge doesn't leak into other languages.
Maintainers
Readme
@ball-lang/compiler
Compiles Ball programs (proto3 JSON / Program objects) into idiomatic TypeScript source. Runs entirely in-process using ts-morph — no Dart subprocess. The Dart compiler (dart/compiler/) is the canonical reference implementation; this package mirrors its semantics.
Install
npm install @ball-lang/compilerUsage
import { compile } from '@ball-lang/compiler';
// `program` is a Ball Program — a proto3 JSON object (or a parsed equivalent).
const program = {
name: 'hello',
version: '1.0.0',
entryModule: 'main',
entryFunction: 'main',
modules: [
{
name: 'std',
functions: [{ name: 'print', isBase: true }],
},
{
name: 'main',
moduleImports: [{ name: 'std' }],
functions: [
{
name: 'main',
body: {
call: {
module: 'std',
function: 'print',
input: {
messageCreation: {
fields: [
{ name: 'value', value: { literal: { stringValue: 'Hello, World!' } } },
],
},
},
},
},
},
],
},
],
};
const tsSource: string = compile(program);
console.log(tsSource); // emitted TypeScriptAPI
compile(program: Program, options?: CompileOptions): string— compile a whole program to TypeScript source.compileModule(module: Module, options?: CompileModuleOptions): string— compile a single module.BallCompiler— the underlying class, if you need finer control.TS_RUNTIME_PREAMBLE— the Dart-flavored runtime polyfill preamble injected at the top of compiled output.
CompileOptions:
| Option | Type | Description |
|--------|------|-------------|
| includePreamble | boolean | Prepend TS_RUNTIME_PREAMBLE to the output. Default true. |
| fileName | string | Output file path hint (affects ts-morph's internal resolution). |
License
MIT
