Skip to content

Commit

Permalink
feat(javascript): support if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
Goose97 committed Nov 21, 2024
1 parent 6f44821 commit ce490ac
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
5 changes: 5 additions & 0 deletions queries/javascript/neolog-log-container.scm
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@
body: (statement_block) @logable_range (#adjust-range! @logable_range 1 -1)
)
)

(if_statement
condition: (parenthesized_expression) @log_container
consequence: (statement_block) @logable_range (#adjust-range! @logable_range 1 -1)
)
41 changes: 41 additions & 0 deletions tests/neolog/actions/lang/javascript_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,47 @@ describe("javascript", function()
end)
end)

it("supports if clause", function()
local actions = require("neolog.actions")

local input = [[
if (fo|o > 1 && bar < baz) {
return null
}
]]

helper.assert_scenario({
input = input,
filetype = "javascript",
action = function()
actions.add_log({ log_template = [[console.log("%identifier", %identifier)]], position = "below" })
end,
expected = [[
if (foo > 1 && bar < baz) {
console.log("foo", foo)
return null
}
]],
})

helper.assert_scenario({
input = input,
filetype = "javascript",
action = function()
vim.cmd("normal! vi(")
actions.add_log({ log_template = [[console.log("%identifier", %identifier)]], position = "below" })
end,
expected = [[
if (foo > 1 && bar < baz) {
console.log("foo", foo)
console.log("bar", bar)
console.log("baz", baz)
return null
}
]],
})
end)

describe("supports import statements", function()
it("supports plain imports", function()
local actions = require("neolog.actions")
Expand Down
41 changes: 41 additions & 0 deletions tests/neolog/actions/lang/typescript_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,47 @@ describe("typescript", function()
end)
end)

it("supports if clause", function()
local actions = require("neolog.actions")

local input = [[
if (fo|o > 1 && bar < baz) {
return null
}
]]

helper.assert_scenario({
input = input,
filetype = "typescript",
action = function()
actions.add_log({ log_template = [[console.log("%identifier", %identifier)]], position = "below" })
end,
expected = [[
if (foo > 1 && bar < baz) {
console.log("foo", foo)
return null
}
]],
})

helper.assert_scenario({
input = input,
filetype = "typescript",
action = function()
vim.cmd("normal! vi(")
actions.add_log({ log_template = [[console.log("%identifier", %identifier)]], position = "below" })
end,
expected = [[
if (foo > 1 && bar < baz) {
console.log("foo", foo)
console.log("bar", bar)
console.log("baz", baz)
return null
}
]],
})
end)

describe("supports import statements", function()
it("supports plain imports", function()
local actions = require("neolog.actions")
Expand Down

0 comments on commit ce490ac

Please sign in to comment.