mirror of
https://github.com/windwp/nvim-ts-autotag.git
synced 2025-01-01 12:49:15 -06:00
fix: jsx #3
This commit is contained in:
parent
e623320172
commit
f0265b2f6e
@ -21,9 +21,6 @@ local HTML_TAG = {
|
||||
close_name_tag_pattern = 'erroneous_end_tag_name',
|
||||
element_tag = 'element',
|
||||
skip_tag_pattern = {'quoted_attribute_value', 'end_tag'},
|
||||
|
||||
close_tag = 'start_tag',
|
||||
close_name_tag = 'tag_name',
|
||||
}
|
||||
local JSX_TAG = {
|
||||
start_tag_pattern = 'jsx_opening_element',
|
||||
@ -34,11 +31,9 @@ local JSX_TAG = {
|
||||
close_name_tag_pattern = 'identifier',
|
||||
element_tag = 'jsx_element',
|
||||
skip_tag_pattern = {'jsx_closing_element','jsx_expression', 'string', 'jsx_attribute'},
|
||||
|
||||
close_name_tag = 'jsx_opening_element>identifier',
|
||||
close_tag = 'jsx_element',
|
||||
}
|
||||
|
||||
|
||||
M.test = false
|
||||
M.enableRename = true
|
||||
M.enableClose = true
|
||||
@ -53,7 +48,6 @@ M.setup = function (opts)
|
||||
vim.cmd[[augroup end]]
|
||||
end
|
||||
|
||||
|
||||
local function is_in_table(tbl, val)
|
||||
if tbl == nil then return false end
|
||||
for _, value in pairs(tbl) do
|
||||
@ -174,8 +168,8 @@ end
|
||||
local function checkCloseTag()
|
||||
local ts_tag = get_ts_tag()
|
||||
local tag_node = find_tag_node({
|
||||
tag_pattern = ts_tag.close_tag,
|
||||
name_tag_pattern = ts_tag.close_name_tag,
|
||||
tag_pattern = ts_tag.start_tag_pattern,
|
||||
name_tag_pattern = ts_tag.start_name_tag_pattern,
|
||||
skip_tag_pattern = ts_tag.skip_tag_pattern
|
||||
})
|
||||
if tag_node ~=nil then
|
||||
@ -184,25 +178,6 @@ local function checkCloseTag()
|
||||
return false
|
||||
end
|
||||
return true,tag_name
|
||||
-- tag_node = find_parent_match({
|
||||
-- target = tag_node,
|
||||
-- pattern = ts_tag.element_tag,
|
||||
-- max_depth = 2
|
||||
-- })
|
||||
-- local close_tag_node = find_close_tag_node({
|
||||
-- target = tag_node,
|
||||
-- tag_pattern = ts_tag.end_tag_pattern,
|
||||
-- name_tag_pattern = ts_tag.end_name_tag_pattern,
|
||||
-- })
|
||||
-- -- check if already have exist tag
|
||||
-- if close_tag_node ~= nil then
|
||||
-- local close_tag_name = get_tag_name(close_tag_node)
|
||||
-- if tag_name ~= close_tag_name then
|
||||
-- return true ,tag_name
|
||||
-- end
|
||||
-- else
|
||||
-- return true,tag_name
|
||||
-- end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
@ -2,7 +2,7 @@
|
||||
import React, { useCallback, useEffect } from 'react'
|
||||
|
||||
const SamplePage: React.FC = () => {
|
||||
const [state, setstate] = useState(initialState)
|
||||
const [state, setstate] = useState<string>(initialState)
|
||||
|
||||
useEffect(() => {
|
||||
},[])
|
||||
|
@ -42,7 +42,7 @@ local data = {
|
||||
linenr = 10,
|
||||
key = [[>]],
|
||||
before = [[<div>aa</div|]],
|
||||
after = [[<div>aa</div>]]
|
||||
after = [[<div>aa</div>|]]
|
||||
},
|
||||
{
|
||||
name = "html not close on input tag" ,
|
||||
@ -89,6 +89,25 @@ local data = {
|
||||
before = [[<div|]],
|
||||
after = [[<div>|</div>]]
|
||||
},
|
||||
{
|
||||
name = "typescriptreact not close on exist tag" ,
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[const a = () => <div|]],
|
||||
after = [[const a = () => <div>|</div>]]
|
||||
},
|
||||
|
||||
{
|
||||
name = "typescriptreact close tag" ,
|
||||
filepath = './sample/index.tsx',
|
||||
filetype = "typescriptreact",
|
||||
linenr = 12,
|
||||
key = [[>]],
|
||||
before = [[<Img|]],
|
||||
after = [[<Img>|</Img>]]
|
||||
},
|
||||
{
|
||||
name = "typescriptreact not close on close tag" ,
|
||||
filepath = './sample/index.tsx',
|
||||
@ -176,9 +195,9 @@ local function Test(test_data)
|
||||
-- autotag.closeTag()
|
||||
helpers.insert(value.key)
|
||||
local result = vim.fn.getline(line)
|
||||
-- local pos = vim.fn.getpos('.')
|
||||
local pos = vim.fn.getpos('.')
|
||||
eq(after, result , "\n\n [ERROR TEXT]: " .. value.name .. "\n")
|
||||
-- eq(p_after, pos[3] + 1, "\n\n [ERROR POS]: " .. value.name .. "\n")
|
||||
eq(p_after, pos[3] + 1, "\n\n [ERROR POS]: " .. value.name .. "\n")
|
||||
else
|
||||
eq(false, true, "\n\n file not exist " .. value.filepath .. "\n")
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user