API Stability Notice

Macroforge is under active development. The API is not yet stable and may change between versions. Some documentation sections may be outdated.

API Reference

Macroforge provides a programmatic API for expanding macros in TypeScript code.

Overview

TypeScript
import {
  expandSync,
  transformSync,
  checkSyntax,
  parseImportSources,
  NativePlugin,
  PositionMapper
} from "macroforge";

Core Functions

FunctionDescription
expandSync()Expand macros synchronously
transformSync()Transform code with additional metadata
checkSyntax()Validate TypeScript syntax
parseImportSources()Extract import information

Classes

ClassDescription
NativePluginStateful plugin with caching
PositionMapperMaps positions between original and expanded code

Quick Example

TypeScript
import { expandSync } from "macroforge";

const sourceCode = `
/** @derive(Debug) */
class User {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
}
`;

const result = expandSync(sourceCode, "user.ts", {
  keepDecorators: false
});

console.log(result.code);
// Output: class with toString() method generated

if (result.diagnostics.length > 0) {
  console.error("Errors:", result.diagnostics);
}

Detailed Reference