Skip to main content

Crate sasso

Crate sasso 

Source
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§

CanonicalUrl
An opaque, importer-defined canonical identifier for a resolved stylesheet.
CanonicalizeContext
Context passed to Importer::canonicalize (dart-sass’s CanonicalizeContext).
CompileResult
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/col are 0 when the position is unknown).
FsImporter
A filesystem Importer resolving Sass partials (_name.scss, name/_index.scss) against a list of load paths.
ImporterError
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”.
ImporterResult
The source an Importer::load produced for a CanonicalUrl — dart-sass’s ImporterResult.
Options
Compilation options.
ScopedAlloc
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:
SourceMap
A finished Source Map v3, ready to serialize as JSON via SourceMap::to_json.
WarnEvent
A @warn / @debug / deprecation diagnostic delivered to an embedder’s WarnHandler (dart-sass logger).

Enums§

OutputStyle
Output formatting style.
Syntax
The input syntax flavour.
WarnKind
The kind of a diagnostic delivered to a WarnHandler.

Traits§

Importer
Resolves @use / @forward / @import URLs 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 an Err(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. 0 disables 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§

HostFunction
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).
WarnHandler
An embedder’s diagnostic handler (dart-sass logger). Receives every @warn / @debug / deprecation warning; if unset, they print to stderr.