Skip to content

Serde support#176

Merged
devongovett merged 2 commits intomasterfrom
serde
May 12, 2022
Merged

Serde support#176
devongovett merged 2 commits intomasterfrom
serde

Conversation

@devongovett
Copy link
Member

@devongovett devongovett commented May 11, 2022

Closes #143

This adds serde serialization and deserialization support to all AST nodes, behind a feature flag. Appears to work, but need to verify the output.

cc. @lucacasonato @johno

@devongovett devongovett marked this pull request as ready for review May 12, 2022 04:42
@devongovett
Copy link
Member Author

Did some testing and verified the output seems reasonable. There are certainly improvements we can make (e.g. a nicer format for vendor prefixes in properties, more detailed serialization of selector components, etc.), but it seems usable for now.

To use, you need to enable the serde feature flag for the crate. You can also test the example in the readme which parses the provided filename and outputs JSON to stdout.

cargo run --example serialize --features serde test.css | jless

The format follows the documented rust structs, but with kebab case for enum variants (matching CSS itself), and a few other minor differences. Not sure if possible, but a future improvement could be to somehow generate TypeScript definitions for the format.

Going to merge as MVP. Please let me know if you have feedback!

@devongovett devongovett merged commit ff02e81 into master May 12, 2022
@devongovett devongovett deleted the serde branch May 12, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement serde::Serialize on AST

1 participant