tss

tree-sitter-svelte

Tree sitter grammar for Svelte

Showing:

Popularity

Downloads/wk

3

GitHub Stars

21

Maintenance

Last Commit

2mos ago

Contributors

2

Package

Dependencies

3

Size (min+gzip)

1.0KB

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

Tree-sitter-svelte

Tree-sitter grammar for svelte

Install

npm i tree-sitter-svelte tree-sitter

Usage

To get started with exploring the grammar in a web-ui. Run:

NOTE: emcc must be installed and in your path

npm run ui

To use the grammar from javascript:

const Parser = require("tree-sitter");
const Svelte = require("tree-sitter-svelte");

const parser = new Parser();
parser.setLanguage(Svelte);

const sourceCode = `
<script context="module">
    let name = 'world';
</script>
<h1>Hello {name'<>{}``"\\''""``{}}!</h1>
`;

const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());

// (document
//    (script_element
//        (start_tag (tag_name)
//            (attribute (attribute_name) (quoted_attribute_value (attribute_value))))
//        (raw_text)
//        (end_tag (tag_name))
//    )
//    (element
//        (start_tag (tag_name))
//        (text) (raw_text_expr) (text)
//        (end_tag (tag_name)
//    )
//  )
//)

Languages supported:

  • JavaScript/TypeScript
  • Rust
  • Go
  • Zig
  • Nim
  • Python

LICENSE

MIT

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100