Skip to content

Commit

Permalink
feat(jsx): support member expression
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Nov 21, 2024
1 parent 2e6cef3 commit b25fdfa
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
11 changes: 11 additions & 0 deletions queries/tsx/neolog-log-target.scm
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,14 @@
(#not-has-parent? @log_target jsx_closing_element)
(#not-has-parent? @log_target jsx_self_closing_element)
)

(
([
(member_expression)
(subscript_expression)
]) @log_target
(#not-field-of-ancestor? @log_target call_expression function)
(#not-has-parent? @log_target jsx_opening_element)
(#not-has-parent? @log_target jsx_closing_element)
(#not-has-parent? @log_target jsx_self_closing_element)
)
62 changes: 62 additions & 0 deletions tests/neolog/actions/lang/jsx_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,68 @@ describe("javascriptreact", function()
})
end)

it("DOES NOT support jsx opening and closing tags", function()
helper.assert_scenario({
input = [[
const foo = <di|v>
<div>{b + 1}</div>
</div>
]],
filetype = "javascriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <div>
<div>{b + 1}</div>
</div>
]],
})

helper.assert_scenario({
input = [[
const foo = <div>
<div>{b + 1}</div>
</di|v>
]],
filetype = "javascriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <div>
<div>{b + 1}</div>
</div>
]],
})

helper.assert_scenario({
input = [[
const foo = <inp|ut />
]],
filetype = "javascriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <input />
]],
})

helper.assert_scenario({
input = [[
const foo = <Foo.B|ar>123</Foo.Bar>
]],
filetype = "javascriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <Foo.Bar>123</Foo.Bar>
]],
})
end)

it("supports visual selection log", function()
local input = [[
function foo() {
Expand Down
62 changes: 62 additions & 0 deletions tests/neolog/actions/lang/tsx_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,68 @@ describe("typescriptreact", function()
})
end)

it("DOES NOT support jsx opening and closing tags", function()
helper.assert_scenario({
input = [[
const foo = <di|v>
<div>{b + 1}</div>
</div>
]],
filetype = "typescriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <div>
<div>{b + 1}</div>
</div>
]],
})

helper.assert_scenario({
input = [[
const foo = <div>
<div>{b + 1}</div>
</di|v>
]],
filetype = "typescriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <div>
<div>{b + 1}</div>
</div>
]],
})

helper.assert_scenario({
input = [[
const foo = <inp|ut />
]],
filetype = "typescriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <input />
]],
})

helper.assert_scenario({
input = [[
const foo = <Foo.B|ar>123</Foo.Bar>
]],
filetype = "typescriptreact",
action = function()
actions.insert_log({ position = "above" })
end,
expected = [[
const foo = <Foo.Bar>123</Foo.Bar>
]],
})
end)

it("supports visual selection log", function()
local input = [[
function foo() {
Expand Down

0 comments on commit b25fdfa

Please sign in to comment.