Sign in

    scss

    SCSS 模块编译与 precss 项目引擎扩展

    Download zip
    Version
    0.9.0
    License
    MIT AND Apache-2.0
    Last updated
    26 days ago
    Downloads
    28

    #可执行 API 示例

    增加保留父选择器上下文的嵌套 @media 编译。这些例子调用公开 API,并随 moon test 执行。

    ///|
    test "nested media preserves parent selector" {
    assert_eq(
    @scss.compile(
    ".a{@media (min-width: 600px){color:red;&:hover{color:blue}}}",
    ),
    "@media (min-width: 600px) {\n.a {\n color: red;\n}\n.a:hover {\n color: blue;\n}\n}\n",
    )
    }

    限制:示例只是已实现范围的一部分;完整颜色、标准库、选择器、导入器及源码映射等缺项见 FEATURES.md。

    ParseError

    pub suberror ParseError {
    Invalid(String)
    } derive(
    Debug
    )

    Compilation

    pub(all) struct Compilation {
    css : String
    loaded_files : Array[String]
    diagnostics : Array[String]
    }

    The compiler reads only this caller-supplied virtual filesystem.

    ModuleDependency

    pub(all) struct ModuleDependency {
    from : String
    path : String
    } derive(ToJson)

    ModuleDependency::to_json

    Project

    pub struct Project {
    // private fields
    }

    Owned virtual files and completed per-entry results. Module evaluation is isolated per entry, including @use configuration. No cross-entry globals.

    Project::apply

    fn Project::apply(self : Project, updates : Map[String, String?]) -> Array[String] raise ParseError

    Atomically apply a file delta after canonical path and total-size validation. None deletes a file. Return invalidated cached entry paths, sorted. Absent resolution candidates are tracked, so additions can invalidate results too. Invalid edits leave both the virtual files and caches unchanged.

    Project::compile

    fn Project::compile(self : Project, entry : String) -> ProjectOutput raise ParseError

    Reuses only a completed result of this exact virtual snapshot. Cache is bounded to 16 entries / 4M CSS UTF-16 units; deterministic key-order eviction. Large outputs are returned uncached; evaluation limits still apply.

    Project::new

    fn Project::new(files : Map[String, String]) -> Project raise ParseError

    Project::source

    fn Project::source(self : Project, entry : String) -> String raise ParseError

    ProjectOutput

    pub(all) struct ProjectOutput {
    entry : String
    compilation : Compilation
    dependencies : Array[ModuleDependency]
    watched_files : Array[String]
    cache_hit : Bool
    }

    compile

    fn compile(source : String) -> String raise ParseError

    compile_files

    fn compile_files(entry : String, files : Map[String, String]) -> Compilation raise ParseError

    Compile an entry and its SCSS modules without accessing the host filesystem.