Skip to content

Commit f7955fe

Browse files
committed
Clean up jsx grammar and comment jsx code.
The jsx grammar only needs to take care of `<>` and `</>` and `</` and `/>`. The `<` and `>` cases are handled via semantic highlighting. And the ids are handled via semantic highlighting just like ids in any other context.
1 parent 4af55e0 commit f7955fe

File tree

2 files changed

+12
-41
lines changed

2 files changed

+12
-41
lines changed

analysis/src/SemanticTokens.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,14 @@ let parser ~debug ~emitter ~path =
217217
Ast_mapper.default_mapper.expr mapper e
218218
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
219219
when Res_parsetree_viewer.isJsxExpression e ->
220+
(*
221+
Angled brackets:
222+
- These are handled in the grammar: <> </> </ />
223+
- Here we handle `<` and `>`
224+
225+
Component names:
226+
- handled like other Longitent.t, except lowercase id is marked Token.JsxLowercase
227+
*)
220228
let rec isSelfClosing args =
221229
match args with
222230
| [] -> false
@@ -231,7 +239,7 @@ let parser ~debug ~emitter ~path =
231239
true
232240
| _ :: rest -> isSelfClosing rest
233241
in
234-
emitter
242+
emitter (* --> <div.. *)
235243
|> emitJsxTag ~debug ~name:"<"
236244
~pos:
237245
(let pos = Utils.tupleOfLexing e.pexp_loc.loc_start in
@@ -262,7 +270,7 @@ let parser ~debug ~emitter ~path =
262270
~pos:
263271
(let pos = Utils.tupleOfLexing e.pexp_loc.loc_end in
264272
(fst pos, snd pos - 1))));
265-
(* only process again arguments, not the jsx label *)
273+
266274
let _ = args |> List.map (fun (_lbl, arg) -> mapper.expr mapper arg) in
267275
e
268276
| Pexp_apply

grammars/rescript.tmLanguage.json

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -364,45 +364,8 @@
364364
]
365365
},
366366
"jsx": {
367-
"patterns": [
368-
{
369-
"match": "<>|</>|/>",
370-
"name": "punctuation.definition.tag"
371-
},
372-
{
373-
"match": "</([A-Z_][0-9a-zA-Z_]*)",
374-
"captures": {
375-
"0": {
376-
"name": "punctuation.definition.tag"
377-
},
378-
"1": {
379-
"name": "entity.name.namespace"
380-
}
381-
}
382-
},
383-
{
384-
"match": "</([a-z_][0-9a-zA-Z_]*)",
385-
"captures": {
386-
"0": {
387-
"name": "punctuation.definition.tag"
388-
},
389-
"1": {
390-
"name": "variable"
391-
}
392-
}
393-
},
394-
{
395-
"match": "<([A-Z_][0-9a-zA-Z_]*)",
396-
"captures": {
397-
"0": {
398-
"name": "punctuation.definition.tag"
399-
},
400-
"1": {
401-
"name": "entity.name.namespace"
402-
}
403-
}
404-
}
405-
]
367+
"match": "<>|</>|</|/>",
368+
"name": "punctuation.definition.tag"
406369
},
407370
"openOrIncludeModule": {
408371
"patterns": [

0 commit comments

Comments
 (0)