Skip to content

Commit a4d9c0a

Browse files
authored
Latest version of parser (#917)
* latest version of parser * changelog
1 parent 80fde16 commit a4d9c0a

9 files changed

+208
-114
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Completion for import attributes in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/913
1919
- Relax filter for what local files that come up in from and regular string completion in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/918
2020
- Make from completion trigger for expr hole so we get a nice experience when completing {from: <com>} in `@module`. https://github.com/rescript-lang/rescript-vscode/pull/918
21+
- Latest parser for newest syntax features. https://github.com/rescript-lang/rescript-vscode/pull/917
2122

2223
## 1.38.0
2324

analysis/tests/src/expected/CompletionJsx.res.txt

+11-11
Original file line numberDiff line numberDiff line change
@@ -429,17 +429,17 @@ posCursor:[30:12] posNoWhite:[30:11] Found expr:[11:4->32:10]
429429
posCursor:[30:12] posNoWhite:[30:11] Found expr:[12:4->32:10]
430430
posCursor:[30:12] posNoWhite:[30:11] Found expr:[15:5->32:10]
431431
JSX <div:[15:5->15:8] > _children:15:8
432-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[15:8->32:4]
433-
Pexp_construct :::[16:7->32:4] [16:7->32:4]
434-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[16:7->32:4]
435-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[17:7->32:4]
436-
Pexp_construct :::[17:7->32:4] [17:7->32:4]
437-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[17:7->32:4]
438-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->32:4]
439-
Pexp_construct :::[30:10->32:4] [30:10->32:4]
440-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->32:4]
441-
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->30:12]
442-
JSX <di:[30:10->30:12] > _children:None
432+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[15:8->33:2]
433+
Pexp_construct :::[16:7->33:2] [16:7->33:2]
434+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[16:7->33:2]
435+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[17:7->33:2]
436+
Pexp_construct :::[17:7->33:2] [17:7->33:2]
437+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[17:7->33:2]
438+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->33:2]
439+
Pexp_construct :::[30:10->33:2] [30:10->33:2]
440+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->33:2]
441+
posCursor:[30:12] posNoWhite:[30:11] Found expr:[30:10->32:10]
442+
JSX <di:[30:10->30:12] div[32:6->32:9]=...[32:6->32:9]> _children:32:9
443443
Completable: ChtmlElement <di
444444
Package opens Pervasives.JsxModules.place holder
445445
Resolved opens 1 pervasives

analysis/vendor/res_syntax/jsx_ppx.ml

+15-7
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,23 @@ let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_:String
4848

