JavaScript API

The WebAssembly build's exports, options, results and errors.

Published to npm as @zoosky/accent-sass, built with wasm-pack for the web target; see Install. The package ships an index.d.ts with real types.

Option names follow dart-sass's JavaScript API wherever the two have a name for the same knob, so a caller that knows one knows the other.

Exports

ExportSignature
compileString(source: string, options?: CompileOptions) => CompileResult
compile(path: string, options?: CompileOptions) => CompileResult
from_string(input: string) => string
default / initSyncwasm-bindgen's initialisers

compile takes the entry point from options.files and ignores options.url, because the path already names the entry.

from_string is the package's original export, kept so existing callers keep working. It has no options and no filesystem, so it cannot resolve @use, and it throws the formatted error block as a string rather than an object.

CompileOptions

OptionTypeDefaultEffect
filesRecord<string,string> or Map<string,string>{}The stylesheet tree imports resolve against
loadPathsstring[][]Searched when a relative import does not resolve
urlstring"stdin"Virtual path of the source; relative imports resolve against its directory, and its extension sets the syntax
style"expanded" | "compressed""expanded"Output style
syntax"scss" | "indented" | "css"from urlSyntax of the entry point only
charsetbooleantrueEmit @charset or a byte-order mark for non-ASCII output
alertAsciibooleanfalseRestrict error messages to ASCII. The inverse of the Rust API's unicode_error_messages
quietbooleanfalseSilence @warn and @debug
logger(event: SassLogEvent) => voidnoneCalled for each @warn and @debug

"sass" is accepted as a synonym for "indented", because that is what the file extension is called. dart-sass spells it indented.

Paths in files are virtual and normalized: a/b.scss and ./a/b.scss name the same file.

A malformed option throws a TypeError rather than failing later as a confusing Sass error. An array passed as files is rejected for that reason.

CompileResult

FieldTypeMeaning
cssstringThe compiled CSS
loadedUrlsstring[]The files the compile read, in order

loadedUrls counts reads, not distinct files, so a stylesheet consulted twice appears twice. De-duplicate if you want a file count.

SassLogEvent

FieldType
type"warn" or "debug"
messagestring
filestring
linenumber, 1-based
columnnumber, 1-based

An exception thrown by the logger is swallowed: a warning must not be able to fail a compile that would otherwise have succeeded.

Errors

A failed compile throws a real Error, so instanceof Error holds and a stack trace survives.

PropertyMeaning
messageThe Sass message alone, with no span or source context
formattedThe full block the command line prints, with source line and caret
fileThe file the error is in
line1-based
column1-based

A missing entry point or a non-UTF-8 file has no span; file is empty and line and column are 0, so a caller never has to branch on shape.

The synchronous filesystem

Fs::read returns bytes directly, with nothing to await. An importer therefore cannot fetch, cannot await and cannot use the File System Access API: every file a compile might touch must be in files before the call.

Making imports asynchronous would mean an asynchronous evaluator, which is a rewrite rather than a binding change.

Size

Buildwasmgzipped
--features wasm-exports,random1.72 MB0.62 MB
Without wasm-exports0.22 MB

The second row is a module with no compiler in it: without the feature, wasm-bindgen exports nothing and every symbol is dead code.