toJson method
Encode pattern components in the same shape as the Rust EST (Vec<PatternElem>) format.
Implementation
List<Object?> toJson() {
if (jsonForm case final json?) {
return json;
}
final encoded = <Object?>[];
for (final comp in comps) {
if (comp is Wildcard) {
encoded.add('Wildcard');
continue;
}
for (final rune in comp.literal.runes) {
encoded.add({'Literal': String.fromCharCode(rune)});
}
}
return encoded;
}