This release includes several features and improvements for the custom visitor API, including support for defining how to parse custom at rules. In addition, lots of bug fixes are included for auto prefixing, selector downleveling, and more.
Custom at-rules
When Lightning CSS does not know how to parse an unknown at rule, it stores the prelude and body as a list of raw tokens. Without a definition for how a rule should be parsed, Lighting CSS doesn't know how to interpret it. Tokens are fine for simple use cases, but if you are building a custom visitor plugin that processes a custom at-rule, and want it to integrate with the rest of CSS, it is useful to define how the rule should be parsed and interpreted. In this release, a new customAtRules
option has been added to the API to enable just that.
For example, here is how you could define an @mixin
rule which expects a custom identifier as its prelude, and a style-block as its body. This allows nesting declarations and rules just like other at-rules like @media
and @supports
.
{
customAtRules: {
mixin: {
prelude: '<custom-ident>',
body: 'style-block'
}
}
}
With that, you can parse code like this:
@mixin foo {
color: red;
&.bar {
color: green;
}
}
Lightning CSS also validates the code and will emit syntax errors when it doesn't conform to the syntax definition. Another nice part is that we use this definition to automatically infer the TypeScript types for these rules when used in custom visitors.
Check out the documentation to learn more!
Features
- Implement support for parsing custom at rules in JS bindings (#395)
- Support
raw
property on returned declarations in visitors (#385) - Support
raw
values in visitors that return tokens (f9ed30f) - Make more AST properties optional in visitor return types (3fc05a9)
- Add
substitute_variables
function toUnparsedProperty
in the Rust API (#388) - Add
Implement Property::set_prefix
function (a19228d) - Merge non-adjacent
@layer
rules (6419d54) - Short-circuit on error in Rust visitor API (#406)
- Support nesting selector at the root, which is transformed to
:scope
(4443411)
Fixes
- fix:
<layer-name>
should be escaped (#383) - WASM: Only use import.meta.url in fallback scenario (#410)
- Publish docs for optional features on docs.rs (#407)
- Support node in wasm package (#387)
- Fix parsing oblique angles in font-style descriptor (0e84e8e)
- Update autoprefixer data for text-decoration (a58ea6f)
- Bump mdn compat data (59cbc02)
- Fix downleveling selectors in
:is
,:where
, and:has
(31fc453) - Fix serializing
:host
and::slotted
selectors (482fc40) - Copy license into all npm packages (856d460)
- Improve deserialization error messages for custom visitors (331c8a9)
- Fix cue-region-function ast types (6a53944)
- Fix serializing
currentColor
(fcf4127) - Use unpkg module option in docs for wasm (f394b50)