generated from ellisonleao/nvim-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
230 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
; Outside of jsx element | ||
( | ||
([ | ||
(identifier) | ||
(shorthand_property_identifier_pattern) | ||
]) @log_target | ||
(#not-has-ancestor? @log_target jsx_element) | ||
(#not-has-ancestor? @log_target jsx_self_closing_element) | ||
) | ||
|
||
; Inside of jsx expression but ignore opening and closing tags | ||
( | ||
([ | ||
(identifier) | ||
(shorthand_property_identifier_pattern) | ||
]) @log_target | ||
(#has-ancestor? @log_target jsx_expression) | ||
(#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) | ||
) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
([ | ||
(identifier) | ||
(shorthand_property_identifier_pattern) | ||
]) @log_target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
local neolog = require("neolog") | ||
local helper = require("tests.neolog.helper") | ||
|
||
describe("typescript", function() | ||
before_each(function() | ||
neolog.setup() | ||
end) | ||
|
||
it("supports jsx expression", function() | ||
local actions = require("neolog.actions") | ||
|
||
local input = [[ | ||
function foo() { | ||
const a = 1 | ||
return ( | ||
<div> | ||
<div>{a| + 1}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
local expected = [[ | ||
function foo() { | ||
const a = 1 | ||
console.log("a", a) | ||
return ( | ||
<div> | ||
<div>{a + 1}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
helper.assert_scenario({ | ||
input = input, | ||
filetype = "typescriptreact", | ||
action = function() | ||
actions.add_log("%identifier", "above") | ||
end, | ||
expected = expected, | ||
}) | ||
|
||
input = [[ | ||
function foo() { | ||
const a = 1 | ||
const el = ( | ||
<div> | ||
<div>{a| + 1}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
expected = [[ | ||
function foo() { | ||
const a = 1 | ||
const el = ( | ||
<div> | ||
<div>{a + 1}</div> | ||
</div> | ||
) | ||
console.log("a", a) | ||
} | ||
]] | ||
|
||
helper.assert_scenario({ | ||
input = input, | ||
filetype = "typescriptreact", | ||
action = function() | ||
actions.add_log("%identifier", "below") | ||
end, | ||
expected = expected, | ||
}) | ||
end) | ||
|
||
it("supports jsx attribute", function() | ||
local actions = require("neolog.actions") | ||
|
||
local input = [[ | ||
function foo() { | ||
return ( | ||
<div className={a|}> | ||
<div>{b + 1}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
local expected = [[ | ||
function foo() { | ||
console.log("a", a) | ||
return ( | ||
<div className={a|}> | ||
<div>{b + 1}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
|
||
helper.assert_scenario({ | ||
input = input, | ||
filetype = "typescriptreact", | ||
action = function() | ||
actions.add_log("%identifier", "above") | ||
end, | ||
expected = expected, | ||
}) | ||
end) | ||
|
||
it("supports visual selection log", function() | ||
local actions = require("neolog.actions") | ||
|
||
local input = [[ | ||
function foo() { | ||
const a = 1 | ||
const b = 1 | ||
return ( | ||
<div> | ||
<div>{a| + b}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
local expected = [[ | ||
function foo() { | ||
const a = 1 | ||
const b = 1 | ||
console.log("a", a) | ||
console.log("b", b) | ||
return ( | ||
<div> | ||
<div>{a + b}</div> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
helper.assert_scenario({ | ||
input = input, | ||
filetype = "typescriptreact", | ||
action = function() | ||
vim.cmd("normal! vi{") | ||
actions.add_log("%identifier", "above") | ||
end, | ||
expected = expected, | ||
}) | ||
|
||
input = [[ | ||
function foo() { | ||
const a = 1 | ||
const b = true | ||
const el = ( | ||
<div> | ||
{b && <div>{|a + 1}</div>} | ||
<input className={c} /> | ||
</div> | ||
) | ||
} | ||
]] | ||
|
||
-- TODO: figure out why indentation is off with inner jsx element | ||
expected = [[ | ||
function foo() { | ||
const a = 1 | ||
const b = true | ||
const el = ( | ||
<div> | ||
{b && <div>{|a + 1}</div>} | ||
<input className={c} /> | ||
</div> | ||
) | ||
console.log("b", b) | ||
console.log("a", a) | ||
console.log("c", c) | ||
} | ||
]] | ||
|
||
helper.assert_scenario({ | ||
input = input, | ||
filetype = "typescriptreact", | ||
action = function() | ||
vim.cmd("normal! Vj") | ||
actions.add_log("%identifier", "below") | ||
end, | ||
expected = expected, | ||
}) | ||
end) | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters