Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed javascript, javascriptreact, typescript and typescriptreact file types. #34

Merged
merged 5 commits into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions queries/javascript/class.scm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
; inherits: tsx

(call_expression
function: [
(identifier) @ident
Expand Down
15 changes: 14 additions & 1 deletion queries/typescript/class.scm
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
; inherits: javascript
(call_expression
function: [
(identifier) @ident
(member_expression
object: (identifier) @object-ident)
]
(#any-of? @ident "clsx" "classnames" "tw" "css")
(#eq? @object-ident "tw")
arguments: [
(arguments
(_)+) @tailwind ; the actual class range is extracted in the code
(template_string
(string_fragment) @tailwind)
])
1 change: 1 addition & 0 deletions tests/parsers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ local parsers = {
"heex",
"elixir",
"javascript",
"typescript",
"templ",
}

Expand Down
23 changes: 23 additions & 0 deletions tests/queries/javascript/Component.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const color = "text-blue-300";

const Component = () => {
return (
<div>
<div
className="flex items-center justify-center container mx-auto p-4
border-2 border-gray-500 rounded-md bg-gray-100"
>
<div className="text-2xl font-bold mb-4">
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint
cillum sint consectetur cupidatat.
</div>
<div className={`${color} bg-gray-100`}>
Lorem ipsum dolor sit amet, qui minim labore adipisicing minim sint
cillum sint consectetur cupidatat.
</div>
</div>
</div>
);
};

export default Component;
15 changes: 14 additions & 1 deletion tests/queries/javascript_spec.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require("tests.queries.runner").test({
local runner = require("tests.queries.runner")

runner.test({
name = "javascript",
provider = "treesitter",
file = "tests/queries/javascript/test.js",
Expand All @@ -9,3 +11,14 @@ require("tests.queries.runner").test({
{ 3, 9, 3, 34 },
},
})

runner.test({
name = "javascriptreact",
provider = "treesitter",
file = "tests/queries/javascript/Component.jsx",
ranges = {
{ 6, 19, 7, 55 },
{ 9, 24, 9, 47 },
{ 13, 24, 13, 46 },
},
})
4 changes: 4 additions & 0 deletions tests/queries/typescript/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
clsx("p-4", "text-center");
classnames("bg-red-500", "uppercase");
tw`font-mono text-sm`
tw.input`border hover:border-black`
11 changes: 11 additions & 0 deletions tests/queries/typescript_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require("tests.queries.runner").test({
name = "typescript",
provider = "treesitter",
file = "tests/queries/typescript/test.ts",
ranges = {
{ 0, 5, 0, 25 },
{ 1, 11, 1, 36 },
{ 2, 3, 2, 20 },
{ 3, 9, 3, 34 },
},
})
Loading