Expand description
sasso — a pure-Rust SCSS → CSS compiler.
A small, zero-dependency, embeddable Sass engine aiming at byte-exact
parity with current dart-sass on the subset it implements (e.g.
computed colors serialize as rgb(63.75, 127.5, 191.25), not rounded
hex). It is sandbox-friendly: @import resolution goes through a
caller-supplied Importer, so an embedder controls all file access.
§Example
use sasso::{compile, Options};
let css = compile("$c: #333; a { color: $c; &:hover { color: $c; } }", &Options::default()).unwrap();
assert!(css.contains("a {"));
assert!(css.contains("a:hover {"));§Scope
This covers a large slice of Sass: variables (!default/!global),
nesting and the & parent selector, #{} interpolation, // and
/* */ comments, unit arithmetic, the color functions, control flow,
mixins/functions, @extend, @import, and the @use/@forward module
system. Both input syntaxes are supported — the brace/semicolon SCSS
syntax and the indented .sass syntax (selected via Options::with_syntax
or, in the CLI, the input file’s extension) — parsing into the same AST and
sharing the evaluator and emitter. The north-star target is 100% of the
official sass-spec suite, tracked by the harness in spec/.
Structs§
- Canonical
Url - An opaque, importer-defined canonical identifier for a resolved stylesheet.
- Canonicalize
Context - Context passed to
Importer::canonicalize(dart-sass’sCanonicalizeContext). - Compile
Result - The CSS plus its source map, returned by
compile_with_source_map. - Error
- A compilation error, carrying a human-readable message and a 1-based
source position (
line/colare0when the position is unknown). - FsImporter
- A filesystem
Importerresolving Sass partials (_name.scss,name/_index.scss) against a list of load paths. - Importer
Error - A real importer failure — an I/O error, a permission error, an ambiguous
match, an invalid URL, … — as distinct from a plain miss. Surfaced as an
actionable compile
crate::Error, never silently treated as “not found”. - Importer
Result - The source an
Importer::loadproduced for aCanonicalUrl— dart-sass’sImporterResult. - Options
- Compilation options.
- Scoped
Alloc - A scoped bump global allocator. Inside a
compile()scope it bump-allocates from a per-thread arena that is reset when the scope ends; outside any scope it forwards to the system allocator. Install it in a binary or wasm wrapper: - Source
Map - A finished Source Map v3, ready to serialize as
JSON via
SourceMap::to_json. - Warn
Event - A
@warn/@debug/ deprecation diagnostic delivered to an embedder’sWarnHandler(dart-sasslogger).
Enums§
- Output
Style - Output formatting style.
- Syntax
- The input syntax flavour.
- Warn
Kind - The kind of a diagnostic delivered to a
WarnHandler.
Traits§
- Importer
- Resolves
@use/@forward/@importURLs in dart-sass’s two phases.
Functions§
- compile
- Compile SCSS source to CSS.
- compile_
with_ source_ map - Compile SCSS source to CSS and a Source Map v3.
- host_
value_ op - Run a value operation: deserialize the operands, dispatch on
op, and return the serialized result (or anErr(message)surfaced to the JS caller). - set_
arena_ bytes - Override the wasm arena reservation size, in bytes. Must be called
BEFORE the first
compile()— the region is reserved on first use and then fixed, so a later call has no effect.0disables the arena entirely (every allocation forwards to the system allocator: lower memory, slower). No effect on native targets (they always use the 2 GiB virtual reservation).
Type Aliases§
- Host
Function - An embedder’s custom-function callback: it receives the bound arguments
serialized to sasso’s host-value wire format and returns the result
serialized the same way (or an
Err(message)that becomes a compile error). - Warn
Handler - An embedder’s diagnostic handler (dart-sass
logger). Receives every@warn/@debug/ deprecation warning; if unset, they print to stderr.