Closed
Description
From v0.21.4, I experienced the jsx elements to be captured too widely. Here's an example of it
export default function Home() {
return (
<>
<Button
style={{
color: 'blue',
}}
disabled
>
</Button>
</>
)
}
The output of tree-sitter parse
is the following:
(program [0, 0] - [13, 0]
(export_statement [0, 0] - [12, 1]
declaration: (function_declaration [0, 15] - [12, 1]
name: (identifier [0, 24] - [0, 28])
parameters: (formal_parameters [0, 28] - [0, 30])
body: (statement_block [0, 31] - [12, 1]
(return_statement [1, 2] - [11, 3]
(parenthesized_expression [1, 9] - [11, 3]
(jsx_element [2, 4] - [10, 7]
open_tag: (jsx_opening_element [2, 4] - [2, 6])
(jsx_element [2, 6] - [9, 15]
open_tag: (jsx_opening_element [2, 6] - [8, 7]
name: (identifier [3, 7] - [3, 13])
attribute: (jsx_attribute [4, 8] - [6, 10]
(property_identifier [4, 8] - [4, 13])
(jsx_expression [4, 14] - [6, 10]
(object [4, 15] - [6, 9]
(pair [5, 10] - [5, 23]
key: (property_identifier [5, 10] - [5, 15])
value: (string [5, 17] - [5, 23]
(string_fragment [5, 18] - [5, 22]))))))
attribute: (jsx_attribute [7, 8] - [7, 16]
(property_identifier [7, 8] - [7, 16])))
close_tag: (jsx_closing_element [8, 7] - [9, 15]
name: (identifier [9, 8] - [9, 14])))
close_tag: (jsx_closing_element [9, 15] - [10, 7]))))))))
While this is the parsed result from commit c4739fe
(program [0, 0] - [13, 0]
(export_statement [0, 0] - [12, 1]
declaration: (function_declaration [0, 15] - [12, 1]
name: (identifier [0, 24] - [0, 28])
parameters: (formal_parameters [0, 28] - [0, 30])
body: (statement_block [0, 31] - [12, 1]
(return_statement [1, 2] - [11, 3]
(parenthesized_expression [1, 9] - [11, 3]
(jsx_element [2, 4] - [10, 7]
open_tag: (jsx_opening_element [2, 4] - [2, 6])
(jsx_element [3, 6] - [9, 15]
open_tag: (jsx_opening_element [3, 6] - [8, 7]
name: (identifier [3, 7] - [3, 13])
attribute: (jsx_attribute [4, 8] - [6, 10]
(property_identifier [4, 8] - [4, 13])
(jsx_expression [4, 14] - [6, 10]
(object [4, 15] - [6, 9]
(pair [5, 10] - [5, 23]
key: (property_identifier [5, 10] - [5, 15])
value: (string [5, 17] - [5, 23]
(string_fragment [5, 18] - [5, 22]))))))
attribute: (jsx_attribute [7, 8] - [7, 16]
(property_identifier [7, 8] - [7, 16])))
close_tag: (jsx_closing_element [9, 6] - [9, 15]
name: (identifier [9, 8] - [9, 14])))
close_tag: (jsx_closing_element [10, 4] - [10, 7]))))))))
And the diff of the two parsed trees:
diff --git a/old_tree.txt b/new_tree.txt
index 31e1bb606db0..f0bb1eb3ac42 100644
--- a/old_tree.txt
+++ b/new_tree.txt
@@ -8,8 +8,8 @@
(parenthesized_expression [1, 9] - [11, 3]
(jsx_element [2, 4] - [10, 7]
open_tag: (jsx_opening_element [2, 4] - [2, 6])
- (jsx_element [3, 6] - [9, 15]
- open_tag: (jsx_opening_element [3, 6] - [8, 7]
+ (jsx_element [2, 6] - [9, 15]
+ open_tag: (jsx_opening_element [2, 6] - [8, 7]
name: (identifier [3, 7] - [3, 13])
attribute: (jsx_attribute [4, 8] - [6, 10]
(property_identifier [4, 8] - [4, 13])
@@ -21,6 +21,6 @@
(string_fragment [5, 18] - [5, 22]))))))
attribute: (jsx_attribute [7, 8] - [7, 16]
(property_identifier [7, 8] - [7, 16])))
- close_tag: (jsx_closing_element [9, 6] - [9, 15]
+ close_tag: (jsx_closing_element [8, 7] - [9, 15]
name: (identifier [9, 8] - [9, 14])))
- close_tag: (jsx_closing_element [10, 4] - [10, 7]))))))))
+ close_tag: (jsx_closing_element [9, 15] - [10, 7]))))))))
As can be seen from the file above. despite <></>
and <Button></Button>
be on different lines, the <Button>
element starts at [2, 6]
instead of [3, 6]
like in v0.21.3
I think the changes in 99be62f may have lead to this being affected.