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

257 lines
6.5 KiB
JSON

{
"type": "Stylesheet",
"span": {
"start": 1,
"end": 80
},
"rules": [
{
"type": "QualifiedRule",
"span": {
"start": 1,
"end": 79
},
"prelude": {
"type": "SelectorList",
"span": {
"start": 1,
"end": 4
},
"children": [
{
"type": "ComplexSelector",
"span": {
"start": 1,
"end": 4
},
"children": [
{
"type": "CompoundSelector",
"span": {
"start": 1,
"end": 4
},
"nestingSelector": null,
"typeSelector": {
"type": "TagNameSelector",
"span": {
"start": 1,
"end": 4
},
"name": {
"type": "WqName",
"span": {
"start": 1,
"end": 4
},
"prefix": null,
"value": {
"type": "Ident",
"span": {
"start": 1,
"end": 4
},
"value": "div",
"raw": "div"
}
}
},
"subclassSelectors": []
}
]
}
]
},
"block": {
"type": "SimpleBlock",
"span": {
"start": 5,
"end": 79
},
"name": {
"type": "PreservedToken",
"span": {
"start": 5,
"end": 6
},
"token": "LBrace"
},
"value": [
{
"type": "Declaration",
"span": {
"start": 11,
"end": 26
},
"name": {
"type": "Ident",
"span": {
"start": 11,
"end": 15
},
"value": "prod",
"raw": "prod"
},
"value": [
{
"type": "Function",
"span": {
"start": 17,
"end": 26
},
"name": {
"type": "Ident",
"span": {
"start": 17,
"end": 19
},
"value": "fn",
"raw": "fn"
},
"value": [
{
"type": "Length",
"span": {
"start": 20,
"end": 25
},
"value": {
"type": "Number",
"span": {
"start": 20,
"end": 23
},
"value": 100.0,
"raw": "100"
},
"unit": {
"type": "Ident",
"span": {
"start": 23,
"end": 25
},
"value": "px",
"raw": "px"
}
}
]
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 32,
"end": 49
},
"name": {
"type": "Ident",
"span": {
"start": 32,
"end": 36
},
"value": "prod",
"raw": "prod"
},
"value": [
{
"type": "Function",
"span": {
"start": 38,
"end": 49
},
"name": {
"type": "DashedIdent",
"span": {
"start": 38,
"end": 42
},
"value": "fn",
"raw": "--fn"
},
"value": [
{
"type": "PreservedToken",
"span": {
"start": 43,
"end": 48
},
"token": {
"Dimension": {
"dimension": {
"value": 100.0,
"raw_value": "100",
"unit": "px",
"type": "integer",
"raw_unit": "px"
}
}
}
}
]
}
],
"important": null
},
{
"type": "Declaration",
"span": {
"start": 55,
"end": 76
},
"name": {
"type": "Ident",
"span": {
"start": 55,
"end": 59
},
"value": "prod",
"raw": "prod"
},
"value": [
{
"type": "Function",
"span": {
"start": 61,
"end": 76
},
"name": {
"type": "DashedIdent",
"span": {
"start": 61,
"end": 69
},
"value": "fn--fn",
"raw": "--fn--fn"
},
"value": [
{
"type": "PreservedToken",
"span": {
"start": 70,
"end": 75
},
"token": {
"Dimension": {
"dimension": {
"value": 100.0,
"raw_value": "100",
"unit": "px",
"type": "integer",
"raw_unit": "px"
}
}
}
}
]
}
],
"important": null
}
]
}
}
]
}