tree-sitter-grammars / tree-sitter-vue

Vue.js grammar for tree-sitter
MIT License
7 stars 2 forks source link

`(text)` node inconsistencies with tree-sitter-html #2

Closed lucario387 closed 8 months ago

lucario387 commented 8 months ago

Using a template code of

<template>
    <router-view />
</template>

Using html parser, we get

(fragment ; [0, 0] - [3, 0]
  (element ; [0, 0] - [2, 11]
    (start_tag ; [0, 0] - [0, 10]
      (tag_name)) ; [0, 1] - [0, 9]
    (element ; [1, 4] - [1, 19]
      (self_closing_tag ; [1, 4] - [1, 19]
        (tag_name))) ; [1, 5] - [1, 16]
    (end_tag ; [2, 0] - [2, 11]
      (tag_name)))) ; [2, 2] - [2, 10]

While with vue, the same code is interpreted as

(component ; [0, 0] - [71, 0]
  (template_element ; [0, 0] - [2, 11]
    (start_tag ; [0, 0] - [0, 10]
      (tag_name)) ; [0, 1] - [0, 9]
    (text) ; [0, 10] - [1, 4]
    (element ; [1, 4] - [1, 19]
      (self_closing_tag ; [1, 4] - [1, 19]
        (tag_name))) ; [1, 5] - [1, 16]
    (text) ; [1, 19] - [2, 0]
    (end_tag ; [2, 0] - [2, 11]
      (tag_name))) ; [2, 2] - [2, 10]

Is it possible to remove the text node when it's whitespaces only?

lucario387 commented 8 months ago

Fixed with v2 branch