Skip to content

Commit 7dcd211

Browse files
committed
allow simplified @@jsxConfig
1 parent 1aa0d34 commit 7dcd211

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

jscomp/syntax/src/jsx_ppx.ml

+34-13
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@ open Asttypes
33
open Parsetree
44
open Longident
55

6-
let getPayloadFields payload =
6+
type configPayload =
7+
| ModuleName of string
8+
| Fields of (t loc * expression) list
9+
| Invalid
10+
11+
let getConfigPayload payload =
712
match payload with
813
| PStr
914
({
1015
pstr_desc =
1116
Pstr_eval ({pexp_desc = Pexp_record (recordFields, None)}, _);
1217
}
1318
:: _rest) ->
14-
recordFields
15-
| _ -> []
19+
Fields recordFields
20+
| PStr
21+
({
22+
pstr_desc =
23+
Pstr_eval
24+
({pexp_desc = Pexp_constant (Pconst_string (moduleName, _))}, _);
25+
}
26+
:: _rest) ->
27+
ModuleName moduleName
28+
| _ -> Invalid
1629

1730
type configKey = Int | String
1831

@@ -47,16 +60,24 @@ let getInt ~key fields =
4760
let getString ~key fields = fields |> getJsxConfigByKey ~key ~type_:String
4861

4962
let updateConfig config payload =
50-
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
55-
| None -> ()
56-
| Some s -> config.module_ <- s);
57-
match getString ~key:"mode" fields with
58-
| None -> ()
59-
| Some s -> config.mode <- s
63+
match getConfigPayload payload with
64+
| Invalid -> () (* TODO(generic-jsx): Report error? *)
65+
| ModuleName moduleName ->
66+
config.Jsx_common.module_ <- moduleName;
67+
if String.lowercase_ascii moduleName <> "react" then (
68+
(* Force set automatic/version for anything but React *)
69+
config.version <- 4;
70+
config.mode <- "automatic")
71+
| Fields fields -> (
72+
(match getInt ~key:"version" fields with
73+
| None -> ()
74+
| Some i -> config.Jsx_common.version <- i);
75+
(match getString ~key:"module_" fields with
76+
| None -> ()
77+
| Some s -> config.module_ <- s);
78+
match getString ~key:"mode" fields with
79+
| None -> ()
80+
| Some s -> config.mode <- s)
6081

6182
let isJsxConfigAttr ((loc, _) : attribute) = loc.txt = "jsxConfig"
6283

jscomp/syntax/src/jsx_v4.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
500500
let domBinding =
501501
match moduleAccessName config with
502502
| "React" -> Lident "ReactDOM"
503-
| generic -> Ldot (Lident generic, "DOM")
503+
| generic -> Ldot (Lident generic, "Elements")
504504
in
505505

506506
let children, nonChildrenProps =

0 commit comments

Comments
 (0)