mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-17 10:50:06 -04:00
fix(jsx): add missing indent end mark to elements
This commit is contained in:
parent
8c71c6c5ed
commit
2cd89b4bc3
6 changed files with 98 additions and 1 deletions
|
|
@ -46,6 +46,7 @@
|
||||||
] @branch
|
] @branch
|
||||||
(statement_block "{" @branch)
|
(statement_block "{" @branch)
|
||||||
|
|
||||||
|
(parenthesized_expression ("(" (_) ")" @indent_end))
|
||||||
["}" "]"] @indent_end
|
["}" "]"] @indent_end
|
||||||
|
|
||||||
[
|
[
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,20 @@
|
||||||
(jsx_fragment)
|
(jsx_fragment)
|
||||||
(jsx_element)
|
(jsx_element)
|
||||||
(jsx_self_closing_element)
|
(jsx_self_closing_element)
|
||||||
|
(jsx_expression)
|
||||||
] @indent
|
] @indent
|
||||||
|
|
||||||
(parenthesized_expression) @indent
|
(jsx_fragment
|
||||||
|
("<" ">" (_) "<" @branch "/" ">" @indent_end)
|
||||||
|
)
|
||||||
|
|
||||||
|
(jsx_closing_element (">" @indent_end))
|
||||||
|
(jsx_self_closing_element ">" @indent_end)
|
||||||
|
|
||||||
[
|
[
|
||||||
(jsx_closing_element)
|
(jsx_closing_element)
|
||||||
">"
|
">"
|
||||||
] @branch
|
] @branch
|
||||||
|
; <button
|
||||||
|
; />
|
||||||
|
(jsx_self_closing_element "/" @branch)
|
||||||
|
|
|
||||||
18
tests/indent/jsx/element_attributes.jsx
Normal file
18
tests/indent/jsx/element_attributes.jsx
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
color: 'blue',
|
||||||
|
}}
|
||||||
|
disabled
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
color: 'blue',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
10
tests/indent/jsx/issue-3986.jsx
Normal file
10
tests/indent/jsx/issue-3986.jsx
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<p>This is a test</p>
|
||||||
|
</div>
|
||||||
|
<Button/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
16
tests/indent/jsx/jsx_expression.jsx
Normal file
16
tests/indent/jsx/jsx_expression.jsx
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
export default function Home() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Button
|
||||||
|
style={
|
||||||
|
}
|
||||||
|
>
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
style={{
|
||||||
|
color: 'blue',
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
43
tests/indent/jsx_spec.lua
Normal file
43
tests/indent/jsx_spec.lua
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
local Runner = require("tests.indent.common").Runner
|
||||||
|
local runner = Runner:new(it, "tests/indent/jsx", {
|
||||||
|
tabstop = 2,
|
||||||
|
shiftwidth = 2,
|
||||||
|
expandtab = true,
|
||||||
|
filetype = "jsx",
|
||||||
|
})
|
||||||
|
|
||||||
|
describe("indent JSX Elements:", function()
|
||||||
|
describe("whole file:", function()
|
||||||
|
runner:whole_file(".", {
|
||||||
|
expected_failures = {},
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe("new line:", function()
|
||||||
|
for _, info in ipairs {
|
||||||
|
{ 5, 8 },
|
||||||
|
{ 6, 6 },
|
||||||
|
{ 7, 6 },
|
||||||
|
{ 8, 4 },
|
||||||
|
{ 9, 2 },
|
||||||
|
} do
|
||||||
|
runner:new_line("issue-3986.jsx", { on_line = info[1], text = "text", indent = info[2] })
|
||||||
|
end
|
||||||
|
for _, info in ipairs {
|
||||||
|
{ 4, 8 },
|
||||||
|
{ 6, 10 },
|
||||||
|
{ 9, 8 },
|
||||||
|
{ 11, 8 },
|
||||||
|
} do
|
||||||
|
runner:new_line("element_attributes.jsx", { on_line = info[1], text = "disabled", indent = info[2] })
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, info in ipairs {
|
||||||
|
{ 5, 10 },
|
||||||
|
{ 7, 8 },
|
||||||
|
{ 11, 10 },
|
||||||
|
} do
|
||||||
|
runner:new_line("jsx_expression.jsx", { on_line = info[1], text = "{disabled}", indent = info[2] })
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue