UNPKG

comptime.ts

Version:

<div align="center"> <img src="https://raw.githubusercontent.com/feathers-studio/comptime.ts/master/docs/comptime.ts.svg" alt="Hyperactive"> </div>

50 lines (49 loc) 1.44 kB
import { type ComptimeContext, type Defer } from "./async_store.ts"; export declare function getComptimeContext(): ComptimeContext | undefined; /** * Defer a function to be executed after comptime evaluation of all modules. * * ## Usage * * ```ts * comptime.defer(() => { * writeFileSync("foo.txt", "bar"); * }); * ``` * * Please note that while all deferred functions are guaranteed to be executed after comptime evaluation, * they are not guaranteed to be executed in any specific order because modules are evaluated concurrently. */ declare function defer(fn: Defer): void; /** * A function that returns the expression it was given. * This is useful to force comptime evaluation of an expression. * * Note that if the provided expression resolves to a Promise-like value, * it will be awaited and resolved to a value at comptime. * * ## Usage * * Import the `comptime` function from `comptime.ts` with the `type: "comptime"` option. * * ```ts * import { comptime } from "comptime.ts" with { type: "comptime" }; * ``` * * Use it to force comptime evaluation of an expression. * * ```ts * const x = comptime(1 + 2); * ``` * * When the compiler is run, the expression will be evaluated at compile time. * * ```ts * const x = 3; * ``` */ declare function comptime<T>(expr: T | PromiseLike<T>): T; declare const _comptime: typeof comptime & { defer: typeof defer; }; export { _comptime as comptime };