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
| Function | Description |
|---|---|
expandSync() | Expand macros synchronously |
transformSync() | Transform code with additional metadata |
checkSyntax() | Validate TypeScript syntax |
parseImportSources() | Extract import information |
Classes
| Class | Description |
|---|---|
NativePlugin | Stateful plugin with caching |
PositionMapper | Maps 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
expandSync()- Full options and return typestransformSync()- Transform with source mapsNativePlugin- Caching for language serversPositionMapper- Position mapping utilities