@algosail/compiler
v0.0.3
Published
Compiles Sail source to JavaScript.
Readme
@algosail/compiler
Compiles Sail source to JavaScript.
API
compile(uri, sailSource, options?)
import { compile } from '@algosail/compiler'
const { js, errors } = await compile('file:///app/main.sail', source, { outPath: '/app' })uri— File URI of the Sail filesailSource— Sail source stringoptions.outPath— Output directory for import resolution
Returns { js?, sourceMap?, errors: Array<{ message, startPosition?, uri?, hint? }> }.
Options:
outPath— Output directory for resolving relative importssourceMap— Generate source map (default: false unlessoutFileprovided)outFile— Output file path (required for source map generation)
CLI
sail-compile input.sail [--out output.js] [--no-source-map]- Writes compiled JS to
output.jsorinput.jsby default - Emits
input.js.mapand//# sourceMappingURL=when source maps enabled - Errors printed as
file:line:col: messagewith optional hints
Structure
| File | Role |
|------|------|
| lib/emitWord.js | Emit word as JS function |
| lib/emitStep.js | Emit single step (builtin, word ref, quotation, tag, …) |
| lib/emitImports.js | Emit import statements |
| lib/emitJSDoc.js | JSDoc for emitted words |
| lib/buildSourceMap.js | Source map generation |
| lib/formatError.js | Error formatting (file:line:col) |
| lib/errorHints.js | Hints for common errors |
| lib/parseMatchBlock.js | Parse MATCH block structure |
| lib/expectedType.js | rawToJsLiteral, expected type for quotation |
Pipeline
- Parse (via
@algosail/parser) - Typecheck (via
@algosail/typecheck) - Emit imports
- Emit each word as a function
Dependencies
@algosail/parser@algosail/typecheck@algosail/builtins
Tests
npm testUses brittle. See lang/docs/TESTING.md.
