https://github.com/himujjal/tree-sitter-svelte
Tree sitter grammar for Svelte
https://github.com/himujjal/tree-sitter-svelte
Last synced: about 1 month ago
JSON representation
Tree sitter grammar for Svelte
- Host: GitHub
- URL: https://github.com/himujjal/tree-sitter-svelte
- Owner: Himujjal
- License: mit
- Created: 2021-01-31T14:15:59.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-07T03:34:22.000Z (8 months ago)
- Last Synced: 2025-04-03T23:08:57.868Z (about 1 month ago)
- Language: C
- Size: 327 KB
- Stars: 84
- Watchers: 4
- Forks: 14
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tree-sitter-svelte
Tree-sitter grammar for [svelte](https://svelte.dev)
# Install
```
npm i tree-sitter-svelte tree-sitter
```Tree-sitter also requires [nodemon](https://nodemon.io/) to run, so also install that if you don’t already have it:
```
npm i -g nodemon
```Finally, you will need [pnpm](https://pnpm.io/installation). If you’re running Node 16.13 or later, it comes as part of Node so you can simply run the following to activate it:
```
corepack enable
```# Dev
After installation (`npm i`),
```
npm run dev
```# Usage
To get started with exploring the grammar in a web-ui. Run:
NOTE: `emcc` must be installed and in your path
```sh
npm run ui
```To use the grammar from javascript:
```javascript
const Parser = require("tree-sitter");
const Svelte = require("tree-sitter-svelte");const parser = new Parser();
parser.setLanguage(Svelte);const sourceCode = `
let name = 'world';
Hello {name'<>{}``"\\''""``{}}!
`;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)
// )
// )
//)
```# For Neovim peeps
Install `:TSInstall typescript scss` for the plugin to work everywhere in Neovim (TypeScript/SCSS/LESS/PostCSS)
# Languages supported:
- [x] JavaScript/TypeScript
- [x] Rust
- [ ] Go
- [ ] Nim
- [ ] Python# LICENSE
[MIT](./LICENSE)