4949
let updateConfig config payload =
5050
let fields = getPayloadFields payload in
51-
(match getInt ~key:"version" fields with
52-
| None -> ()
53-
| Some i -> config.Jsx_common.version <- i);
54-
(match getString ~key:"module_" fields with
51+
let moduleRaw = getString ~key:"module_" fields in
52+
let isGeneric =
53+
match moduleRaw |> Option.map (fun m -> String.lowercase_ascii m) with
54+
| Some "react" | None -> false
55+
| Some _ -> true
56+
in
57+
(match (isGeneric, getInt ~key:"version" fields) with
58+
| true, _ -> config.Jsx_common.version <- 4
59+
| false, Some i -> config.Jsx_common.version <- i
60+
| _ -> ());
61+
(match moduleRaw with
5562
| None -> ()
5663
| Some s -> config.module_ <- s);
57-
match getString ~key:"mode" fields with
58-
| None -> ()
59-
| Some s -> config.mode <- s
64+
match (isGeneric, getString ~key:"mode" fields) with
65+
| true, _ -> config.mode <- "automatic"
66+
| false, Some s -> config.mode <- s
67+
| _ -> ()
6068

6169
let isJsxConfigAttr ((loc, _) : attribute) = loc.txt = "jsxConfig"
6270

analysis/vendor/res_syntax/jsx_v4.ml

+18-49
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ open Asttypes
44
open Parsetree
55
open Longident
66

7-
let moduleAccessName config = String.capitalize_ascii config.Jsx_common.module_
7+
let moduleAccessName config value =
8+
String.capitalize_ascii config.Jsx_common.module_ ^ "." ^ value
9+
|> Longident.parse
810

911
let nolabel = Nolabel
1012

@@ -384,10 +386,7 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
384386
( labelled "children",
385387
Exp.apply
386388
(Exp.ident
387-
{
388-
txt = Ldot (Lident (moduleAccessName config), "array");
389-
loc = Location.none;
390-
})
389+
{txt = moduleAccessName config "array"; loc = Location.none})
391390
[(Nolabel, expression)] );
392391
]
393392
| _ ->
@@ -431,31 +430,17 @@ let transformUppercaseCall3 ~config modulePath mapper jsxExprLoc callExprLoc
431430
match (!childrenArg, keyProp) with
432431
| None, key :: _ ->
433432
( Exp.ident
434-
{
435-
loc = Location.none;
436-
txt = Ldot (Lident (moduleAccessName config), "jsxKeyed");
437-
},
433+
{loc = Location.none; txt = moduleAccessName config "jsxKeyed"},
438434
[key; (nolabel, unitExpr ~loc:Location.none)] )
439435
| None, [] ->
440-
( Exp.ident
441-
{
442-
loc = Location.none;
443-
txt = Ldot (Lident (moduleAccessName config), "jsx");
444-
},
436+
( Exp.ident {loc = Location.none; txt = moduleAccessName config "jsx"},
445437
[] )
446438
| Some _, key :: _ ->
447439
( Exp.ident
448-
{
449-
loc = Location.none;
450-
txt = Ldot (Lident (moduleAccessName config), "jsxsKeyed");
451-
},
440+
{loc = Location.none; txt = moduleAccessName config "jsxsKeyed"},
452441
[key; (nolabel, unitExpr ~loc:Location.none)] )
453442
| Some _, [] ->
454-
( Exp.ident
455-
{
456-
loc = Location.none;
457-
txt = Ldot (Lident (moduleAccessName config), "jsxs");
458-
},
443+
( Exp.ident {loc = Location.none; txt = moduleAccessName config "jsxs"},
459444
[] )
460445
in
461446
Exp.apply ~loc:jsxExprLoc ~attrs jsxExpr
@@ -500,9 +485,9 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
500485
(* the new jsx transform *)
501486
| "automatic" ->
502487
let elementBinding =
503-
match moduleAccessName config with
504-
| "React" -> Lident "ReactDOM"
505-
| generic -> Ldot (Lident generic, "DOM")
488+
match config.module_ |> String.lowercase_ascii with
489+
| "react" -> Lident "ReactDOM"
490+
| _generic -> moduleAccessName config "Elements"
506491
in
507492

508493
let children, nonChildrenProps =
@@ -539,10 +524,7 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
539524
( labelled "children",
540525
Exp.apply
541526
(Exp.ident
542-
{
543-
txt = Ldot (Lident (moduleAccessName config), "array");
544-
loc = Location.none;
545-
})
527+
{txt = moduleAccessName config "array"; loc = Location.none})
546528
[(Nolabel, expression)] );
547529
]
548530
in
@@ -1203,10 +1185,7 @@ let transformStructureItem ~config item =
12031185
(* can't be an arrow because it will defensively uncurry *)
12041186
let newExternalType =
12051187
Ptyp_constr
1206-
( {
1207-
loc = pstr_loc;
1208-
txt = Ldot (Lident (moduleAccessName config), "componentLike");
1209-
},
1188+
( {loc = pstr_loc; txt = moduleAccessName config "componentLike"},
12101189
[retPropsType; innerType] )
12111190
in
12121191
let newStructure =
@@ -1321,10 +1300,7 @@ let transformSignatureItem ~config item =
13211300
(* can't be an arrow because it will defensively uncurry *)
13221301
let newExternalType =
13231302
Ptyp_constr
1324-
( {
1325-
loc = psig_loc;
1326-
txt = Ldot (Lident (moduleAccessName config), "componentLike");
1327-
},
1303+
( {loc = psig_loc; txt = moduleAccessName config "componentLike"},
13281304
[retPropsType; innerType] )
13291305
in
13301306
let newStructure =
@@ -1419,8 +1395,7 @@ let expr ~config mapper expression =
14191395
let fragment =
14201396
match config.mode with
14211397
| "automatic" ->
1422-
Exp.ident ~loc
1423-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsxFragment")}
1398+
Exp.ident ~loc {loc; txt = moduleAccessName config "jsxFragment"}
14241399
| "classic" | _ ->
14251400
Exp.ident ~loc {loc; txt = Ldot (Lident "React", "fragment")}
14261401
in
@@ -1431,10 +1406,7 @@ let expr ~config mapper expression =
14311406
let applyJsxArray expr =
14321407
Exp.apply
14331408
(Exp.ident
1434-
{
1435-
txt = Ldot (Lident (moduleAccessName config), "array");
1436-
loc = Location.none;
1437-
})
1409+
{txt = moduleAccessName config "array"; loc = Location.none})
14381410
[(Nolabel, expr)]
14391411
in
14401412
let countOfChildren = function
@@ -1472,11 +1444,8 @@ let expr ~config mapper expression =
14721444
(match config.mode with
14731445
| "automatic" ->
14741446
if countOfChildren childrenExpr > 1 then
1475-
Exp.ident ~loc
1476-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsxs")}
1477-
else
1478-
Exp.ident ~loc
1479-
{loc; txt = Ldot (Lident (moduleAccessName config), "jsx")}
1447+
Exp.ident ~loc {loc; txt = moduleAccessName config "jsxs"}
1448+
else Exp.ident ~loc {loc; txt = moduleAccessName config "jsx"}
14801449
| "classic" | _ ->
14811450
if countOfChildren childrenExpr > 1 then
14821451
Exp.ident ~loc

0 commit comments

Comments
 (0)