Skip to content

Commit 1511d0c

Browse files
rriskiarendjr
andauthored
feat(grit): add JSX node name mappings for GritQL patterns (#7285)
Co-authored-by: Arend van Beelen jr. <arend@arendjr.nl>
1 parent 0b07f45 commit 1511d0c

File tree

5 files changed

+105
-0
lines changed

5 files changed

+105
-0
lines changed

.changeset/cyan-jars-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Partially fixed [#6782](https://github.com/biomejs/biome/issues/6782): JSX node kinds are now supported in GritQL AST nodes.

crates/biome_grit_patterns/src/grit_target_language/js_target_language.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@ impl GritTargetLanguageImpl for JsTargetLanguage {
4545
"assignment_expression" => JS_ASSIGNMENT_EXPRESSION,
4646
"call_expression" => JS_CALL_EXPRESSION,
4747
"new_expression" => JS_NEW_EXPRESSION,
48+
"jsx_expression" => JSX_EXPRESSION_CHILD,
49+
"jsx_attribute" => JSX_ATTRIBUTE,
50+
"jsx_element" => JSX_ELEMENT,
51+
"jsx_self_closing_element" => JSX_SELF_CLOSING_ELEMENT,
52+
"jsx_opening_element" => JSX_OPENING_ELEMENT,
53+
"jsx_closing_element" => JSX_CLOSING_ELEMENT,
54+
"jsx_text" => JSX_TEXT,
55+
"jsx_namespace_name" => JSX_NAMESPACE_NAME,
4856
// TODO: Many more of these. We should probably find a way to
4957
// generate these impls from TS `grammar.js` files, combined with
5058
// our `js.ungram`.
@@ -69,6 +77,14 @@ impl GritTargetLanguageImpl for JsTargetLanguage {
6977
JS_ASSIGNMENT_EXPRESSION => "assignment_expression",
7078
JS_CALL_EXPRESSION => "call_expression",
7179
JS_NEW_EXPRESSION => "new_expression",
80+
JSX_EXPRESSION_CHILD => "jsx_expression",
81+
JSX_ATTRIBUTE => "jsx_attribute",
82+
JSX_ELEMENT => "jsx_element",
83+
JSX_SELF_CLOSING_ELEMENT => "jsx_self_closing_element",
84+
JSX_OPENING_ELEMENT => "jsx_opening_element",
85+
JSX_CLOSING_ELEMENT => "jsx_closing_element",
86+
JSX_TEXT => "jsx_text",
87+
JSX_NAMESPACE_NAME => "jsx_namespace_name",
7288
// TODO: Many more of these. We should probably find a way to
7389
// generate these impls from TS `grammar.js` files, combined with
7490
// our `js.ungram`.
@@ -91,6 +107,18 @@ impl GritTargetLanguageImpl for JsTargetLanguage {
91107
JS_ASSIGNMENT_EXPRESSION => &[],
92108
JS_CALL_EXPRESSION => &[("function", 0), ("type_arguments", 2), ("arguments", 3)],
93109
JS_NEW_EXPRESSION => &[],
110+
JSX_ELEMENT => &[
111+
("opening_element", 0),
112+
("children", 1),
113+
("closing_element", 2),
114+
],
115+
JSX_SELF_CLOSING_ELEMENT => &[("name", 1), ("attributes", 2)],
116+
JSX_OPENING_ELEMENT => &[("name", 1), ("attributes", 2)],
117+
JSX_CLOSING_ELEMENT => &[("name", 2)],
118+
JSX_ATTRIBUTE => &[],
119+
JSX_EXPRESSION_CHILD => &[("expression", 1)],
120+
JSX_TEXT => &[],
121+
JSX_NAMESPACE_NAME => &[("namespace", 0), ("name", 2)],
94122
// TODO: Many more of these. We should probably find a way to
95123
// generate these impls from TS `grammar.js` files, combined with
96124
// our `js.ungram`.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
engine biome(1.0)
2+
language js(jsx)
3+
4+
or {
5+
jsx_expression(),
6+
jsx_attribute(),
7+
jsx_element(),
8+
jsx_self_closing_element(),
9+
jsx_opening_element(),
10+
jsx_closing_element(),
11+
jsx_text(),
12+
jsx_namespace_name()
13+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
source: crates/biome_grit_patterns/tests/spec_tests.rs
3+
expression: jsx_nodes
4+
---
5+
SnapshotResult {
6+
messages: [],
7+
matched_ranges: [
8+
"1:1-1:35",
9+
"1:1-11:7",
10+
"1:6-1:22",
11+
"1:23-1:34",
12+
"1:35-2:3",
13+
"2:3-2:12",
14+
"2:12-3:3",
15+
"3:3-3:33",
16+
"3:18-3:22",
17+
"3:18-3:32",
18+
"3:22-3:27",
19+
"3:27-3:32",
20+
"3:33-4:3",
21+
"4:3-4:35",
22+
"4:8-4:18",
23+
"4:19-4:32",
24+
"4:35-5:3",
25+
"5:3-5:19",
26+
"5:3-7:20",
27+
"5:19-6:5",
28+
"6:5-6:11",
29+
"6:5-6:24",
30+
"6:11-6:17",
31+
"6:17-6:24",
32+
"6:24-7:3",
33+
"7:3-7:20",
34+
"7:20-8:3",
35+
"8:3-8:70",
36+
"8:3-10:20",
37+
"8:4-8:18",
38+
"8:19-8:31",
39+
"8:19-8:52",
40+
"8:70-10:3",
41+
"10:3-10:20",
42+
"10:5-10:19",
43+
"10:20-11:1",
44+
"11:1-11:7",
45+
],
46+
rewritten_files: [],
47+
created_files: [],
48+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<div className="test" id={someId}>
2+
{content}
3+
{showHeader && <h1>Title</h1>}
4+
<img alt="logo" src={logoSrc} />
5+
<React.Fragment>
6+
<span>Inside</span>
7+
</React.Fragment>
8+
<custom:element xmlns:custom="http://example.com" {...spreadProps}>
9+
Text content here
10+
</custom:element>
11+
</div>

0 commit comments

Comments
 (0)