Files
quininerandGitHub dfaa5d5ddf refactor(ast): Introduce flexible serialization encoding for AST (#11100)
**Description:**

Following our previous discussion, I am trying to introduce a
self-describing serialization encoding for ast to replace
https://github.com/swc-project/swc/pull/11069 .

Since `serde` is currently used for json serialization, it is hard to
modify serde to support both json and binary encodings (due to the
`untagged` and `flatten` attr). So I made our own `Encode` and `Decode`
proc macro, which also facilitate unknown variant support.

<img width="1804" height="1776" alt="benchmark"
src="https://github.com/user-attachments/assets/73e294cd-be88-43a0-a390-fdd24c8f464f"
/>

I've done some simple benchmarks with a modified swc ast, and I believe
we don't have an unacceptable performance loss relative to `rkyv`.
I'm using `cbor4ii` here, which I developed, so I'd prefer it if there's
no performance difference. but it's easy to migrate to `bincode` or
other scheme.

This also introduces an `unknown` feature for `ecma_ast` crate, which
should only be enabled by the wasm plugin to ensure that old plugins can
decode new AST.
2025-10-31 18:06:00 +09:00

174 lines
4.3 KiB
JSON

{
"type": "Stylesheet",
"span": {
"start": 1,
"end": 31
},
"rules": [
{
"type": "QualifiedRule",
"span": {
"start": 1,
"end": 31
},
"prelude": {
"type": "SelectorList",
"span": {
"start": 1,
"end": 7
},
"children": [
{
"type": "ComplexSelector",
"span": {
"start": 1,
"end": 7
},
"children": [
{
"type": "CompoundSelector",
"span": {
"start": 1,
"end": 7
},
"nestingSelector": null,
"typeSelector": null,
"subclassSelectors": [
{
"type": "ClassSelector",
"span": {
"start": 1,
"end": 7
},
"text": {
"type": "Ident",
"span": {
"start": 2,
"end": 7
},
"value": "style",
"raw": "style"
}
}
]
}
]
}
]
},
"block": {
"type": "SimpleBlock",
"span": {
"start": 8,
"end": 31
},
"name": {
"type": "PreservedToken",
"span": {
"start": 8,
"end": 9
},
"token": "LBrace"
},
"value": [
{
"type": "Declaration",
"span": {
"start": 11,
"end": 31
},
"name": {
"type": "Ident",
"span": {
"start": 11,
"end": 16
},
"value": "width",
"raw": "width"
},
"value": [
{
"type": "Function",
"span": {
"start": 18,
"end": 31
},
"name": {
"type": "Ident",
"span": {
"start": 18,
"end": 21
},
"value": "min",
"raw": "min"
},
"value": [
{
"type": "PreservedToken",
"span": {
"start": 22,
"end": 27
},
"token": {
"Dimension": {
"dimension": {
"value": 500.0,
"raw_value": "500",
"unit": "px",
"type": "integer",
"raw_unit": "px"
}
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 27,
"end": 28
},
"token": "Semi"
},
{
"type": "PreservedToken",
"span": {
"start": 28,
"end": 29
},
"token": {
"WhiteSpace": {
"value": "\n"
}
}
},
{
"type": "PreservedToken",
"span": {
"start": 29,
"end": 30
},
"token": "RBrace"
},
{
"type": "PreservedToken",
"span": {
"start": 30,
"end": 31
},
"token": {
"WhiteSpace": {
"value": "\n"
}
}
}
]
}
],
"important": null
}
]
}
}
]
}