svelte_ast
Parser and utilities for the SvelteDart template compiler.
Based on the original Svelte 5 (v5.16.6) parser. Top-level scripts,
styles and template expressions are parsed using analyzer
and
`csslib.
Usage
import 'dart:convert';
import 'package:svelte_ast/svelte_ast.dart';
import 'package:svelte_ast/mirror_mapper.dart';
const String content = '''
<script>
int count = 0;
</script>
<button on:click="{() => count++}">count: {count}</button>''';
void main() {
// Create an AST tree by parsing a template.
Root root = parse(content);
// Print to console.
print(const JsonEncoder.withIndent(' ').convert(root.toJson(mapper)));
}