@hecto/compiler
v3.0.0
Published
Zero-configuration build-time lowering for Hecto FP pipelines
Readme
@hecto/compiler
A build-time backend for explicitly pure @hecto/fp pipelines, including
environments where new Function is unavailable: strict Content Security
Policy pages, most browser extensions, and some serverless runtimes.
The plugin statically detects pipe(input, ...steps) / flow(...steps) /
compile(...steps) / compilePure(...steps) call sites whose every step is
a call to a tracked @hecto/fp/array, /option, /result, or /record
operator with statically-inspectable arguments, and replaces the call site
with a hoisted, monomorphic function __hgFused_N(input, ...bindings) { ... }
whose generated bindings are isolated from user bindings — the same
loop/ladder shape @hecto/fp's own runtime codegen produces, generated
at build time via @hecto/fp's emitSource. It never reimplements that
emission logic itself.
Single-step ordinary composition may be lowered because it preserves callback
count, order, and exceptions. Multi-step fusion requires compilePure,
pipe/flow imported from @hecto/fp/fusion, or plugin { pure: true }.
That explicit contract promises every callback is total, depends only on its
arguments, and has no observable side effects. Anything outside the supported
scope is left byte-identical and reported with a decline reason.
Usage
// vite.config.ts
import { hgFp } from '@hecto/compiler/vite'
export default {
plugins: [hgFp({ diagnostics: 'warn' })],
}Also available: @hecto/compiler/rollup, @hecto/compiler/esbuild,
@hecto/compiler/webpack, and @hecto/compiler's raw export (an
unplugin factory) for hosts that consume unplugin directly.
Options
diagnostics:'off' | 'warn' | 'error'(default'warn') —'warn'reports each declined site plus a build-end summary;'error'throws at the first declined site.pure:boolean(defaultfalse) — declares every matched pipeline in the included files pure and enables multi-step fusion. PrefercompilePureor the/fusionentry for a per-site contract.include/exclude: file filters (default: JS/TS/JSX/TSX, excludingnode_modules).
Testing without a bundler
transformHgPipelines(code, id, options) is exported as a pure function —
call it directly to get { code, map, diagnostics } without going through
any bundler.
Strict TypeScript consumers
The public adapter declarations use the native Vite, Rollup, esbuild and Webpack
types. These four host packages are declared peers; install them with the
compiler when your package manager does not install peers automatically.
The typed adapter surface covers those four hosts and the concrete raw factory.
Other unplugin adapter properties remain available at runtime for compatibility.
