alloc / alloc/saus

Add compile-time evaluation

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
enhancement roadmap
Dominant language
TypeScript
Stars
38
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Useful for compile-time data generation used in declaring routes, paths, etc.

```ts
// src/node/routes.ts
import { preval } from 'saus'

// Run this module at compile-time. Unwrap its default export. Top-level await is allowed.
const result = preval(import('./path/to/module'))
```

In the future, we could support inline function that references outside its scope.
```ts
// src/node/routes.ts
import { preval } from 'saus'
import fs from 'fs'

const result = preval(() => {
return fs.readdirSync('./data')
})
```

…or even a simple expression:
```ts
// src/node/routes.ts
import { preval } from 'saus'
import fs from 'fs'

const result = preval(fs.readdirSync('./data'))
```

The result would be passed through our `dataToEsm` helper.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.