`tree-sitter-vue` provides a specialized grammar for parsing Vue.js template syntax, specifically targeting Vue v2.6.0. It leverages the `tree-sitter` parsing library to generate concrete syntax trees for the template sections within `.vue` files. As of version 0.2.1, its primary focus is on the Vue 2 template syntax itself, explicitly not handling embedded languages like JavaScript within `<script>` tags or CSS within `<style>` tags. Users needing multi-language parsing must integrate other `tree-sitter` grammars for those respective sections. The project appears to be in maintenance mode, with its last commit dating to September 2021, suggesting infrequent releases unless major changes occur in Vue 2 syntax or the `tree-sitter` core. It differentiates itself by offering a robust, structural parse of Vue 2 templates, which is crucial for advanced tooling like linters, formatters, and IDE features that rely on accurate syntax analysis.
npm install tree-sitter-vueVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Tree-sitter parser with the Vue grammar and parse a basic Vue 2 template string, then print its root node's S-expression representation.
For Vue 3 projects, seek out a dedicated `tree-sitter-vue3` grammar (e.g., `tree-sitter-vue3` for Rust) or use a custom parser compatible with the target Vue version. This package is not suitable for Vue 3.
To achieve full multi-language parsing of Vue SFCs, you must manually combine this grammar with other `tree-sitter` grammars (e.g., `tree-sitter-javascript`, `tree-sitter-css`) for the embedded sections, following Tree-sitter's 'Multi-language Documents' guidelines.
Evaluate alternatives for actively developed projects or consider forking if extensive updates or new feature support are critical for your use case.
Ensure your Vue project uses Vue 2.6.0 syntax or find a different grammar compatible with your specific Vue version. Inspect the template for unsupported syntax elements.
Run `npm install tree-sitter-vue tree-sitter`. If using an ESM environment, ensure your bundler (e.g., Webpack, Rollup, Vite) is configured to correctly handle and transpile CommonJS modules.